Skip to content

Commit

Permalink
Apply PHP 7.4 syntax and typed property
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik committed Jul 27, 2022
1 parent c94df30 commit c1648e5
Show file tree
Hide file tree
Showing 51 changed files with 91 additions and 146 deletions.
8 changes: 2 additions & 6 deletions src/Annotation/AbstractBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/AllowEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#[Attribute]
final class AllowEmpty
{
/** @var bool */
protected $allowEmpty;
protected bool $allowEmpty;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#[Attribute]
final class Attributes
{
/** @var array */
protected $attributes;
protected array $attributes;

/**
* Receive and process the contents of an annotation
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/BuilderAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
final class BuilderAbstractFactory implements AbstractFactoryInterface
{
/** @var string[] */
protected $aliases = [
protected array $aliases = [
'FormAnnotationBuilder' => AnnotationBuilder::class,
'FormAttributeBuilder' => AttributeBuilder::class,
];
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/ContinueIfEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#[Attribute]
final class ContinueIfEmpty
{
/** @var bool */
protected $continueIfEmpty;
protected bool $continueIfEmpty;

/**
* Receive and process the contents of an annotation
Expand Down
4 changes: 2 additions & 2 deletions src/Annotation/ElementAnnotationsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/ErrorMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#[Attribute]
final class ErrorMessage
{
/** @var string */
protected $message;
protected string $message;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#[Attribute]
final class Flags
{
/** @var array */
protected $flags;
protected array $flags;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#[Attribute]
final class Input
{
/** @var string */
protected $input;
protected string $input;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#[Attribute]
final class Instance
{
/** @var string */
protected $instance;
protected string $instance;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#[Attribute]
final class Name
{
/** @var string */
protected $name;
protected string $name;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#[Attribute]
final class Options
{
/** @var array */
protected $options;
protected array $options;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#[Attribute]
final class Required
{
/** @var bool */
protected $required;
protected bool $required;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#[Attribute]
final class Type
{
/** @var string */
protected $type;
protected string $type;

/**
* Receive and process the contents of an annotation
Expand Down
3 changes: 1 addition & 2 deletions src/Annotation/ValidationGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#[Attribute]
final class ValidationGroup
{
/** @var array */
protected $validationGroup;
protected array $validationGroup;

/**
* Receive and process the contents of an annotation
Expand Down
4 changes: 2 additions & 2 deletions src/Element/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/FormAbstractServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/InputFilterProviderFieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 1 addition & 2 deletions src/View/Helper/FormCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ class FormCollection extends AbstractHelper
*/
protected $fieldsetHelper;

/** @var array */
private $doctypesAllowedToHaveNameAttribute = [
private array $doctypesAllowedToHaveNameAttribute = [
Doctype::HTML5 => true,
Doctype::XHTML5 => true,
];
Expand Down
3 changes: 2 additions & 1 deletion test/Annotation/AbstractBuilderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace LaminasTest\Form\Annotation;

use ArrayObject;
use Generator;
use Laminas\Form\Annotation;
use Laminas\Form\Element;
Expand Down Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions test/Element/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace LaminasTest\Form\Element;

use ArrayAccess;
use ArrayObject;
use Laminas\Form\Element;
use Laminas\Form\Element\Collection;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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']);
}
Expand Down
4 changes: 1 addition & 3 deletions test/Element/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ final class DateTest extends TestCase
{
/**
* Stores the original set timezone
*
* @var string
*/
private $originaltimezone;
private string $originaltimezone;

/**
* {@inheritDoc}
Expand Down
4 changes: 1 addition & 3 deletions test/Element/TelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
9 changes: 4 additions & 5 deletions test/FieldsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit c1648e5

Please sign in to comment.