From c1648e58c5aa5066cdf2eed8817c6316cf0a105d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 27 Jul 2022 22:52:34 +0700 Subject: [PATCH] Apply PHP 7.4 syntax and typed property Signed-off-by: Abdul Malik Ikhsan --- src/Annotation/AbstractBuilder.php | 8 ++----- src/Annotation/AllowEmpty.php | 3 +-- src/Annotation/Attributes.php | 3 +-- src/Annotation/BuilderAbstractFactory.php | 2 +- src/Annotation/ContinueIfEmpty.php | 3 +-- src/Annotation/ElementAnnotationsListener.php | 4 ++-- src/Annotation/ErrorMessage.php | 3 +-- src/Annotation/Flags.php | 3 +-- src/Annotation/Input.php | 3 +-- src/Annotation/Instance.php | 3 +-- src/Annotation/Name.php | 3 +-- src/Annotation/Options.php | 3 +-- src/Annotation/Required.php | 3 +-- src/Annotation/Type.php | 3 +-- src/Annotation/ValidationGroup.php | 3 +-- src/Element/Captcha.php | 4 ++-- src/Factory.php | 5 +++-- src/FormAbstractServiceFactory.php | 5 +++-- src/InputFilterProviderFieldset.php | 4 +--- src/View/Helper/FormCollection.php | 3 +-- test/Annotation/AbstractBuilderTestCase.php | 3 ++- test/Element/CollectionTest.php | 19 +++++++---------- test/Element/DateTest.php | 4 +--- test/Element/TelTest.php | 4 +--- test/FactoryTest.php | 6 ++---- test/FieldsetTest.php | 9 ++++---- test/FormAbstractServiceFactoryTest.php | 6 ++---- test/FormElementManagerFactoryTest.php | 8 ++----- test/FormElementManagerTest.php | 21 ++++++++++--------- test/FormTest.php | 3 +-- test/InputFilterProviderFieldsetTest.php | 3 +-- test/Integration/ServiceManagerTest.php | 10 +++------ .../LegacyComposedObjectAnnotation.php | 2 +- .../Annotation/LegacyHydratorAnnotation.php | 2 +- test/TestAsset/CustomCreatedForm.php | 3 +-- test/TestAsset/CustomTraversable.php | 3 +-- test/TestAsset/FieldsetWithDependency.php | 4 ++-- test/TestAsset/HydratorStrategy.php | 4 +--- test/TestAsset/HydratorStrategyEntityA.php | 5 ++--- test/TestAsset/HydratorStrategyEntityB.php | 6 ++---- test/TestAsset/Identifier.php | 3 +-- test/View/Helper/Captcha/DumbTest.php | 3 +-- test/View/Helper/Captcha/FigletTest.php | 3 +-- test/View/Helper/Captcha/ImageTest.php | 9 +++----- test/View/Helper/Captcha/ReCaptchaTest.php | 3 +-- .../Factory/FormElementErrorsFactoryTest.php | 4 +--- test/View/Helper/FormButtonTest.php | 2 +- test/View/Helper/FormCaptchaTest.php | 6 ++---- test/View/Helper/FormCollectionTest.php | 3 ++- test/View/Helper/FormElementErrorsTest.php | 3 +-- test/View/Helper/FormLabelTest.php | 2 +- 51 files changed, 91 insertions(+), 146 deletions(-) diff --git a/src/Annotation/AbstractBuilder.php b/src/Annotation/AbstractBuilder.php index 2fc7e72ea..2b61e6211 100644 --- a/src/Annotation/AbstractBuilder.php +++ b/src/Annotation/AbstractBuilder.php @@ -293,9 +293,7 @@ protected function discoverName(AnnotationCollection $annotations, Reflector $re // @codingStandardsIgnoreStart $results = $this->getEventManager()->triggerEventUntil( - static function (?string $r): bool { - return $r !== null && $r !== ''; - }, + static fn(?string $r): bool => $r !== null && $r !== '', $event ); // @codingStandardsIgnoreEnd @@ -317,9 +315,7 @@ protected function checkForExclude(AnnotationCollection $annotations): bool // @codingStandardsIgnoreStart $results = $this->getEventManager()->triggerEventUntil( - static function (bool $r): bool { - return true === $r; - }, + static fn(bool $r): bool => true === $r, $event ); // @codingStandardsIgnoreEnd diff --git a/src/Annotation/AllowEmpty.php b/src/Annotation/AllowEmpty.php index df783dd8e..bfc7b03a9 100644 --- a/src/Annotation/AllowEmpty.php +++ b/src/Annotation/AllowEmpty.php @@ -25,8 +25,7 @@ #[Attribute] final class AllowEmpty { - /** @var bool */ - protected $allowEmpty; + protected bool $allowEmpty; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/Attributes.php b/src/Annotation/Attributes.php index eeaeacb66..85496f4c9 100644 --- a/src/Annotation/Attributes.php +++ b/src/Annotation/Attributes.php @@ -20,8 +20,7 @@ #[Attribute] final class Attributes { - /** @var array */ - protected $attributes; + protected array $attributes; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/BuilderAbstractFactory.php b/src/Annotation/BuilderAbstractFactory.php index cd228fd2c..d8c647613 100644 --- a/src/Annotation/BuilderAbstractFactory.php +++ b/src/Annotation/BuilderAbstractFactory.php @@ -18,7 +18,7 @@ final class BuilderAbstractFactory implements AbstractFactoryInterface { /** @var string[] */ - protected $aliases = [ + protected array $aliases = [ 'FormAnnotationBuilder' => AnnotationBuilder::class, 'FormAttributeBuilder' => AttributeBuilder::class, ]; diff --git a/src/Annotation/ContinueIfEmpty.php b/src/Annotation/ContinueIfEmpty.php index 0389487e6..8ed0aa6ea 100644 --- a/src/Annotation/ContinueIfEmpty.php +++ b/src/Annotation/ContinueIfEmpty.php @@ -25,8 +25,7 @@ #[Attribute] final class ContinueIfEmpty { - /** @var bool */ - protected $continueIfEmpty; + protected bool $continueIfEmpty; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/ElementAnnotationsListener.php b/src/Annotation/ElementAnnotationsListener.php index ab5d9b71f..aa058f160 100644 --- a/src/Annotation/ElementAnnotationsListener.php +++ b/src/Annotation/ElementAnnotationsListener.php @@ -165,8 +165,8 @@ public function handleComposedObjectAnnotation(EventInterface $e): void } if (isset($elementSpec['spec']['options'])) { - $specification['options'] = $specification['options'] ?? []; - $specification['options'] = array_merge($elementSpec['spec']['options'], $specification['options']); + $specification['options'] ??= []; + $specification['options'] = array_merge($elementSpec['spec']['options'], $specification['options']); } // Add element spec: diff --git a/src/Annotation/ErrorMessage.php b/src/Annotation/ErrorMessage.php index b32120d3b..e01e97ac7 100644 --- a/src/Annotation/ErrorMessage.php +++ b/src/Annotation/ErrorMessage.php @@ -20,8 +20,7 @@ #[Attribute] final class ErrorMessage { - /** @var string */ - protected $message; + protected string $message; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/Flags.php b/src/Annotation/Flags.php index 289dfa1a9..f713c28eb 100644 --- a/src/Annotation/Flags.php +++ b/src/Annotation/Flags.php @@ -23,8 +23,7 @@ #[Attribute] final class Flags { - /** @var array */ - protected $flags; + protected array $flags; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/Input.php b/src/Annotation/Input.php index 3f185702f..9b65addef 100644 --- a/src/Annotation/Input.php +++ b/src/Annotation/Input.php @@ -21,8 +21,7 @@ #[Attribute] final class Input { - /** @var string */ - protected $input; + protected string $input; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/Instance.php b/src/Annotation/Instance.php index 042aaf63a..54c6f7241 100644 --- a/src/Annotation/Instance.php +++ b/src/Annotation/Instance.php @@ -20,8 +20,7 @@ #[Attribute] final class Instance { - /** @var string */ - protected $instance; + protected string $instance; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/Name.php b/src/Annotation/Name.php index 916fcd016..a802b4517 100644 --- a/src/Annotation/Name.php +++ b/src/Annotation/Name.php @@ -20,8 +20,7 @@ #[Attribute] final class Name { - /** @var string */ - protected $name; + protected string $name; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/Options.php b/src/Annotation/Options.php index 3b49b0014..c40042897 100644 --- a/src/Annotation/Options.php +++ b/src/Annotation/Options.php @@ -22,8 +22,7 @@ #[Attribute] final class Options { - /** @var array */ - protected $options; + protected array $options; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/Required.php b/src/Annotation/Required.php index c85522c03..8b66dc14f 100644 --- a/src/Annotation/Required.php +++ b/src/Annotation/Required.php @@ -25,8 +25,7 @@ #[Attribute] final class Required { - /** @var bool */ - protected $required; + protected bool $required; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/Type.php b/src/Annotation/Type.php index 36fa87d70..fcfacac4f 100644 --- a/src/Annotation/Type.php +++ b/src/Annotation/Type.php @@ -21,8 +21,7 @@ #[Attribute] final class Type { - /** @var string */ - protected $type; + protected string $type; /** * Receive and process the contents of an annotation diff --git a/src/Annotation/ValidationGroup.php b/src/Annotation/ValidationGroup.php index d58e25a2e..b59f0ba2f 100644 --- a/src/Annotation/ValidationGroup.php +++ b/src/Annotation/ValidationGroup.php @@ -21,8 +21,7 @@ #[Attribute] final class ValidationGroup { - /** @var array */ - protected $validationGroup; + protected array $validationGroup; /** * Receive and process the contents of an annotation diff --git a/src/Element/Captcha.php b/src/Element/Captcha.php index 229befcc6..28d7e7e4e 100644 --- a/src/Element/Captcha.php +++ b/src/Element/Captcha.php @@ -13,7 +13,7 @@ use function get_class; use function gettype; -use function is_array; +use function is_iterable; use function is_object; use function sprintf; @@ -48,7 +48,7 @@ public function setOptions(iterable $options) */ public function setCaptcha($captcha) { - if (is_array($captcha) || $captcha instanceof Traversable) { + if (is_iterable($captcha)) { $captcha = LaminasCaptcha\Factory::factory($captcha); } elseif (! $captcha instanceof LaminasCaptcha\AdapterInterface) { throw new Exception\InvalidArgumentException(sprintf( diff --git a/src/Factory.php b/src/Factory.php index 98fbcea77..57f6547e1 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -17,6 +17,7 @@ use function get_class; use function gettype; use function is_array; +use function is_iterable; use function is_object; use function is_string; use function method_exists; @@ -197,11 +198,11 @@ public function configureElement(ElementInterface $element, $spec): ElementInter $element->setName($name); } - if (is_array($options) || $options instanceof Traversable) { + if (is_iterable($options)) { $element->setOptions($options); } - if (is_array($attributes) || $attributes instanceof Traversable) { + if (is_iterable($attributes)) { $element->setAttributes($attributes); } diff --git a/src/FormAbstractServiceFactory.php b/src/FormAbstractServiceFactory.php index ec7f90b73..0f3253b3e 100644 --- a/src/FormAbstractServiceFactory.php +++ b/src/FormAbstractServiceFactory.php @@ -6,6 +6,7 @@ use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\Filter\FilterPluginManager; +use Laminas\Form\Factory; use Laminas\InputFilter\InputFilterInterface; use Laminas\InputFilter\InputFilterPluginManager; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; @@ -20,10 +21,10 @@ final class FormAbstractServiceFactory implements AbstractFactoryInterface protected $config; /** @var string Top-level configuration key indicating forms configuration */ - protected $configKey = 'forms'; + protected string $configKey = 'forms'; /** @var null|Factory Form factory used to create forms */ - protected $factory; + protected ?Factory $factory = null; /** * Create a form (v3) diff --git a/src/InputFilterProviderFieldset.php b/src/InputFilterProviderFieldset.php index 265c27835..d32bae5e1 100644 --- a/src/InputFilterProviderFieldset.php +++ b/src/InputFilterProviderFieldset.php @@ -12,10 +12,8 @@ final class InputFilterProviderFieldset extends Fieldset implements InputFilterP { /** * Holds the specification which will be returned by getInputFilterSpecification - * - * @var array */ - protected $filterSpec = []; + protected array $filterSpec = []; public function getInputFilterSpecification(): array { diff --git a/src/View/Helper/FormCollection.php b/src/View/Helper/FormCollection.php index 6f845916e..23b055d98 100644 --- a/src/View/Helper/FormCollection.php +++ b/src/View/Helper/FormCollection.php @@ -77,8 +77,7 @@ class FormCollection extends AbstractHelper */ protected $fieldsetHelper; - /** @var array */ - private $doctypesAllowedToHaveNameAttribute = [ + private array $doctypesAllowedToHaveNameAttribute = [ Doctype::HTML5 => true, Doctype::XHTML5 => true, ]; diff --git a/test/Annotation/AbstractBuilderTestCase.php b/test/Annotation/AbstractBuilderTestCase.php index 0758eb407..487cad464 100644 --- a/test/Annotation/AbstractBuilderTestCase.php +++ b/test/Annotation/AbstractBuilderTestCase.php @@ -4,6 +4,7 @@ namespace LaminasTest\Form\Annotation; +use ArrayObject; use Generator; use Laminas\Form\Annotation; use Laminas\Form\Element; @@ -163,7 +164,7 @@ public function testCanRetrieveOnlyFormSpecification(): void $entity = new TestAsset\Annotation\ComplexEntity(); $builder = $this->createBuilder(); $spec = $builder->getFormSpecification($entity); - $this->assertInstanceOf('ArrayObject', $spec); + $this->assertInstanceOf(ArrayObject::class, $spec); } public function testAllowsExtensionOfEntities(): void diff --git a/test/Element/CollectionTest.php b/test/Element/CollectionTest.php index 82f1ff60b..16cd34749 100644 --- a/test/Element/CollectionTest.php +++ b/test/Element/CollectionTest.php @@ -4,6 +4,7 @@ namespace LaminasTest\Form\Element; +use ArrayAccess; use ArrayObject; use Laminas\Form\Element; use Laminas\Form\Element\Collection; @@ -42,10 +43,8 @@ final class CollectionTest extends TestCase { - /** @var FormCollection */ - protected $form; - /** @var ProductFieldset */ - protected $productFieldset; + protected FormCollection $form; + protected ProductFieldset $productFieldset; protected function setUp(): void { @@ -689,9 +688,7 @@ public function testExtractThroughCustomHydrator(): void $mockHydrator = $this->createMock(HydratorInterface::class); $mockHydrator->expects($this->exactly(2)) ->method('extract') - ->willReturnCallback(static function (object $object): array { - return ['value' => $object->field . '_foo']; - }); + ->willReturnCallback(static fn(object $object): array => ['value' => $object->field . '_foo']); $collection->setHydrator($mockHydrator); @@ -834,7 +831,7 @@ public function testCollectionCanBindObjectAndPopulateAndExtractNestedFieldsets( foreach ($marketCollection as $shopFieldset) { $this->assertInstanceOf(Fieldset::class, $shopFieldset); - $this->assertInstanceOf('stdClass', $shopFieldset->getObject()); + $this->assertInstanceOf(stdClass::class, $shopFieldset->getObject()); // test for collection -> fieldset $productFieldset = $shopFieldset->get('product'); @@ -1255,7 +1252,7 @@ public function testCollectionProperlyHandlesAddingObjectsOfTypeElementInterface $this->assertTrue($form->isValid()); $result = $form->getData(); - $this->assertInstanceOf('ArrayAccess', $result); + $this->assertInstanceOf(ArrayAccess::class, $result); $this->assertArrayHasKey('text', $result); $this->assertIsArray($result['text']); $this->assertArrayHasKey(0, $result['text']); @@ -1296,11 +1293,11 @@ public function testCollectionShouldSilentlyIgnorePopulatingFieldsetWithDisallow $this->assertTrue($form->isValid()); $result = $form->getData(); - $this->assertInstanceOf('stdClass', $result); + $this->assertInstanceOf(stdClass::class, $result); $this->assertObjectHasAttribute('collection', $result); $this->assertIsArray($result->collection); $this->assertCount(1, $result->collection); - $this->assertInstanceOf('ArrayObject', $result->collection[0]); + $this->assertInstanceOf(ArrayObject::class, $result->collection[0]); $this->assertArrayHasKey('test', $result->collection[0]); $this->assertEquals('bar', $result->collection[0]['test']); } diff --git a/test/Element/DateTest.php b/test/Element/DateTest.php index 6d94b4b24..c3c2bfaba 100644 --- a/test/Element/DateTest.php +++ b/test/Element/DateTest.php @@ -26,10 +26,8 @@ final class DateTest extends TestCase { /** * Stores the original set timezone - * - * @var string */ - private $originaltimezone; + private string $originaltimezone; /** * {@inheritDoc} diff --git a/test/Element/TelTest.php b/test/Element/TelTest.php index df6e8ce36..5f2a672f8 100644 --- a/test/Element/TelTest.php +++ b/test/Element/TelTest.php @@ -42,9 +42,7 @@ public function testInputSpecification(): void */ private function assertInputSpecContainsFilters(array $expectedFilters, array $inputSpec): void { - $actualFilters = array_map(static function (array $filterSpec): string { - return $filterSpec['name']; - }, $inputSpec['filters']); + $actualFilters = array_map(static fn(array $filterSpec): string => $filterSpec['name'], $inputSpec['filters']); $missingFilters = array_diff($expectedFilters, $actualFilters); $this->assertCount(0, $missingFilters); } diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 145871cc6..c9938821d 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -29,11 +29,9 @@ final class FactoryTest extends TestCase { - /** @var FormFactory */ - protected $factory; + protected FormFactory $factory; - /** @var ServiceManager */ - protected $services; + protected ServiceManager $services; protected function setUp(): void { diff --git a/test/FieldsetTest.php b/test/FieldsetTest.php index 186934de5..4ff6af038 100644 --- a/test/FieldsetTest.php +++ b/test/FieldsetTest.php @@ -11,6 +11,7 @@ use Laminas\Form\Form; use Laminas\Form\FormElementManager; use Laminas\Hydrator; +use Laminas\Hydrator\HydratorInterface; use Laminas\InputFilter\InputFilter; use Laminas\ServiceManager\PluginManagerInterface; use PHPUnit\Framework\TestCase; @@ -19,11 +20,9 @@ final class FieldsetTest extends TestCase { - /** @var Fieldset */ - private $fieldset; + private Fieldset $fieldset; - /** @var Hydrator\HydratorInterface */ - private $hydrator; + private HydratorInterface $hydrator; protected function setUp(): void { @@ -529,7 +528,7 @@ public function testSetObjectWithStringRaisesException(): void public function testShouldValidateAllowObjectBindingByClassname(): void { $object = new stdClass(); - $this->fieldset->setAllowedObjectBindingClass('stdClass'); + $this->fieldset->setAllowedObjectBindingClass(stdClass::class); $allowed = $this->fieldset->allowObjectBinding($object); $this->assertTrue($allowed); diff --git a/test/FormAbstractServiceFactoryTest.php b/test/FormAbstractServiceFactoryTest.php index a401a0568..0434beaef 100644 --- a/test/FormAbstractServiceFactoryTest.php +++ b/test/FormAbstractServiceFactoryTest.php @@ -20,10 +20,8 @@ final class FormAbstractServiceFactoryTest extends TestCase { - /** @var ServiceManager */ - private $services; - /** @var FormAbstractServiceFactory */ - private $forms; + private ServiceManager $services; + private FormAbstractServiceFactory $forms; protected function setUp(): void { diff --git a/test/FormElementManagerFactoryTest.php b/test/FormElementManagerFactoryTest.php index 01df6f036..d6fa91ed3 100644 --- a/test/FormElementManagerFactoryTest.php +++ b/test/FormElementManagerFactoryTest.php @@ -54,9 +54,7 @@ public function testConfiguresFormElementsServicesWhenFound(): void 'test' => Number::class, ], 'factories' => [ - 'test-too' => function ($container) use ($element): ElementInterface { - return $element; - }, + 'test-too' => static fn($container): ElementInterface => $element, ], ], ]; @@ -87,9 +85,7 @@ public function testDoesNotConfigureFormElementsServicesWhenServiceListenerPrese 'test' => Number::class, ], 'factories' => [ - 'test-too' => function ($container) use ($element): ElementInterface { - return $element; - }, + 'test-too' => static fn($container): ElementInterface => $element, ], ], ]; diff --git a/test/FormElementManagerTest.php b/test/FormElementManagerTest.php index 1ab37a4f6..5013ba266 100644 --- a/test/FormElementManagerTest.php +++ b/test/FormElementManagerTest.php @@ -31,8 +31,7 @@ */ final class FormElementManagerTest extends TestCase { - /** @var FormElementManager */ - protected $manager; + protected FormElementManager $manager; protected function setUp(): void { @@ -51,7 +50,7 @@ public function testInjectToFormFactoryAware(): void public function testInjectsFormElementManagerToFormComposedByFormFactoryAwareElement(): void { $factory = new Factory(); - $this->manager->setFactory('my-form', function ($elements) use ($factory) { + $this->manager->setFactory('my-form', static function ($elements) use ($factory) { $form = new Form(); $form->setFormFactory($factory); return $form; @@ -128,9 +127,7 @@ public function testSharedFormElementsAreNotInitializedMultipleTimes(): void $element->expects($this->once())->method('init'); - $this->manager->setFactory('sharedElement', function () use ($element) { - return $element; - }); + $this->manager->setFactory('sharedElement', static fn() => $element); $this->manager->setShared('sharedElement', true); @@ -152,8 +149,10 @@ public function testInjectFactoryInitializerShouldBeRegisteredFirst(): void { // @codingStandardsIgnoreStart $initializers = [ - function (): void {}, - function (): void {}, + static function () : void { + }, + static function () : void { + }, ]; // @codingStandardsIgnoreEnd @@ -178,8 +177,10 @@ public function testCallElementInitInitializerShouldBeRegisteredLast(): void { // @codingStandardsIgnoreStart $initializers = [ - function (): void {}, - function (): void {}, + static function () : void { + }, + static function () : void { + }, ]; // @codingStandardsIgnoreEnd diff --git a/test/FormTest.php b/test/FormTest.php index d172bd37a..2fa1f3f2b 100644 --- a/test/FormTest.php +++ b/test/FormTest.php @@ -35,8 +35,7 @@ final class FormTest extends TestCase { - /** @var Form */ - protected $form; + protected Form $form; protected function setUp(): void { diff --git a/test/InputFilterProviderFieldsetTest.php b/test/InputFilterProviderFieldsetTest.php index a6bda4e49..c8ead1678 100644 --- a/test/InputFilterProviderFieldsetTest.php +++ b/test/InputFilterProviderFieldsetTest.php @@ -9,8 +9,7 @@ final class InputFilterProviderFieldsetTest extends TestCase { - /** @var InputFilterProviderFieldset */ - private $fieldset; + private InputFilterProviderFieldset $fieldset; protected function setUp(): void { diff --git a/test/Integration/ServiceManagerTest.php b/test/Integration/ServiceManagerTest.php index a7a26e030..017a5c6f5 100644 --- a/test/Integration/ServiceManagerTest.php +++ b/test/Integration/ServiceManagerTest.php @@ -52,9 +52,7 @@ public function testInitInitializerShouldBeCalledAfterAllOtherInitializers(): vo $formElementManagerConfig = new Config([ 'factories' => [ - 'InitializableElement' => static function () use ($element): Element { - return $element->reveal(); - }, + 'InitializableElement' => fn(): Element => $element->reveal(), ], 'initializers' => [ $initializer->reveal(), @@ -81,7 +79,7 @@ public function testInjectFactoryInitializerShouldTriggerBeforeInitInitializer() $formElementManager = $serviceManager->get('FormElementManager'); $initializer = $this->prophesize(InitializerInterface::class); - $formElementManagerAssertion = static function ($form) use ($formElementManager): bool { + $formElementManagerAssertion = function ($form) use ($formElementManager): bool { TestCase::assertInstanceOf(Form::class, $form); TestCase::assertSame($formElementManager, $form->getFormFactory()->getFormElementManager()); return true; @@ -93,9 +91,7 @@ public function testInjectFactoryInitializerShouldTriggerBeforeInitInitializer() $formElementManagerConfig = new Config([ 'factories' => [ - 'MyForm' => function () { - return new TestAsset\Form(); - }, + 'MyForm' => fn() => new TestAsset\Form(), ], 'initializers' => [ $initializer->reveal(), diff --git a/test/TestAsset/Annotation/LegacyComposedObjectAnnotation.php b/test/TestAsset/Annotation/LegacyComposedObjectAnnotation.php index a90444dd1..f8f8733cb 100644 --- a/test/TestAsset/Annotation/LegacyComposedObjectAnnotation.php +++ b/test/TestAsset/Annotation/LegacyComposedObjectAnnotation.php @@ -19,6 +19,6 @@ class LegacyComposedObjectAnnotation */ #[Annotation\Name("composed")] // @codingStandardsIgnoreLine - #[Annotation\ComposedObject(["target_object" => "LaminasTest\Form\TestAsset\Annotation\Entity", "is_collection" => "true"])] + #[Annotation\ComposedObject(["target_object" => \LaminasTest\Form\TestAsset\Annotation\Entity::class, "is_collection" => "true"])] public $child; } diff --git a/test/TestAsset/Annotation/LegacyHydratorAnnotation.php b/test/TestAsset/Annotation/LegacyHydratorAnnotation.php index b9ce56d2e..d190af2b8 100644 --- a/test/TestAsset/Annotation/LegacyHydratorAnnotation.php +++ b/test/TestAsset/Annotation/LegacyHydratorAnnotation.php @@ -12,7 +12,7 @@ * @Annotation\Hydrator({"type": "Laminas\Hydrator\ClassMethodsHydrator", "options":{"underscoreSeparatedKeys": false}}) */ #[Annotation\Name("user")] -#[Annotation\Hydrator(["type" => "Laminas\Hydrator\ClassMethodsHydrator", "options" => ["underscoreSeparatedKeys" => false]])] +#[Annotation\Hydrator(["type" => \Laminas\Hydrator\ClassMethodsHydrator::class, "options" => ["underscoreSeparatedKeys" => false]])] class LegacyHydratorAnnotation { /** diff --git a/test/TestAsset/CustomCreatedForm.php b/test/TestAsset/CustomCreatedForm.php index 61a4606f5..48a049e82 100644 --- a/test/TestAsset/CustomCreatedForm.php +++ b/test/TestAsset/CustomCreatedForm.php @@ -9,8 +9,7 @@ class CustomCreatedForm extends Form { - /** @var DateTime */ - private $created; + private DateTime $created; public function __construct(DateTime $created, ?string $name = null, array $options = []) { diff --git a/test/TestAsset/CustomTraversable.php b/test/TestAsset/CustomTraversable.php index d9c476d63..27429b262 100644 --- a/test/TestAsset/CustomTraversable.php +++ b/test/TestAsset/CustomTraversable.php @@ -14,8 +14,7 @@ class CustomTraversable implements Iterator { - /** @var array */ - private $data; + private array $data; public function __construct(array $data) { diff --git a/test/TestAsset/FieldsetWithDependency.php b/test/TestAsset/FieldsetWithDependency.php index 77c4ab1c9..b24dce04a 100644 --- a/test/TestAsset/FieldsetWithDependency.php +++ b/test/TestAsset/FieldsetWithDependency.php @@ -5,11 +5,11 @@ namespace LaminasTest\Form\TestAsset; use Laminas\Form\Fieldset; +use LaminasTest\Form\TestAsset\InputFilter; class FieldsetWithDependency extends Fieldset { - /** @var InputFilter */ - private $dependency; + private InputFilter $dependency; /** * @inheritDoc diff --git a/test/TestAsset/HydratorStrategy.php b/test/TestAsset/HydratorStrategy.php index 79fe9e2aa..9ac766438 100644 --- a/test/TestAsset/HydratorStrategy.php +++ b/test/TestAsset/HydratorStrategy.php @@ -12,10 +12,8 @@ class HydratorStrategy extends DefaultStrategy { /** * A simulated storage device which is just an array with Car objects. - * - * @var array */ - private $simulatedStorageDevice; + private array $simulatedStorageDevice; public function __construct() { diff --git a/test/TestAsset/HydratorStrategyEntityA.php b/test/TestAsset/HydratorStrategyEntityA.php index dfaa50016..1fd70cce2 100644 --- a/test/TestAsset/HydratorStrategyEntityA.php +++ b/test/TestAsset/HydratorStrategyEntityA.php @@ -14,9 +14,8 @@ class HydratorStrategyEntityA implements InputFilterAwareInterface { /** @var HydratorStrategyEntityB[] */ - public $entities = []; // public to make testing easier! - /** @var null|InputFilterInterface */ - private $inputFilter; // used to test forms + public $entities = []; + private ?InputFilterInterface $inputFilter = null; // used to test forms public function addEntity(HydratorStrategyEntityB $entity): void { diff --git a/test/TestAsset/HydratorStrategyEntityB.php b/test/TestAsset/HydratorStrategyEntityB.php index 82e8a9901..cae9fb340 100644 --- a/test/TestAsset/HydratorStrategyEntityB.php +++ b/test/TestAsset/HydratorStrategyEntityB.php @@ -6,10 +6,8 @@ class HydratorStrategyEntityB { - /** @var int */ - private $field1; - /** @var string */ - private $field2; + private int $field1; + private string $field2; public function __construct(int $field1, string $field2) { diff --git a/test/TestAsset/Identifier.php b/test/TestAsset/Identifier.php index 7c5ddaf3a..fad1c4dce 100644 --- a/test/TestAsset/Identifier.php +++ b/test/TestAsset/Identifier.php @@ -6,8 +6,7 @@ class Identifier { - /** @var int */ - private $id; + private int $id; public function __construct(int $id) { diff --git a/test/View/Helper/Captcha/DumbTest.php b/test/View/Helper/Captcha/DumbTest.php index e5ec184f8..6415a4b4a 100644 --- a/test/View/Helper/Captcha/DumbTest.php +++ b/test/View/Helper/Captcha/DumbTest.php @@ -17,8 +17,7 @@ */ final class DumbTest extends AbstractCommonTestCase { - /** @var DumbCaptcha */ - protected $captcha; + protected DumbCaptcha $captcha; protected function setUp(): void { diff --git a/test/View/Helper/Captcha/FigletTest.php b/test/View/Helper/Captcha/FigletTest.php index b83409636..dc3faf6e5 100644 --- a/test/View/Helper/Captcha/FigletTest.php +++ b/test/View/Helper/Captcha/FigletTest.php @@ -15,8 +15,7 @@ */ final class FigletTest extends AbstractCommonTestCase { - /** @var FigletCaptcha */ - private $captcha; + private FigletCaptcha $captcha; protected function setUp(): void { diff --git a/test/View/Helper/Captcha/ImageTest.php b/test/View/Helper/Captcha/ImageTest.php index c789c6b8f..b6a4667a9 100644 --- a/test/View/Helper/Captcha/ImageTest.php +++ b/test/View/Helper/Captcha/ImageTest.php @@ -24,12 +24,9 @@ */ final class ImageTest extends AbstractCommonTestCase { - /** @var string */ - protected $tmpDir; - /** @var string */ - protected $testDir; - /** @var ImageCaptcha */ - protected $captcha; + protected ?string $tmpDir = null; + protected string $testDir; + protected ImageCaptcha $captcha; protected function setUp(): void { diff --git a/test/View/Helper/Captcha/ReCaptchaTest.php b/test/View/Helper/Captcha/ReCaptchaTest.php index 3f97ea869..09ffc2312 100644 --- a/test/View/Helper/Captcha/ReCaptchaTest.php +++ b/test/View/Helper/Captcha/ReCaptchaTest.php @@ -18,8 +18,7 @@ */ final class ReCaptchaTest extends AbstractCommonTestCase { - /** @var ReCaptcha */ - private $captcha; + private ReCaptcha $captcha; protected function setUp(): void { diff --git a/test/View/Helper/Factory/FormElementErrorsFactoryTest.php b/test/View/Helper/Factory/FormElementErrorsFactoryTest.php index 9119350a2..68bab0213 100644 --- a/test/View/Helper/Factory/FormElementErrorsFactoryTest.php +++ b/test/View/Helper/Factory/FormElementErrorsFactoryTest.php @@ -57,9 +57,7 @@ public function testFactoryShouldCreateHelperAndSetOptions( $methodName = 'get' . implode( array_map( - static function ($value) { - return ucfirst($value); - }, + static fn($value) => ucfirst($value), explode('_', $option) ) ); diff --git a/test/View/Helper/FormButtonTest.php b/test/View/Helper/FormButtonTest.php index b96ffae63..0c179ded1 100644 --- a/test/View/Helper/FormButtonTest.php +++ b/test/View/Helper/FormButtonTest.php @@ -69,7 +69,7 @@ public function testOpenTagWithWrongElementRaisesException(): void { $element = new ArrayObject(); $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('ArrayObject'); + $this->expectExceptionMessage(ArrayObject::class); $this->helper->openTag($element); } diff --git a/test/View/Helper/FormCaptchaTest.php b/test/View/Helper/FormCaptchaTest.php index 17102e775..a1b2481ed 100644 --- a/test/View/Helper/FormCaptchaTest.php +++ b/test/View/Helper/FormCaptchaTest.php @@ -25,10 +25,8 @@ */ final class FormCaptchaTest extends AbstractCommonTestCase { - /** @var null|string */ - protected $testDir; - /** @var null|string */ - protected $tmpDir; + protected ?string $testDir = null; + protected ?string $tmpDir = null; protected function setUp(): void { diff --git a/test/View/Helper/FormCollectionTest.php b/test/View/Helper/FormCollectionTest.php index fac7888ec..ab0fcd6e1 100644 --- a/test/View/Helper/FormCollectionTest.php +++ b/test/View/Helper/FormCollectionTest.php @@ -12,6 +12,7 @@ use LaminasTest\Form\TestAsset\CustomViewHelper; use LaminasTest\Form\TestAsset\FormCollection; use ReflectionMethod; +use RuntimeException; /** * @property FormCollectionHelper $helper @@ -412,7 +413,7 @@ public function testForElementHelperNotInstanceOfHelperInterface(): void $method = new ReflectionMethod(FormCollectionHelper::class, 'getElementHelper'); $method->setAccessible(true); - $this->expectException('RuntimeException'); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage( 'Invalid element helper set in FormCollection.' . ' The helper must be an instance of Laminas\View\Helper\HelperInterface.' diff --git a/test/View/Helper/FormElementErrorsTest.php b/test/View/Helper/FormElementErrorsTest.php index cbed22097..8ee1c0fcf 100644 --- a/test/View/Helper/FormElementErrorsTest.php +++ b/test/View/Helper/FormElementErrorsTest.php @@ -19,8 +19,7 @@ final class FormElementErrorsTest extends AbstractCommonTestCase { use ProphecyTrait; - /** @var null|TranslatorInterface */ - protected $defaultTranslator; + protected ?TranslatorInterface $defaultTranslator; protected function setUp(): void { diff --git a/test/View/Helper/FormLabelTest.php b/test/View/Helper/FormLabelTest.php index 97bd40e99..4d9351e46 100644 --- a/test/View/Helper/FormLabelTest.php +++ b/test/View/Helper/FormLabelTest.php @@ -34,7 +34,7 @@ public function testOpenTagWithWrongElementRaisesException(): void { $element = new ArrayObject(); $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('ArrayObject'); + $this->expectExceptionMessage(ArrayObject::class); $this->helper->openTag($element); }