From 944cc1b8a6e4fcaef47305a4c4f54ba388fcf56d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 11 Dec 2020 22:00:07 +0100 Subject: [PATCH] PHPStan 0.12 fixes --- phpstan.neon | 3 +-- src/ContinuesVersionsValidator.php | 5 +++- src/Version.php | 4 +-- tests/ContinuesVersionsValidatorTest.php | 31 +++++++++++++++++++++--- tests/VersionTest.php | 31 ++++++++++++++++-------- 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index d601cbf..c05fef4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,5 +6,4 @@ parameters: paths: - src - tests - autoload_files: - - vendor/autoload.php + ignoreErrors: diff --git a/src/ContinuesVersionsValidator.php b/src/ContinuesVersionsValidator.php index f34f350..d4868cc 100644 --- a/src/ContinuesVersionsValidator.php +++ b/src/ContinuesVersionsValidator.php @@ -106,7 +106,10 @@ private function computePossibleVersionsFromLastExisting(): void $this->possibleVersions = $version->getNextVersionCandidates(); } - private function getLastArrayIndex(array $array) + /** + * @param array $array + */ + private function getLastArrayIndex(array $array): int { end($array); diff --git a/src/Version.php b/src/Version.php index 2873a6c..7220c3e 100644 --- a/src/Version.php +++ b/src/Version.php @@ -50,7 +50,7 @@ final class Version /** * Higher means more stable. * - * @var int[] + * @var array */ private static $stabilityIndexes = [ 'alpha' => self::STABILITY_ALPHA, @@ -81,7 +81,7 @@ private function __construct(int $major, int $minor, int $patch, int $stability, $this->major, $this->minor, $this->patch, - strtoupper(array_search($this->stability, self::$stabilityIndexes, true)), + strtoupper(array_search($this->stability, self::$stabilityIndexes, true)), /** @phpstan-ignore-line */ $this->metaver ); } else { diff --git a/tests/ContinuesVersionsValidatorTest.php b/tests/ContinuesVersionsValidatorTest.php index a59a14a..2efb024 100644 --- a/tests/ContinuesVersionsValidatorTest.php +++ b/tests/ContinuesVersionsValidatorTest.php @@ -19,6 +19,9 @@ class ContinuesVersionsValidatorTest extends TestCase { + /** + * @return array + */ public function provideInitialContinuesVersions(): iterable { yield ['0.1.0']; @@ -31,7 +34,7 @@ public function provideInitialContinuesVersions(): iterable * @test * @dataProvider provideInitialContinuesVersions */ - public function it_accepts_a_continues_version_with_no_pre_existing(string $new) + public function it_accepts_a_continues_version_with_no_pre_existing(string $new): void { $validator = new ContinuesVersionsValidator(); @@ -47,6 +50,9 @@ public function it_accepts_a_continues_version_with_no_pre_existing(string $new) ); } + /** + * @return array> + */ public function provideContinuesVersions(): iterable { yield 'unstable #1' => ['0.3', ['0.2', '0.1'], ['0.2.1', '0.3', '1.0-BETA1', '1.0']]; @@ -63,8 +69,11 @@ public function provideContinuesVersions(): iterable /** * @test * @dataProvider provideContinuesVersions + * + * @param array $existing + * @param array $possible */ - public function it_accepts_a_continues_version(string $new, array $existing, array $possible) + public function it_accepts_a_continues_version(string $new, array $existing, array $possible): void { $validator = new ContinuesVersionsValidator(...$this->createVersions($existing)); @@ -72,6 +81,11 @@ public function it_accepts_a_continues_version(string $new, array $existing, arr self::assertEquals($this->createVersions($possible), array_merge([], $validator->getPossibleVersions())); } + /** + * @param array $existing + * + * @return array + */ private function createVersions(array $existing): array { return array_map( @@ -82,6 +96,9 @@ function (string $version) { ); } + /** + * @return array + */ public function provideNotInitialContinuesVersions(): iterable { yield ['0.2.0']; @@ -95,7 +112,7 @@ public function provideNotInitialContinuesVersions(): iterable * @test * @dataProvider provideNotInitialContinuesVersions */ - public function it_rejects_non_continues_version_with_no_pre_existing(string $new) + public function it_rejects_non_continues_version_with_no_pre_existing(string $new): void { $validator = new ContinuesVersionsValidator(); @@ -111,6 +128,9 @@ public function it_rejects_non_continues_version_with_no_pre_existing(string $ne ); } + /** + * @return array> + */ public function provideNonContinuesVersions(): iterable { yield 'unstable #1' => ['0.5', ['0.2', '0.1'], ['0.2.1', '0.3', '1.0-BETA1', '1.0']]; @@ -127,8 +147,11 @@ public function provideNonContinuesVersions(): iterable /** * @test * @dataProvider provideNonContinuesVersions + * + * @param array $existing + * @param array $possible */ - public function it_rejects_non_continues_version(string $new, array $existing, array $possible) + public function it_rejects_non_continues_version(string $new, array $existing, array $possible): void { $validator = new ContinuesVersionsValidator(...$this->createVersions($existing)); diff --git a/tests/VersionTest.php b/tests/VersionTest.php index fc57d22..90bfca9 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -19,7 +19,7 @@ class VersionTest extends TestCase { /** @test */ - public function it_creates_from_full_string() + public function it_creates_from_full_string(): void { $version = Version::fromString('1.0.0-beta-5'); @@ -33,7 +33,7 @@ public function it_creates_from_full_string() } /** @test */ - public function it_creates_with_explicit_stable() + public function it_creates_with_explicit_stable(): void { $version = Version::fromString('1.0.0-stable'); @@ -47,7 +47,7 @@ public function it_creates_with_explicit_stable() } /** @test */ - public function it_creates_without_patch() + public function it_creates_without_patch(): void { $version = Version::fromString('1.0'); @@ -60,6 +60,9 @@ public function it_creates_without_patch() self::assertEquals('1.0.0', (string) $version); } + /** + * @return array + */ public function provideValidFormats(): array { return [ @@ -77,7 +80,7 @@ public function provideValidFormats(): array * @test * @dataProvider provideValidFormats */ - public function it_supports_various_formats(string $version, string $expectedOutput) + public function it_supports_various_formats(string $version, string $expectedOutput): void { $version = Version::fromString($version); @@ -85,7 +88,7 @@ public function it_supports_various_formats(string $version, string $expectedOut } /** @test */ - public function it_compares_two_versions_are_equal() + public function it_compares_two_versions_are_equal(): void { $version = Version::fromString('1.0.0-beta-5'); $version2 = Version::fromString('1.0.0-beta5'); @@ -96,7 +99,7 @@ public function it_compares_two_versions_are_equal() } /** @test */ - public function it_fails_for_invalid_format() + public function it_fails_for_invalid_format(): void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Unable to parse version "1.0.0-WAT"'); @@ -105,7 +108,7 @@ public function it_fails_for_invalid_format() } /** @test */ - public function it_fails_with_stable_plus_metaver() + public function it_fails_with_stable_plus_metaver(): void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Meta version of the stability flag cannot be set for stable.'); @@ -113,6 +116,9 @@ public function it_fails_with_stable_plus_metaver() Version::fromString('1.0.0-stable-5'); } + /** + * @return array|string>>> + */ public function provideExpectedNextVersionCandidates(): array { return [ @@ -132,8 +138,10 @@ public function provideExpectedNextVersionCandidates(): array /** * @test * @dataProvider provideExpectedNextVersionCandidates + * + * @param array $expected */ - public function it_provides_next_version_candidates($current, $expected) + public function it_provides_next_version_candidates(string $current, array $expected): void { $candidates = Version::fromString($current)->getNextVersionCandidates(); $expected = array_map([Version::class, 'fromString'], $expected); @@ -141,6 +149,9 @@ public function it_provides_next_version_candidates($current, $expected) self::assertEquals($expected, $candidates); } + /** + * @return array + */ public function provideExpectedIncreasedVersion(): array { return [ @@ -199,13 +210,13 @@ public function provideExpectedIncreasedVersion(): array * @test * @dataProvider provideExpectedIncreasedVersion */ - public function it_increases_to_next_version(string $current, string $expected, $stability) + public function it_increases_to_next_version(string $current, string $expected, string $stability): void { self::assertEquals(Version::fromString($expected), Version::fromString($current)->getNextIncreaseOf($stability)); } /** @test */ - public function it_cannot_increases_for_unsupported() + public function it_cannot_increases_for_unsupported(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Unknown stability "next-stable", accepts "alpha", "beta", "rc", "stable", "major", "next", "minor", "patch".');