From 26412dfec676b48b9607180e00a8e496c6697377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 11 Mar 2020 11:25:12 +0100 Subject: [PATCH] Fix: Annotations --- src/Helper.php | 63 ++++++++++++++++++++++------------------ test/Unit/HelperTest.php | 19 +++++++----- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/Helper.php b/src/Helper.php index 0559cc8b..25a3743e 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -33,6 +33,9 @@ trait Helper */ final protected static function faker(string $locale = 'en_US'): Generator { + /** + * @var array + */ static $fakers = []; if (!\array_key_exists($locale, $fakers)) { @@ -51,8 +54,8 @@ final protected static function faker(string $locale = 'en_US'): Generator * * Useful to prevent long inheritance chains. * - * @param string $directory - * @param string[] $excludeClassNames + * @param string $directory + * @param class-string[] $excludeClassNames * * @throws Exception\NonExistentDirectory * @throws Exception\InvalidExcludeClassName @@ -80,10 +83,10 @@ static function (string $className): bool { /** * Asserts that classes in a directory have matching test classes extending from PHPUnit\Framework\TestCase. * - * @param string $directory - * @param string $namespace - * @param string $testNamespace - * @param string[] $excludeClassyNames + * @param string $directory + * @param string $namespace + * @param string $testNamespace + * @param class-string[] $excludeClassyNames * * @throws Exception\NonExistentDirectory * @throws Exception\InvalidExcludeClassName @@ -128,6 +131,7 @@ final protected static function assertClassesHaveTests(string $directory, string }; $classesWithoutTests = \array_filter($classyNames, static function (string $className) use ($testClassNameFrom): bool { + /** @var class-string $className */ $reflection = new \ReflectionClass($className); /** @@ -147,6 +151,7 @@ final protected static function assertClassesHaveTests(string $directory, string $testClassName = $testClassNameFrom($className); if (\class_exists($testClassName)) { + /** @var class-string $testClassName */ $testReflection = new \ReflectionClass($testClassName); if ($testReflection->isSubclassOf(Framework\TestCase::class) && $testReflection->isInstantiable()) { @@ -182,10 +187,10 @@ final protected static function assertClassesHaveTests(string $directory, string * * The specification will be invoked with a single argument, the class name, and should return true or false. * - * @param callable $specification - * @param string $directory - * @param string[] $excludeClassyNames - * @param string $message + * @param callable $specification + * @param string $directory + * @param class-string[] $excludeClassyNames + * @param string $message * * @throws Exception\NonExistentDirectory * @throws Exception\InvalidExcludeClassName @@ -241,8 +246,8 @@ final protected static function assertClassExists(string $className): void /** * Asserts that a class extends from a parent class. * - * @param string $parentClassName - * @param string $className + * @param class-string $parentClassName + * @param class-string $className */ final protected static function assertClassExtends(string $parentClassName, string $className): void { @@ -262,8 +267,8 @@ final protected static function assertClassExtends(string $parentClassName, stri /** * Asserts that a class implements an interface. * - * @param string $interfaceName - * @param string $className + * @param class-string $interfaceName + * @param class-string $className */ final protected static function assertClassImplementsInterface(string $interfaceName, string $className): void { @@ -283,7 +288,7 @@ final protected static function assertClassImplementsInterface(string $interface /** * Asserts that a class is abstract. * - * @param string $className + * @param class-string $className */ final protected static function assertClassIsAbstract(string $className): void { @@ -303,7 +308,7 @@ final protected static function assertClassIsAbstract(string $className): void * * Useful to prevent long inheritance chains. * - * @param string $className + * @param class-string $className */ final protected static function assertClassIsFinal(string $className): void { @@ -323,9 +328,9 @@ final protected static function assertClassIsFinal(string $className): void * * The specification will be invoked with a single argument, the class name, and should return true or false. * - * @param callable $specification - * @param string $className - * @param string $message + * @param callable(class-string):bool $specification + * @param class-string $className + * @param string $message */ final protected static function assertClassSatisfiesSpecification(callable $specification, string $className, string $message = ''): void { @@ -340,8 +345,8 @@ final protected static function assertClassSatisfiesSpecification(callable $spec /** * Asserts that a class uses a trait. * - * @param string $traitName - * @param string $className + * @param class-string $traitName + * @param class-string $className */ final protected static function assertClassUsesTrait(string $traitName, string $className): void { @@ -371,8 +376,8 @@ final protected static function assertInterfaceExists(string $interfaceName): vo /** * Asserts that an interface extends a parent interface. * - * @param string $parentInterfaceName - * @param string $interfaceName + * @param class-string $parentInterfaceName + * @param class-string $interfaceName */ final protected static function assertInterfaceExtends(string $parentInterfaceName, string $interfaceName): void { @@ -394,9 +399,9 @@ final protected static function assertInterfaceExtends(string $parentInterfaceNa * * The specification will be invoked with a single argument, the class name, and should return true or false. * - * @param callable $specification - * @param string $interfaceName - * @param string $message + * @param callable(class-string):bool $specification + * @param class-string $interfaceName + * @param string $message */ final protected static function assertInterfaceSatisfiesSpecification(callable $specification, string $interfaceName, string $message = ''): void { @@ -426,9 +431,9 @@ final protected static function assertTraitExists(string $traitName): void * * The specification will be invoked with a single argument, the class name, and should return true or false. * - * @param callable $specification - * @param string $traitName - * @param string $message + * @param callable(class-string):bool $specification + * @param class-string $traitName + * @param string $message */ final protected static function assertTraitSatisfiesSpecification(callable $specification, string $traitName, string $message = ''): void { diff --git a/test/Unit/HelperTest.php b/test/Unit/HelperTest.php index 37ea7dee..37683d16 100644 --- a/test/Unit/HelperTest.php +++ b/test/Unit/HelperTest.php @@ -91,7 +91,7 @@ public function testFakerReturnsSameFaker(string $locale): void } /** - * @return \Generator> + * @return \Generator> */ public function providerLocale(): \Generator { @@ -177,7 +177,7 @@ public function testAssertClassesAreAbstractOrFinalWithExcludeClassNamesRejectsI } /** - * @return \Generator> + * @return \Generator> */ public function providerInvalidExcludeClassyName(): \Generator { @@ -361,7 +361,7 @@ public function testAssertClassesHaveTestsWorksWithAndWithoutTrailingSlash(strin } /** - * @return \Generator> + * @return \Generator> */ public function providerNamespaceAndTestNamespace(): \Generator { @@ -551,7 +551,7 @@ public function testAssertClassyConstructsSatisfySpecificationWithExcludeClassNa $this->expectException(Exception\InvalidExcludeClassName::class); self::assertClassyConstructsSatisfySpecification( - static function (string $classyName): bool { + static function (): bool { return true; }, $directory, @@ -638,7 +638,7 @@ public function testAssertClassExistsFailsWhenClassIsNotClass(string $className) } /** - * @return \Generator> + * @return \Generator> */ public function providerNotClass(): \Generator { @@ -1035,7 +1035,7 @@ public function testAssertInterfaceExistsFailsWhenInterfaceIsNotInterface(string } /** - * @return \Generator> + * @return \Generator> */ public function providerNotInterface(): \Generator { @@ -1135,7 +1135,7 @@ public function testAssertInterfaceExtendsSucceedsWhenInterfaceExtendsParentInte * * @param string $interfaceName */ - public function testAssertInterfaceSatisfiesSpecificationFailsWhenInterfaceIsNotAInterface(string $interfaceName): void + public function testAssertInterfaceSatisfiesSpecificationFailsWhenInterfaceIsNotInterface(string $interfaceName): void { $this->expectException(Framework\AssertionFailedError::class); $this->expectExceptionMessage(\sprintf( @@ -1315,9 +1315,12 @@ static function (): bool { private function assertHasOnlyProvidersWithLocale(string $locale, Generator $faker): void { + /** @var Provider\Base[] $providers */ + $providers = $faker->getProviders(); + $providerClasses = \array_map(static function (Provider\Base $provider): string { return \get_class($provider); - }, $faker->getProviders()); + }, $providers); $providerLocales = \array_reduce( $providerClasses,