Skip to content

Commit f17c797

Browse files
authored
Merge pull request #72 from shivas/type-hints
Add PHP type hints to private methods and test classes
2 parents 0fdab22 + fab0ce3 commit f17c797

11 files changed

+57
-80
lines changed

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@ matrix:
1818
fast_finish: true
1919
include:
2020
# Minimum supported dependencies with the latest and oldest PHP version
21-
- php: 7.3
21+
- php: 7.4
2222
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
23-
- php: 7.0
23+
- php: 7.1
2424
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
2525

2626
# Test the latest stable release
27-
- php: 7.0
2827
- php: 7.1
2928
- php: 7.2
3029
- php: 7.3
30+
- php: 7.4
3131
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text --coverage-clover=coverage.clover"
3232

3333
# Test with Symfony 3
34-
- php: 7.3
34+
- php: 7.4
3535
env: SYMFONY_VERSION="^3"
3636

3737
# Test with Symfony 4
38-
- php: 7.3
38+
- php: 7.4
3939
env: SYMFONY_VERSION="^4"
4040

4141
# Latest commit to master
42-
- php: 7.3
42+
- php: 7.4
4343
env: STABILITY="dev"
4444

4545
# Upcoming PHP version

Formatter/GitDescribeFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function format(Version $version)
4646
return $version;
4747
}
4848

49-
private function clearPreRelease(Version $version)
49+
private function clearPreRelease(Version $version): Version
5050
{
5151
if (class_exists(\Version\Metadata\PreRelease::class)) {
5252
// we cannot use null with nikolaposa/version 2.2

Provider/GitRepositoryProvider.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ public function getVersion()
4141
return $this->getGitDescribe();
4242
}
4343

44-
/**
45-
* @param string $path
46-
* @return boolean
47-
*/
48-
private function isGitRepository($path)
44+
private function isGitRepository(string $path): bool
4945
{
5046
// silenced to avoid E_WARNING on open_basedir restriction
5147
if (!@is_readable($path)) {
@@ -69,9 +65,9 @@ private function isGitRepository($path)
6965
/**
7066
* If describing throws error return false, otherwise true
7167
*
72-
* @return boolean
68+
* @return bool
7369
*/
74-
private function canGitDescribe()
70+
private function canGitDescribe(): bool
7571
{
7672
try {
7773
$this->getGitDescribe();
@@ -86,7 +82,7 @@ private function canGitDescribe()
8682
* @return string
8783
* @throws RuntimeException
8884
*/
89-
private function getGitDescribe()
85+
private function getGitDescribe(): string
9086
{
9187
$dir = getcwd();
9288
if (false === $dir) {

Provider/RevisionProvider.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,12 @@ public function getVersion()
4040
return $this->getRevision();
4141
}
4242

43-
/**
44-
* @return bool
45-
*/
46-
private function isCapistranoEnv()
43+
private function isCapistranoEnv(): bool
4744
{
4845
return file_exists($this->path . DIRECTORY_SEPARATOR . 'REVISION');
4946
}
5047

51-
/**
52-
* If describing throws error return false, otherwise true
53-
*
54-
* @return boolean
55-
* @throws RuntimeException
56-
*/
57-
private function canGetRevision()
48+
private function canGetRevision(): bool
5849
{
5950
try {
6051
if ('' === $this->getRevision()) {
@@ -67,10 +58,7 @@ private function canGetRevision()
6758
return true;
6859
}
6960

70-
/**
71-
* @return string
72-
*/
73-
private function getRevision()
61+
private function getRevision(): string
7462
{
7563
$filename = $this->path . DIRECTORY_SEPARATOR . 'REVISION';
7664
$result = file_get_contents($filename);

Provider/VersionProvider.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,12 @@ public function getVersion()
4646
return rtrim($result);
4747
}
4848

49-
/**
50-
* @return bool
51-
*/
52-
private function hasVersionFile()
49+
private function hasVersionFile(): bool
5350
{
5451
return file_exists($this->path . DIRECTORY_SEPARATOR . 'VERSION');
5552
}
5653

57-
/**
58-
* @return boolean
59-
* @throws RuntimeException
60-
*/
61-
private function canGetVersion()
54+
private function canGetVersion(): bool
6255
{
6356
try {
6457
if ('' === $this->getVersion()) {

Tests/Formatter/GitDescribeFormatterTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,56 @@
99
/**
1010
* Class GitDescribeFormatterTest
1111
*/
12-
class GitDescribeFormatterTest extends TestCase
12+
final class GitDescribeFormatterTest extends TestCase
1313
{
14-
public function testInitializable()
14+
public function testInitializable(): void
1515
{
1616
$formatter = new GitDescribeFormatter();
1717

1818
$this->assertInstanceOf(GitDescribeFormatter::class, $formatter);
1919
}
2020

21-
public function testInitialVersion()
21+
public function testInitialVersion(): void
2222
{
2323
$formatter = new GitDescribeFormatter();
2424
$version = Version::fromString('0.1.0');
2525

2626
$this->assertEquals('0.1.0', $formatter->format($version), 'Basic version number');
2727
}
2828

29-
public function testGitVersion()
29+
public function testGitVersion(): void
3030
{
3131
$formatter = new GitDescribeFormatter();
3232
$version = Version::fromString('1.4.1-0-gd891f45');
3333

3434
$this->assertEquals('1.4.1', $formatter->format($version), 'Tag commit should ignore hash');
3535
}
3636

37-
public function testGitHashVersion()
37+
public function testGitHashVersion(): void
3838
{
3939
$formatter = new GitDescribeFormatter();
4040
$version = Version::fromString('1.4.1-1-g7f07e6d');
4141

4242
$this->assertEquals('1.4.1-dev.7f07e6d', $formatter->format($version), 'Not on tag commit adds dev.hash');
4343
}
4444

45-
public function testGitMultipleCommitsVersion()
45+
public function testGitMultipleCommitsVersion(): void
4646
{
4747
$formatter = new GitDescribeFormatter();
4848
$version = Version::fromString('2.3.3-201-g1c224d9fa');
4949

5050
$this->assertEquals('2.3.3-dev.1c224d9fa', $formatter->format($version), 'Multiple commits since last tag');
5151
}
5252

53-
public function testGitLongVersion()
53+
public function testGitLongVersion(): void
5454
{
5555
$formatter = new GitDescribeFormatter();
5656
$version = Version::fromString('1.2.3-foo-bar.1-0-gd891f45');
5757

5858
$this->assertEquals('1.2.3-foo-bar.1', $formatter->format($version), 'Long version on tag commit');
5959
}
6060

61-
public function testGitLongHashVersion()
61+
public function testGitLongHashVersion(): void
6262
{
6363
$formatter = new GitDescribeFormatter();
6464
$version = Version::fromString('1.2.3-foo-bar.1-203-g13ebcdd');

Tests/Provider/GitRepositoryProviderTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ final class GitRepositoryProviderTest extends TestCase
4040
*/
4141
private $root;
4242

43-
public static function setUpBeforeClass()
43+
public static function setUpBeforeClass(): void
4444
{
4545
self::mockChdir();
4646
self::mockGitDescribe();
4747
}
4848

49-
protected function setUp()
49+
protected function setUp(): void
5050
{
5151
self::$gitDescribeExitCode = 0;
5252
self::$gitDescribeOutput = __CLASS__;
@@ -65,15 +65,15 @@ protected function setUp()
6565
/**
6666
* @covers \Shivas\VersioningBundle\Provider\GitRepositoryProvider::isSupported
6767
*/
68-
public function testIsSupportedNonGit()
68+
public function testIsSupportedNonGit(): void
6969
{
7070
$this->assertFalse($this->gitRepositoryProvider->isSupported());
7171
}
7272

7373
/**
7474
* @covers \Shivas\VersioningBundle\Provider\GitRepositoryProvider::isSupported
7575
*/
76-
public function testIsSupportedDirNotReadable()
76+
public function testIsSupportedDirNotReadable(): void
7777
{
7878
vfsStream::newDirectory('.git')->at($this->root);
7979
$this->root->getChild('folder')->chmod(0000);
@@ -83,7 +83,7 @@ public function testIsSupportedDirNotReadable()
8383
/**
8484
* @covers \Shivas\VersioningBundle\Provider\GitRepositoryProvider::isSupported
8585
*/
86-
public function testIsSupportedGitDescribeError()
86+
public function testIsSupportedGitDescribeError(): void
8787
{
8888
vfsStream::newDirectory('.git')->at($this->root);
8989
self::$gitDescribeExitCode = 1;
@@ -93,7 +93,7 @@ public function testIsSupportedGitDescribeError()
9393
/**
9494
* @covers \Shivas\VersioningBundle\Provider\GitRepositoryProvider::isSupported
9595
*/
96-
public function testIsSupportedDir()
96+
public function testIsSupportedDir(): void
9797
{
9898
vfsStream::newDirectory('.git')->at($this->root);
9999
self::$gitDescribeOutput = '1.2.3';
@@ -103,7 +103,7 @@ public function testIsSupportedDir()
103103
/**
104104
* @covers \Shivas\VersioningBundle\Provider\GitRepositoryProvider::isSupported
105105
*/
106-
public function testIsSupportedFile()
106+
public function testIsSupportedFile(): void
107107
{
108108
vfsStream::newFile('.git')->at($this->root);
109109
self::$gitDescribeOutput = '1.2.3';
@@ -113,7 +113,7 @@ public function testIsSupportedFile()
113113
/**
114114
* @covers \Shivas\VersioningBundle\Provider\GitRepositoryProvider::getVersion
115115
*/
116-
public function testGetVersion()
116+
public function testGetVersion(): void
117117
{
118118
vfsStream::newDirectory('.git')->at($this->root);
119119
self::$gitDescribeOutput = '1.2.3';
@@ -123,7 +123,7 @@ public function testGetVersion()
123123
/**
124124
* @covers \Shivas\VersioningBundle\Provider\GitRepositoryProvider::getVersion
125125
*/
126-
public function testGetVersionGitDescribeError()
126+
public function testGetVersionGitDescribeError(): void
127127
{
128128
vfsStream::newDirectory('.git')->at($this->root);
129129
self::$gitDescribeExitCode = 1;
@@ -133,7 +133,7 @@ public function testGetVersionGitDescribeError()
133133
$this->gitRepositoryProvider->getVersion();
134134
}
135135

136-
private static function mockChdir()
136+
private static function mockChdir(): void
137137
{
138138
$self = '\\' . __CLASS__;
139139
eval(<<<EOPHP
@@ -151,7 +151,7 @@ function chdir(string \$directory): bool
151151
);
152152
}
153153

154-
private static function mockGitDescribe()
154+
private static function mockGitDescribe(): void
155155
{
156156
$self = '\\' . __CLASS__;
157157
eval(<<<EOPHP

Tests/Provider/InitialVersionProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
/**
99
* Class InitialVersionProviderTest
1010
*/
11-
class InitialVersionProviderTest extends TestCase
11+
final class InitialVersionProviderTest extends TestCase
1212
{
13-
public function testInitializable()
13+
public function testInitializable(): void
1414
{
1515
$provider = new InitialVersionProvider();
1616

1717
$this->assertInstanceOf(InitialVersionProvider::class, $provider);
1818
}
1919

20-
public function testAlwaysSupported()
20+
public function testAlwaysSupported(): void
2121
{
2222
$provider = new InitialVersionProvider();
2323

2424
$this->assertTrue($provider->isSupported(), 'The provider should always be supported');
2525
}
2626

27-
public function testInitialVersion()
27+
public function testInitialVersion(): void
2828
{
2929
$provider = new InitialVersionProvider();
3030

Tests/Provider/RevisionProviderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class RevisionProviderTest extends TestCase
2424
*/
2525
private $revisionProvider;
2626

27-
protected function setUp()
27+
protected function setUp(): void
2828
{
2929
$this->root = vfsStream::setup();
3030
$this->revisionProvider = new RevisionProvider($this->root->url());
@@ -33,15 +33,15 @@ protected function setUp()
3333
/**
3434
* @covers \Shivas\VersioningBundle\Provider\RevisionProvider::isSupported
3535
*/
36-
public function testIsSupportedWithoutFile()
36+
public function testIsSupportedWithoutFile(): void
3737
{
3838
$this->assertFalse($this->revisionProvider->isSupported());
3939
}
4040

4141
/**
4242
* @covers \Shivas\VersioningBundle\Provider\RevisionProvider::isSupported
4343
*/
44-
public function testIsSupportedWithUnreadableFile()
44+
public function testIsSupportedWithUnreadableFile(): void
4545
{
4646
vfsStream::newFile('REVISION', 0000)
4747
->withContent('1.2.3')
@@ -52,7 +52,7 @@ public function testIsSupportedWithUnreadableFile()
5252
/**
5353
* @covers \Shivas\VersioningBundle\Provider\RevisionProvider::isSupported
5454
*/
55-
public function testIsSupportedWithWhiteSpaceOnly()
55+
public function testIsSupportedWithWhiteSpaceOnly(): void
5656
{
5757
vfsStream::newFile('REVISION')
5858
->withContent(" \n")
@@ -63,7 +63,7 @@ public function testIsSupportedWithWhiteSpaceOnly()
6363
/**
6464
* @covers \Shivas\VersioningBundle\Provider\RevisionProvider::isSupported
6565
*/
66-
public function testIsSupported()
66+
public function testIsSupported(): void
6767
{
6868
vfsStream::newFile('REVISION')
6969
->withContent('1.2.3')
@@ -74,7 +74,7 @@ public function testIsSupported()
7474
/**
7575
* @covers \Shivas\VersioningBundle\Provider\RevisionProvider::getVersion
7676
*/
77-
public function testGetVersion()
77+
public function testGetVersion(): void
7878
{
7979
vfsStream::newFile('REVISION')
8080
->withContent('1.2.3')
@@ -85,7 +85,7 @@ public function testGetVersion()
8585
/**
8686
* @covers \Shivas\VersioningBundle\Provider\RevisionProvider::getVersion
8787
*/
88-
public function testGetVersionTrimsWhitespace()
88+
public function testGetVersionTrimsWhitespace(): void
8989
{
9090
vfsStream::newFile('REVISION')
9191
->withContent("1.2.3 \n")

0 commit comments

Comments
 (0)