From 5a03e5c07cab618d51b9adf80322115f04f24979 Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 19:37:26 +0100 Subject: [PATCH 01/20] Initial WIP improving type inference Signed-off-by: George Steel --- composer.lock | 26 +- psalm-baseline.xml | 386 +------------------- src/ArrayInput.php | 10 +- src/BaseInputFilter.php | 81 ++-- src/CollectionInputFilter.php | 68 +++- src/Factory.php | 58 ++- src/FileInput.php | 10 +- src/Input.php | 40 +- src/InputFilter.php | 13 +- src/InputFilterAbstractServiceFactory.php | 18 +- src/InputFilterInterface.php | 48 ++- src/InputFilterProviderInterface.php | 2 +- src/InputInterface.php | 20 +- src/InputProviderInterface.php | 7 +- src/OptionalInputFilter.php | 18 +- src/UnfilteredDataInterface.php | 6 +- test/FactoryTest.php | 144 ++++---- test/FileInput/TestAsset/FileUploadMock.php | 2 +- test/InputTest.php | 2 +- 19 files changed, 379 insertions(+), 580 deletions(-) diff --git a/composer.lock b/composer.lock index 767fe062..c8fc8cc8 100644 --- a/composer.lock +++ b/composer.lock @@ -209,16 +209,16 @@ }, { "name": "laminas/laminas-stdlib", - "version": "3.6.1", + "version": "3.10.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-stdlib.git", - "reference": "db581851a092246ad99e12d4fddf105184924c71" + "reference": "449c0405e182bfe77702604a474668fbb63e9907" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/db581851a092246ad99e12d4fddf105184924c71", - "reference": "db581851a092246ad99e12d4fddf105184924c71", + "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/449c0405e182bfe77702604a474668fbb63e9907", + "reference": "449c0405e182bfe77702604a474668fbb63e9907", "shasum": "" }, "require": { @@ -229,8 +229,8 @@ }, "require-dev": { "laminas/laminas-coding-standard": "~2.3.0", - "phpbench/phpbench": "^0.17.1", - "phpunit/phpunit": "~9.3.7", + "phpbench/phpbench": "^1.0", + "phpunit/phpunit": "^9.3.7", "psalm/plugin-phpunit": "^0.16.0", "vimeo/psalm": "^4.7" }, @@ -264,25 +264,25 @@ "type": "community_bridge" } ], - "time": "2021-11-10T11:33:52+00:00" + "time": "2022-06-09T08:43:49+00:00" }, { "name": "laminas/laminas-validator", - "version": "2.15.1", + "version": "2.18.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-validator.git", - "reference": "fbd87f30c0a27aaeeee8adb2f934c14fb6046c80" + "reference": "dd9d10602048c561730d8bdb0ae589cd8ba11a82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/fbd87f30c0a27aaeeee8adb2f934c14fb6046c80", - "reference": "fbd87f30c0a27aaeeee8adb2f934c14fb6046c80", + "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/dd9d10602048c561730d8bdb0ae589cd8ba11a82", + "reference": "dd9d10602048c561730d8bdb0ae589cd8ba11a82", "shasum": "" }, "require": { "container-interop/container-interop": "^1.1", - "laminas/laminas-stdlib": "^3.6", + "laminas/laminas-stdlib": "^3.10", "php": "^7.3 || ~8.0.0 || ~8.1.0" }, "conflict": { @@ -354,7 +354,7 @@ "type": "community_bridge" } ], - "time": "2021-12-02T14:23:06+00:00" + "time": "2022-06-09T11:13:14+00:00" }, { "name": "psr/container", diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a84f51f2..76088543 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -36,165 +36,53 @@ - - is_array($data) - - - is_array($this->invalidInputs) ? $this->invalidInputs : [] - is_array($this->validInputs) ? $this->validInputs : [] - - - InputInterface[] - InputInterface[] - - - array - + + $input - - $inputs - $inputs - $key - $name - - + $inputContext - $inputs[] $unknownInputs[$key] - $value - $value - $values[$name] - $values[$name] - - $inputs - - - $input - $input $this->data - - $this->inputs - isValid isValid - - $this->notEmptyValidator === null - gettype($inputFilter) - is_object($data) - null === $this->inputFilter - + $data - - $data - $this->invalidInputs - $this->validInputs - - - $inputFilter - $notEmptyValidator - - - $data - $data - $data - $message - - - $templates[NotEmpty::IS_EMPTY] - - - $data - $data - $item - $message - $templates - $this->validationGroup - - - array<string, string> - - - $this->data - $this->data - - - gettype($data) - is_object($inputFilter) - + - - setAllowEmpty - setContinueIfEmpty - - + ! is_array($inputFilterSpecification) && ! $inputFilterSpecification instanceof Traversable ! is_array($inputSpecification) && ! $inputSpecification instanceof Traversable - is_array($validator) - - $inputFilter - - - InputFilterInterface - - + $breakChainOnFailure - $class - $class - $class - $class - $class $inputFilterSpecification['count'] $inputFilterSpecification['input_filter'] $inputFilterSpecification['required'] $inputFilterSpecification['required_message'] - $inputSpecification['continue_if_empty'] $key - $name - $name $options $priority $priority - $value - $value - $value - $value - $value - $value $value['type'] - - $key - $value - - - $validator['break_chain_on_failure'] - $validator['name'] - $validator['options'] - $validator['priority'] - - + $breakChainOnFailure - $class - $filter $key - $name - $name $options $options $priority @@ -204,26 +92,6 @@ new $class() - - null - null - - - add - add - - - $input->getFilterChain() - $input->getValidatorChain() - $this->defaultFilterChain - $this->defaultFilterChain - $this->defaultFilterChain - $this->defaultFilterChain - $this->defaultValidatorChain - $this->defaultValidatorChain - $this->defaultValidatorChain - $this->defaultValidatorChain - @@ -242,30 +110,18 @@ $this->prepareRequiredValidationFailureMessage() - - parent::resetValue() - $rawValue - - Input - $value - - self - null $implementation - - array|UploadedFile - @@ -325,7 +181,7 @@ setAllowEmpty setContinueIfEmpty - + $this->allowEmpty $this->allowEmpty $this->continueIfEmpty @@ -340,72 +196,22 @@ null|string - - FilterChain - ValidatorChain - $this->prepareRequiredValidationFailureMessage() clearFallbackValue - - $templates[NotEmpty::IS_EMPTY] - $validator['instance'] - $validator['instance'] - $validator['instance'] - - - $message - $message - $notEmpty - $templates - $translator - $validator - $validator + $value - - getOption - getTranslator - getTranslatorTextDomain - translate - - - $validator->getMessages() - string[] - string[] - - - $this->filterChain - $this->validatorChain - - - getOption - getTranslator - getTranslatorTextDomain - - + (bool) $allowEmpty (bool) $breakOnFailure (bool) $continueIfEmpty - (bool) $required (string) $errorMessage - (string) $name - - - parent::add($input, $name) - - - InputFilter - - - $input - - InputFilterAbstractServiceFactory @@ -428,10 +234,6 @@ $rName $services - - setPluginManager - setPluginManager - @@ -458,15 +260,7 @@ - - array|null - - - $data ?: [] - - - $data ?: [] - + @@ -551,8 +345,7 @@ - - $data + $input $input new stdClass() @@ -736,34 +529,10 @@ testSettingDataWithNonArrayNonTraversableRaisesException testUsesMessageFromComposedNotEmptyValidatorWhenRequiredButCollectionIsEmpty - + $data - $messages[0] - $messages[0] - $messages[0]['phone'] - $messages[0]['phone'] - $messages[0]['phone'] - $messages[0]['phone'] - $messages[0]['phone'] - $messages[1] - $messages[1] - $messages[1]['phone'] - $messages[1]['phone'] - $messages[1]['phone'] - $messages[1]['phone'] - $messages[1]['phone'] - - $messages[0]['phone'] - $messages[0]['phone'] - $messages[0]['phone'] - $messages[0]['phone'] - $messages[0]['phone'] - $messages[1]['phone'] - $messages[1]['phone'] - $messages[1]['phone'] - $messages[1]['phone'] - $messages[1]['phone'] + $set[3] @@ -827,72 +596,11 @@ 'invalid_value' 'invalid_value' - - testCanCreateInputFilterFromProvider - testCanCreateInputFilterWithNullInputs - testCanCreateInputFromProvider - testCanSetInputErrorMessage - testClearDefaultFilterChain - testClearDefaultValidatorChain - testConflictNameWithInputFilterType - testCreateInputFilterConfiguredNameWhenSpecIsIntegerIndexed - testCreateInputFilterUsesAssociatedNameMappingOverConfiguredName - testCreateInputFilterUsesConfiguredNameForNestedInputFilters - testCreateInputFilterWithInvalidDataTypeThrowsInvalidArgumentException - testCreateInputWithFiltersAsAnCollectionOfInvalidTypesThrowException - testCreateInputWithFiltersAsAnInvalidTypeThrowException - testCreateInputWithFiltersAsAnSpecificationWithMissingNameThrowException - testCreateInputWithInvalidDataTypeThrowsInvalidArgumentException - testCreateInputWithSpecificInputTypeSettingsThrowException - testCreateInputWithTypeAsAnInvalidClassInstanceThrowException - testCreateInputWithTypeAsAnInvalidPluginInstanceThrowException - testCreateInputWithTypeAsAnUnknownPluginAndNotExistsAsClassNameThrowException - testCreateInputWithValidatorsAsAnCollectionOfInvalidTypesThrowException - testCreateInputWithValidatorsAsAnInvalidTypeThrowException - testCreateInputWithValidatorsAsAnSpecificationWithMissingNameThrowException - testCustomFactoryInCollection - testFactoryAcceptsCollectionInputFilter - testFactoryAcceptsInputFilterInterface - testFactoryAcceptsInputInterface - testFactoryAllowsInjectingFilterChain - testFactoryAllowsInjectingValidatorChain - testFactoryAllowsPassingFilterChainsInInputSpec - testFactoryAllowsPassingValidatorChainsInInputSpec - testFactoryCanCreateCollectionInputFilterWithRequiredMessage - testFactoryComposesFilterChainByDefault - testFactoryComposesValidatorChainByDefault - testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjectsWhenCreatingNewInputFilterObjects - testFactoryUsesComposedFilterChainWhenCreatingNewInputObjects - testFactoryUsesComposedValidatorChainWhenCreatingNewInputObjects - testFactoryValidatorsPriority - testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfiguration - testFactoryWillCreateInputFilterMatchingInputNameWhenNotSpecified - testFactoryWillCreateInputWithContinueIfEmptyFlag - testFactoryWillCreateInputWithErrorMessage - testFactoryWillCreateInputWithSuggestedAllowEmptyFlagAndImpliesRequiredFlag - testFactoryWillCreateInputWithSuggestedFilters - testFactoryWillCreateInputWithSuggestedName - testFactoryWillCreateInputWithSuggestedRequiredFlagAndAlternativeAllowEmptyFlag - testFactoryWillCreateInputWithSuggestedValidators - testFactoryWillNotGetPrioritySetting - testGetInputFilterManagerSettedByItsSetter - testGetInputFilterManagerWhenYouConstructFactoryWithIt - testInputFromPluginManagerMayBeFurtherConfiguredWithSpec - testSetInputFilterManagerOnConstruct - testSetInputFilterManagerWithoutServiceManager - testSetsBreakChainOnFailure - testSuggestedTypeMayBePluginNameInInputFilterPluginManager - testWhenCreateInputPullsInputFromThePluginManagerItMustNotOverwriteFilterAndValidatorChains - - - $validator['instance'] - - + $defaultFilterChain $defaultValidatorChain - $validator - + count count getFilters @@ -905,17 +613,8 @@ method will will - willReturn - willReturn - willReturn - with - with - with - - $pluginManager - $pluginManager - $pluginManager + $provider $provider @@ -923,7 +622,7 @@ getPluginManager getPluginManager - + breakOnFailure breakOnFailure expects @@ -991,10 +690,6 @@ testValidationsRunWithoutFileArrayDueToAjaxPost testValidationsRunWithoutFileArrayIsSend - - $validators[0]['instance'] - $validators[0]['instance'] - array @@ -1017,14 +712,6 @@ UploadedFileInterface - - $badValue->reveal() - $upload->reveal() - $upload->reveal() - $uploadedFile->reveal() - $uploadedFile->reveal() - $value->reveal() - testAutoPrependUploadValidatorIsOnByDefault @@ -1050,10 +737,6 @@ [$upload, 'reveal'] - - $validators[0]['instance'] - $validators[0]['instance'] - $input @@ -1200,33 +883,6 @@ - - allowEmpty - allowEmpty - continueIfEmpty - continueIfEmpty - continueIfEmpty - continueIfEmpty - continueIfEmpty - setAllowEmpty - setAllowEmpty - setAllowEmpty - setAllowEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setContinueIfEmpty - setMethods - setMethods - $dataSets @@ -1289,9 +945,7 @@ testValidationOperatesOnFilteredValue testValueMayBeInjected - - $validators[0]['instance'] - $validators[1]['instance'] + $value['filtered'] $value['raw'] diff --git a/src/ArrayInput.php b/src/ArrayInput.php index 43b3d95c..4071c3ec 100644 --- a/src/ArrayInput.php +++ b/src/ArrayInput.php @@ -8,13 +8,13 @@ class ArrayInput extends Input { - /** @var array */ + /** @var array */ protected $value = []; /** - * @param array $value + * @inheritDoc + * @param array $value * @throws Exception\InvalidArgumentException - * @return Input */ public function setValue($value) { @@ -24,7 +24,9 @@ public function setValue($value) gettype($value) )); } - return parent::setValue($value); + parent::setValue($value); + + return $this; } /** diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index 7f489f23..10e9b3d1 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -20,8 +20,12 @@ use function is_array; use function is_int; use function is_object; +use function is_string; use function sprintf; +/** + * @psalm-import-type InputData from InputFilterInterface + */ class BaseInputFilter implements InputFilterInterface, UnknownInputsCapableInterface, @@ -29,22 +33,22 @@ class BaseInputFilter implements ReplaceableInputInterface, UnfilteredDataInterface { - /** @var null|array */ + /** @var InputData|null */ protected $data; - /** @var array|object */ + /** @var InputData */ protected $unfilteredData = []; - /** @var InputInterface[]|InputFilterInterface[] */ + /** @var array */ protected $inputs = []; - /** @var InputInterface[]|InputFilterInterface[]|null */ + /** @var array|null */ protected $invalidInputs; - /** @var null|string[]|null Input names */ + /** @var null|list Input names */ protected $validationGroup; - /** @var InputInterface[]|InputFilterInterface[]|null */ + /** @var array|null */ protected $validInputs; /** @@ -76,7 +80,8 @@ public function count() * @param InputInterface|InputFilterInterface $input * @param null|string $name Name used to retrieve this input * @throws Exception\InvalidArgumentException - * @return InputFilterInterface + * @return $this + * @psalm-suppress MoreSpecificImplementedParamType */ public function add($input, $name = null) { @@ -104,6 +109,8 @@ public function add($input, $name = null) return $this; } + /** @psalm-var string $name */ + $this->inputs[$name] = $input; return $this; } @@ -177,14 +184,16 @@ public function remove($name) /** * Set data to use when validating and filtering * - * @param null|array|Traversable $data null is cast to an empty array. + * @param InputData|Traversable|null $data null is cast to an empty array. * @throws Exception\InvalidArgumentException * @return InputFilterInterface + * @psalm-assert InputData $this->data */ public function setData($data) { // A null value indicates an empty set if (null === $data) { + /** @psalm-var InputData $data */ $data = []; } @@ -192,6 +201,7 @@ public function setData($data) $data = ArrayUtils::iteratorToArray($data); } + /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ if (! is_array($data)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects an array or Traversable argument; received %s', @@ -231,8 +241,8 @@ public function isValid($context = null) /** * Validate a set of inputs against the current data * - * @param string[] $inputs Array of input names. - * @param array $data + * @param list $inputs Array of input names. + * @param array $data * @param mixed|null $context * @return bool */ @@ -299,7 +309,7 @@ protected function validateInputs(array $inputs, array $data = [], $context = nu * Implementations should allow passing a single array value, or multiple arguments, * each specifying a single input. * - * @param mixed $name + * @param string|list|array> $name * @throws Exception\InvalidArgumentException * @return InputFilterInterface */ @@ -318,22 +328,25 @@ public function setValidationGroup($name) if (is_array($name)) { $inputs = []; foreach ($name as $key => $value) { - if (! $this->has($key)) { + if (! $this->has((string) $key)) { $inputs[] = $value; continue; } $inputs[] = $key; - if ($this->inputs[$key] instanceof InputFilterInterface) { + $input = $this->inputs[(string) $key]; + if ($input instanceof InputFilterInterface) { // Recursively populate validation groups for sub input filters - $this->inputs[$key]->setValidationGroup($value); + $input->setValidationGroup($value); } } } else { $inputs = func_get_args(); } + /** @psalm-var list $inputs */ + if (! empty($inputs)) { $this->validateValidationGroup($inputs); $this->validationGroup = $inputs; @@ -348,7 +361,7 @@ public function setValidationGroup($name) * Implementations should return an associative array of name/input pairs * that failed validation. * - * @return InputInterface[] + * @return array */ public function getInvalidInput() { @@ -361,7 +374,7 @@ public function getInvalidInput() * Implementations should return an associative array of name/input pairs * that passed validation. * - * @return InputInterface[] + * @return array */ public function getValidInput() { @@ -399,7 +412,7 @@ public function getValue($name) * List should be an associative array, with the values filtered. If * validation failed, this should raise an exception. * - * @return array + * @return array */ public function getValues() { @@ -408,11 +421,13 @@ public function getValues() foreach ($inputs as $name) { $input = $this->inputs[$name]; - if ($input instanceof InputFilterInterface) { - $values[$name] = $input->getValues(); - continue; - } - $values[$name] = $input->getValue(); + /** @psalm-var mixed $value */ + $value = $input instanceof InputFilterInterface + ? $input->getValues() + : $input->getValue(); + + /** @psalm-suppress MixedAssignment */ + $values[$name] = $value; } return $values; } @@ -446,7 +461,7 @@ public function getRawValue($name) * List should be an associative array of named input/value pairs, * with the values unfiltered. * - * @return array + * @return InputData|array */ public function getRawValues() { @@ -457,6 +472,7 @@ public function getRawValues() continue; } + /** @psalm-suppress MixedAssignment */ $values[$name] = $input->getRawValue(); } return $values; @@ -468,7 +484,7 @@ public function getRawValues() * Should return an associative array of named input/message list pairs. * Pairs should only be returned for inputs that failed validation. * - * @return array + * @return array> */ public function getMessages() { @@ -483,17 +499,18 @@ public function getMessages() /** * Ensure all names of a validation group exist as input in the filter * - * @param string[] $inputs Input names + * @param array $inputs Input names * @return void * @throws Exception\InvalidArgumentException + * @psalm-assert list $inputs */ protected function validateValidationGroup(array $inputs) { foreach ($inputs as $name) { - if (! array_key_exists($name, $this->inputs)) { + if (! is_string($name) || ! array_key_exists($name, $this->inputs)) { throw new Exception\InvalidArgumentException(sprintf( 'setValidationGroup() expects a list of valid input names; "%s" was not found', - $name + (string) $name )); } } @@ -530,6 +547,7 @@ protected function populate() continue; } + /** @psalm-var array|mixed $value */ $value = $this->data[$name]; if ($input instanceof InputFilterInterface) { @@ -538,6 +556,7 @@ protected function populate() $value = []; } + /** @psalm-var InputData $value */ $input->setData($value); continue; } @@ -590,7 +609,7 @@ public function getUnknown() /** * Get an array of all inputs * - * @return InputInterface[]|InputFilterInterface[] + * @return array */ public function getInputs() { @@ -600,7 +619,7 @@ public function getInputs() /** * Merges the inputs from an InputFilter into the current one * - * @return self + * @return $this */ public function merge(BaseInputFilter $inputFilter) { @@ -612,7 +631,7 @@ public function merge(BaseInputFilter $inputFilter) } /** - * @return array|object + * @return InputData */ public function getUnfilteredData() { @@ -620,7 +639,7 @@ public function getUnfilteredData() } /** - * @param array|object $data + * @param InputData $data * @return $this */ public function setUnfilteredData($data) diff --git a/src/CollectionInputFilter.php b/src/CollectionInputFilter.php index 51b85d12..0cd42cb8 100644 --- a/src/CollectionInputFilter.php +++ b/src/CollectionInputFilter.php @@ -12,35 +12,63 @@ use function is_object; use function sprintf; +/** + * @psalm-import-type InputData from InputFilterInterface + */ class CollectionInputFilter extends InputFilter { + /** + * @var array|null + * @psalm-suppress NonInvariantDocblockPropertyType + */ + protected $data; + /** @var bool */ protected $isRequired = false; /** @var null|int */ protected $count; - /** @var array[] */ + /** @var array> */ protected $collectionValues = []; - /** @var array[] */ + /** @var array> */ protected $collectionRawValues = []; - /** @var array */ + /** @var array>> */ protected $collectionMessages = []; - /** @var BaseInputFilter */ + /** @var BaseInputFilter|null */ protected $inputFilter; - /** @var NotEmpty */ + /** @var NotEmpty|null */ protected $notEmptyValidator; + /** + * @var array>|null + * @psalm-suppress NonInvariantDocblockPropertyType + */ + protected $validInputs; + + /** + * @var array>|null + * @psalm-suppress NonInvariantDocblockPropertyType + */ + protected $invalidInputs; + + /** + * @var array>|null + * @psalm-suppress NonInvariantDocblockPropertyType + */ + protected $validationGroup; + /** * Set the input filter to use when looping the data * * @param BaseInputFilter|array|Traversable $inputFilter * @throws Exception\RuntimeException * @return CollectionInputFilter + * @psalm-assert BaseInputFilter $this->inputFilter */ public function setInputFilter($inputFilter) { @@ -48,6 +76,7 @@ public function setInputFilter($inputFilter) $inputFilter = $this->getFactory()->createInputFilter($inputFilter); } + /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ if (! $inputFilter instanceof BaseInputFilter) { throw new Exception\RuntimeException(sprintf( '%s expects an instance of %s; received "%s"', @@ -120,17 +149,21 @@ public function setCount($count) public function getCount() { if (null === $this->count) { - return count($this->data); + return $this->data !== null ? count($this->data) : 0; } return $this->count; } /** - * {@inheritdoc} + * @param array|Traversable $data + * @psalm-suppress ImplementedParamTypeMismatch + * @psalm-assert array|Traversable $this->data + * @return $this */ public function setData($data) { + /** @psalm-suppress DocblockTypeContradiction, RedundantConditionGivenDocblockType */ if (! (is_array($data) || $data instanceof Traversable)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects an array or Traversable collection; invalid collection of type %s provided', @@ -142,6 +175,7 @@ public function setData($data) $this->setUnfilteredData($data); foreach ($data as $item) { + /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ if (is_array($item) || $item instanceof Traversable) { continue; } @@ -154,6 +188,7 @@ public function setData($data) )); } + /** @psalm-suppress InvalidPropertyAssignmentValue */ $this->data = $data; return $this; } @@ -204,7 +239,8 @@ public function isValid($context = null) $valid = false; } - if (count($this->data) < $this->getCount()) { + $dataCount = $this->data !== null ? count($this->data) : 0; + if ($dataCount < $this->getCount()) { $valid = false; } @@ -238,7 +274,8 @@ public function isValid($context = null) } /** - * {@inheritdoc} + * @param string|array> $name + * @return $this */ public function setValidationGroup($name) { @@ -251,7 +288,7 @@ public function setValidationGroup($name) } /** - * {@inheritdoc} + * @return array> */ public function getValues() { @@ -259,7 +296,7 @@ public function getValues() } /** - * {@inheritdoc} + * @return array> */ public function getRawValues() { @@ -287,7 +324,7 @@ public function clearRawValues() } /** - * {@inheritdoc} + * @return array>> */ public function getMessages() { @@ -326,9 +363,10 @@ public function getUnknown() protected function prepareRequiredValidationFailureMessage() { $notEmptyValidator = $this->getNotEmptyValidator(); - $templates = $notEmptyValidator->getOption('messageTemplates'); - $message = $templates[NotEmpty::IS_EMPTY]; - $translator = $notEmptyValidator->getTranslator(); + /** @var array $templates */ + $templates = $notEmptyValidator->getOption('messageTemplates'); + $message = $templates[NotEmpty::IS_EMPTY]; + $translator = $notEmptyValidator->getTranslator(); return [ NotEmpty::IS_EMPTY => $translator diff --git a/src/Factory.php b/src/Factory.php index 95c3c518..d0752acd 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -3,6 +3,7 @@ namespace Laminas\InputFilter; use Laminas\Filter\FilterChain; +use Laminas\Filter\FilterInterface; use Laminas\ServiceManager\ServiceManager; use Laminas\Stdlib\ArrayUtils; use Laminas\Validator\ValidatorChain; @@ -19,12 +20,17 @@ use function is_string; use function sprintf; +/** + * @psalm-import-type InputSpecification from InputFilterInterface + * @psalm-import-type FilterSpecification from InputFilterInterface + * @psalm-import-type ValidatorSpecification from InputFilterInterface + */ class Factory { - /** @var FilterChain */ + /** @var FilterChain|null */ protected $defaultFilterChain; - /** @var ValidatorChain */ + /** @var ValidatorChain|null */ protected $defaultValidatorChain; /** @var InputFilterPluginManager|null */ @@ -43,7 +49,8 @@ public function __construct(?InputFilterPluginManager $inputFilterManager = null /** * Set default filter chain to use * - * @return Factory + * @psalm-assert FilterChain $this->defaultFilterChain + * @return $this */ public function setDefaultFilterChain(FilterChain $filterChain) { @@ -64,6 +71,7 @@ public function getDefaultFilterChain() /** * Clear the default filter chain (i.e., don't inject one into new inputs) * + * @psalm-assert null $this->defaultFilterChain * @return void */ public function clearDefaultFilterChain() @@ -74,7 +82,8 @@ public function clearDefaultFilterChain() /** * Set default validator chain to use * - * @return Factory + * @psalm-assert ValidatorChain $this->defaultValidatorChain + * @return $this */ public function setDefaultValidatorChain(ValidatorChain $validatorChain) { @@ -95,6 +104,7 @@ public function getDefaultValidatorChain() /** * Clear the default validator chain (i.e., don't inject one into new inputs) * + * @psalm-assert null $this->defaultValidatorChain * @return void */ public function clearDefaultValidatorChain() @@ -128,7 +138,7 @@ public function getInputFilterManager() /** * Factory for input objects * - * @param array|Traversable|InputProviderInterface $inputSpecification + * @param InputSpecification|Traversable|InputProviderInterface $inputSpecification * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException * @return InputInterface|InputFilterInterface @@ -150,6 +160,8 @@ public function createInput($inputSpecification) $inputSpecification = ArrayUtils::iteratorToArray($inputSpecification); } + /** @psalm-var InputSpecification $inputSpecification */ + $class = Input::class; if (isset($inputSpecification['type'])) { @@ -185,6 +197,11 @@ public function createInput($inputSpecification) ? $this->injectFilterAndValidatorChainsWithPluginManagers($input) : $this->injectDefaultFilterAndValidatorChains($input); + /** + * Even though the specification is typed, psalm cannot tell the individual item types inside the switch + * + * @psalm-suppress MixedArgument, DeprecatedMethod + */ foreach ($inputSpecification as $key => $value) { switch ($key) { case 'name': @@ -238,6 +255,7 @@ public function createInput($inputSpecification) is_object($value) ? get_class($value) : gettype($value) )); } + /** @psalm-var iterable $value */ $this->populateFilters($input->getFilterChain(), $value); break; case 'validators': @@ -253,6 +271,7 @@ public function createInput($inputSpecification) is_object($value) ? get_class($value) : gettype($value) )); } + /** @psalm-var iterable $value */ $this->populateValidators($input->getValidatorChain(), $value); break; default: @@ -298,6 +317,7 @@ public function createInputFilter($inputFilterSpecification) unset($inputFilterSpecification['type']); } + /** @psalm-var InputFilterInterface $inputFilter */ $inputFilter = $this->getInputFilterManager()->get($type); if ($inputFilter instanceof CollectionInputFilter) { @@ -338,6 +358,7 @@ public function createInputFilter($inputFilterSpecification) && (isset($value['name']) && is_string($value['name'])) && $this->getInputFilterManager()->get($value['type']) instanceof InputFilter ) { + /** @psalm-var string $value['name'] */ // If $key is an integer, reset it to the specified name. if (is_int($key)) { $key = $value['name']; @@ -348,6 +369,11 @@ public function createInputFilter($inputFilterSpecification) unset($value['name']); } + /** + * @psalm-var InputSpecification $value + * @psalm-var string $key + */ + $inputFilter->add($this->createInput($value), $key); } @@ -355,18 +381,23 @@ public function createInputFilter($inputFilterSpecification) } /** - * @param array|Traversable $filters + * @param iterable $filters * @throws Exception\RuntimeException * @return void */ protected function populateFilters(FilterChain $chain, $filters) { foreach ($filters as $filter) { + /** @psalm-suppress RedundantConditionGivenDocblockType */ if (is_object($filter) || is_callable($filter)) { $chain->attach($filter); continue; } + /** + * @psalm-var FilterSpecification $filter + * @psalm-suppress RedundantConditionGivenDocblockType + */ if (is_array($filter)) { if (! isset($filter['name'])) { throw new Exception\RuntimeException( @@ -390,7 +421,7 @@ protected function populateFilters(FilterChain $chain, $filters) } /** - * @param string[]|ValidatorInterface[] $validators + * @param iterable $validators * @throws Exception\RuntimeException * @return void */ @@ -402,6 +433,7 @@ protected function populateValidators(ValidatorChain $chain, $validators) continue; } + /** @psalm-suppress RedundantConditionGivenDocblockType */ if (is_array($validator)) { if (! isset($validator['name'])) { throw new Exception\RuntimeException( @@ -457,14 +489,18 @@ protected function injectDefaultFilterAndValidatorChains(InputInterface $input) protected function injectFilterAndValidatorChainsWithPluginManagers(InputInterface $input) { if ($this->defaultFilterChain) { - $input->getFilterChain() - ? $input->getFilterChain()->setPluginManager($this->defaultFilterChain->getPluginManager()) + $filterChain = $input->getFilterChain(); + /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ + $filterChain instanceof FilterChain + ? $filterChain->setPluginManager($this->defaultFilterChain->getPluginManager()) : $input->setFilterChain(clone $this->defaultFilterChain); } if ($this->defaultValidatorChain) { - $input->getValidatorChain() - ? $input->getValidatorChain()->setPluginManager($this->defaultValidatorChain->getPluginManager()) + $validatorChain = $input->getValidatorChain(); + /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ + $validatorChain instanceof ValidatorChain + ? $validatorChain->setPluginManager($this->defaultValidatorChain->getPluginManager()) : $input->setValidatorChain(clone $this->defaultValidatorChain); } } diff --git a/src/FileInput.php b/src/FileInput.php index dacd8ef1..cf66205c 100644 --- a/src/FileInput.php +++ b/src/FileInput.php @@ -33,8 +33,8 @@ class FileInput extends Input private $implementation; /** - * @param array|UploadedFile $value - * @return Input + * @inheritDoc + * @param array|UploadedFileInterface $value */ public function setValue($value) { @@ -43,7 +43,7 @@ public function setValue($value) return $this; } - /** @return self */ + /** @return $this */ public function resetValue() { $this->implementation = null; @@ -52,7 +52,7 @@ public function resetValue() /** * @param bool $value Enable/Disable automatically prepending an Upload validator - * @return FileInput + * @return $this */ public function setAutoPrependUploadValidator($value) { @@ -138,7 +138,7 @@ public function isValid($context = null) } /** - * @return FileInput + * @return $this */ public function merge(InputInterface $input) { diff --git a/src/Input.php b/src/Input.php index baab64b5..4158d913 100644 --- a/src/Input.php +++ b/src/Input.php @@ -5,6 +5,7 @@ use Laminas\Filter\FilterChain; use Laminas\ServiceManager\AbstractPluginManager; use Laminas\Validator\NotEmpty; +use Laminas\Validator\Translator\TranslatorInterface; use Laminas\Validator\ValidatorChain; use function class_exists; @@ -63,7 +64,7 @@ class Input implements */ protected $hasValue = false; - /** @var mixed */ + /** @var mixed|null */ protected $fallbackValue; /** @var bool */ @@ -79,7 +80,7 @@ public function __construct($name = null) * @deprecated 2.4.8 Add Laminas\Validator\NotEmpty validator to the ValidatorChain and set this to `true`. * * @param bool $allowEmpty - * @return Input + * @return $this */ public function setAllowEmpty($allowEmpty) { @@ -89,7 +90,7 @@ public function setAllowEmpty($allowEmpty) /** * @param bool $breakOnFailure - * @return Input + * @return $this */ public function setBreakOnFailure($breakOnFailure) { @@ -101,7 +102,7 @@ public function setBreakOnFailure($breakOnFailure) * @deprecated 2.4.8 Add Laminas\Validator\NotEmpty validator to the ValidatorChain and set this to `true`. * * @param bool $continueIfEmpty - * @return Input + * @return $this */ public function setContinueIfEmpty($continueIfEmpty) { @@ -111,7 +112,7 @@ public function setContinueIfEmpty($continueIfEmpty) /** * @param string|null $errorMessage - * @return Input + * @return $this */ public function setErrorMessage($errorMessage) { @@ -120,7 +121,8 @@ public function setErrorMessage($errorMessage) } /** - * @return Input + * @return $this + * @psalm-assert FilterChain $this->filterChain */ public function setFilterChain(FilterChain $filterChain) { @@ -130,26 +132,29 @@ public function setFilterChain(FilterChain $filterChain) /** * @param string $name - * @return Input + * @return $this */ public function setName($name) { + /** @psalm-suppress RedundantCastGivenDocblockType */ $this->name = (string) $name; return $this; } /** * @param bool $required - * @return Input + * @return $this */ public function setRequired($required) { + /** @psalm-suppress RedundantCastGivenDocblockType */ $this->required = (bool) $required; return $this; } /** - * @return Input + * @return $this + * @psalm-assert ValidatorChain $this->validatorChain */ public function setValidatorChain(ValidatorChain $validatorChain) { @@ -167,7 +172,7 @@ public function setValidatorChain(ValidatorChain $validatorChain) * @see Input::resetValue() For reset the input value to the default state. * * @param mixed $value - * @return Input + * @return $this */ public function setValue($value) { @@ -182,7 +187,7 @@ public function setValue($value) * @see Input::hasValue() For to know if input value was set. * @see Input::setValue() For set a new value. * - * @return Input + * @return $this */ public function resetValue() { @@ -193,7 +198,7 @@ public function resetValue() /** * @param mixed $value - * @return Input + * @return $this */ public function setFallbackValue($value) { @@ -209,6 +214,7 @@ public function setFallbackValue($value) */ public function allowEmpty() { + /** @psalm-suppress DeprecatedProperty */ return $this->allowEmpty; } @@ -227,6 +233,7 @@ public function breakOnFailure() */ public function continueIfEmpty() { + /** @psalm-suppress DeprecatedProperty */ return $this->continueIfEmpty; } @@ -333,7 +340,7 @@ public function clearFallbackValue() } /** - * @return Input + * @return $this */ public function merge(InputInterface $input) { @@ -417,7 +424,7 @@ public function isValid($context = null) } /** - * @return string[] + * @return array */ public function getMessages() { @@ -468,7 +475,7 @@ protected function injectNotEmptyValidator() /** * Create and return the validation failure message for required input. * - * @return string[] + * @return array */ protected function prepareRequiredValidationFailureMessage() { @@ -482,11 +489,12 @@ protected function prepareRequiredValidationFailureMessage() } } + /** @psalm-var array $templates */ $templates = $notEmpty->getOption('messageTemplates'); $message = $templates[NotEmpty::IS_EMPTY]; $translator = $notEmpty->getTranslator(); - if ($translator) { + if ($translator instanceof TranslatorInterface) { $message = $translator->translate($message, $notEmpty->getTranslatorTextDomain()); } diff --git a/src/InputFilter.php b/src/InputFilter.php index dcfffb79..c9d10860 100644 --- a/src/InputFilter.php +++ b/src/InputFilter.php @@ -6,6 +6,9 @@ use function is_array; +/** + * @psalm-import-type InputSpecification from InputFilterInterface + **/ class InputFilter extends BaseInputFilter { /** @var Factory|null */ @@ -41,9 +44,9 @@ public function getFactory() /** * Add an input to the input filter * - * @param array|Traversable|InputInterface|InputFilterInterface $input + * @param InputSpecification|Traversable|InputInterface|InputFilterInterface $input * @param null|string $name - * @return InputFilter + * @return $this */ public function add($input, $name = null) { @@ -54,6 +57,10 @@ public function add($input, $name = null) $factory = $this->getFactory(); $input = $factory->createInput($input); } - return parent::add($input, $name); + + /** @psalm-var InputInterface|InputFilterInterface $input */ + parent::add($input, $name); + + return $this; } } diff --git a/src/InputFilterAbstractServiceFactory.php b/src/InputFilterAbstractServiceFactory.php index ef1a0f1f..ba6408a6 100644 --- a/src/InputFilterAbstractServiceFactory.php +++ b/src/InputFilterAbstractServiceFactory.php @@ -3,11 +3,14 @@ namespace Laminas\InputFilter; use Interop\Container\ContainerInterface; +use Laminas\Filter\FilterChain; use Laminas\Filter\FilterPluginManager; use Laminas\ServiceManager\AbstractFactoryInterface; use Laminas\ServiceManager\ServiceLocatorInterface; +use Laminas\Validator\ValidatorChain; use Laminas\Validator\ValidatorPluginManager; +use function assert; use function is_array; class InputFilterAbstractServiceFactory implements AbstractFactoryInterface @@ -89,13 +92,14 @@ protected function getInputFilterFactory(ContainerInterface $container) return $this->factory; } - $this->factory = new Factory(); - $this->factory - ->getDefaultFilterChain() - ->setPluginManager($this->getFilterPluginManager($container)); - $this->factory - ->getDefaultValidatorChain() - ->setPluginManager($this->getValidatorPluginManager($container)); + $this->factory = new Factory(); + $filterChain = $this->factory->getDefaultFilterChain(); + $validatorChain = $this->factory->getDefaultValidatorChain(); + assert($filterChain instanceof FilterChain); + assert($validatorChain instanceof ValidatorChain); + + $filterChain->setPluginManager($this->getFilterPluginManager($container)); + $validatorChain->setPluginManager($this->getValidatorPluginManager($container)); $this->factory->setInputFilterManager($container->get(InputFilterPluginManager::class)); diff --git a/src/InputFilterInterface.php b/src/InputFilterInterface.php index 46b7d1f6..d75ba811 100644 --- a/src/InputFilterInterface.php +++ b/src/InputFilterInterface.php @@ -1,10 +1,40 @@ -, + * priority?: int, + * options?: array, + * }&array + * @psalm-type ValidatorSpecification = array{ + * name: string|class-string, + * priority?: int, + * break_chain_on_failure?: bool, + * options?: array, + * }&array + * @psalm-type InputSpecification = array{ + * type?: string|class-string, + * name?: string, + * required?: bool, + * allow_empty?: bool, + * continue_if_empty?: bool, + * error_message?: string|null, + * fallback_value?: mixed|null, + * break_on_failure?: bool, + * filters?: FilterChain|iterable, + * validators?: ValidatorChain|iterable, + * }&array + * @psalm-type InputData = array + */ interface InputFilterInterface extends Countable { public const VALIDATE_ALL = 'INPUT_FILTER_ALL'; @@ -12,7 +42,7 @@ interface InputFilterInterface extends Countable /** * Add an input to the input filter * - * @param InputInterface|InputFilterInterface|array|Traversable $input + * @param InputInterface|InputFilterInterface|InputSpecification|Traversable $input * Implementations MUST handle at least one of the specified types, and * raise an exception for any they cannot process. * @param null|string $name Name used to retrieve this input @@ -48,7 +78,7 @@ public function remove($name); /** * Set data to use when validating and filtering * - * @param array|Traversable $data + * @param InputData|Traversable|null $data * @return InputFilterInterface */ public function setData($data); @@ -71,7 +101,7 @@ public function isValid(); * Implementations should allow passing a single array value, or multiple arguments, * each specifying a single input. * - * @param mixed $name + * @param string|list $name * @return InputFilterInterface */ public function setValidationGroup($name); @@ -82,7 +112,7 @@ public function setValidationGroup($name); * Implementations should return an associative array of name/input pairs * that failed validation. * - * @return InputInterface[] + * @return array */ public function getInvalidInput(); @@ -92,7 +122,7 @@ public function getInvalidInput(); * Implementations should return an associative array of name/input pairs * that passed validation. * - * @return InputInterface[] + * @return array */ public function getValidInput(); @@ -110,7 +140,7 @@ public function getValue($name); * List should be an associative array, with the values filtered. If * validation failed, this should raise an exception. * - * @return array + * @return array */ public function getValues(); @@ -128,7 +158,7 @@ public function getRawValue($name); * List should be an associative array of named input/value pairs, * with the values unfiltered. * - * @return array + * @return InputData */ public function getRawValues(); @@ -138,7 +168,7 @@ public function getRawValues(); * Should return an associative array of named input/message list pairs. * Pairs should only be returned for inputs that failed validation. * - * @return string[] + * @return array> */ public function getMessages(); } diff --git a/src/InputFilterProviderInterface.php b/src/InputFilterProviderInterface.php index a3015395..b87ee52e 100644 --- a/src/InputFilterProviderInterface.php +++ b/src/InputFilterProviderInterface.php @@ -6,7 +6,7 @@ interface InputFilterProviderInterface { /** * Should return an array specification compatible with - * {@link Laminas\InputFilter\Factory::createInputFilter()}. + * {@link Factory::createInputFilter()}. * * @return array */ diff --git a/src/InputInterface.php b/src/InputInterface.php index f2faee28..cd95d411 100644 --- a/src/InputInterface.php +++ b/src/InputInterface.php @@ -11,52 +11,52 @@ interface InputInterface * @deprecated 2.4.8 Add Laminas\Validator\NotEmpty validator to the ValidatorChain and set this to `true`. * * @param bool $allowEmpty - * @return self + * @return $this */ public function setAllowEmpty($allowEmpty); /** * @param bool $breakOnFailure - * @return self + * @return $this */ public function setBreakOnFailure($breakOnFailure); /** * @param string|null $errorMessage - * @return self + * @return $this */ public function setErrorMessage($errorMessage); /** - * @return self + * @return $this */ public function setFilterChain(FilterChain $filterChain); /** * @param string $name - * @return self + * @return $this */ public function setName($name); /** * @param bool $required - * @return self + * @return $this */ public function setRequired($required); /** - * @return self + * @return $this */ public function setValidatorChain(ValidatorChain $validatorChain); /** * @param mixed $value - * @return self + * @return $this */ public function setValue($value); /** - * @return self + * @return $this */ public function merge(InputInterface $input); @@ -113,7 +113,7 @@ public function getValue(); public function isValid(); /** - * @return string[] + * @return array */ public function getMessages(); } diff --git a/src/InputProviderInterface.php b/src/InputProviderInterface.php index b8dea84b..3a855679 100644 --- a/src/InputProviderInterface.php +++ b/src/InputProviderInterface.php @@ -2,13 +2,16 @@ namespace Laminas\InputFilter; +/** + * @psalm-import-type InputSpecification from InputFilterInterface + */ interface InputProviderInterface { /** * Should return an array specification compatible with - * {@link Laminas\InputFilter\Factory::createInput()}. + * {@link Factory::createInput()}. * - * @return array + * @return InputSpecification */ public function getInputSpecification(); } diff --git a/src/OptionalInputFilter.php b/src/OptionalInputFilter.php index 49606d15..beb7590d 100644 --- a/src/OptionalInputFilter.php +++ b/src/OptionalInputFilter.php @@ -2,25 +2,31 @@ namespace Laminas\InputFilter; +use Traversable; + /** * InputFilter which only checks the containing Inputs when non-empty data is set, * else it reports valid + * This is analog to {@see Input} with the option ->setRequired(false) * - * This is analog to {@see Laminas\InputFilter\Input} with the option ->setRequired(false) + * @psalm-import-type InputData from InputFilterInterface */ class OptionalInputFilter extends InputFilter { /** * Set data to use when validating and filtering * - * @param iterable|mixed $data - * must be a non-empty iterable in order trigger actual validation, else it is always valid + * @param InputData|Traversable|null $data must be a non-empty iterable in order trigger + * actual validation, else it is always valid + * @return $this * @throws Exception\InvalidArgumentException - * @return InputFilterInterface + * @psalm-assert InputData $this->data */ public function setData($data) { - return parent::setData($data ?: []); + parent::setData($data ?: []); + + return $this; } /** @@ -43,7 +49,7 @@ public function isValid($context = null) * which would likely cause failures later on in your program * Fallbacks for the inputs are not respected by design * - * @return array|null + * @return array|null */ public function getValues() { diff --git a/src/UnfilteredDataInterface.php b/src/UnfilteredDataInterface.php index 78f56a00..aed96265 100644 --- a/src/UnfilteredDataInterface.php +++ b/src/UnfilteredDataInterface.php @@ -4,16 +4,18 @@ /** * Ensures Inputs store unfiltered data and are capable of returning it + * + * @psalm-import-type InputData from InputFilterInterface */ interface UnfilteredDataInterface { /** - * @return array|object + * @return InputData */ public function getUnfilteredData(); /** - * @param array|object $data + * @param InputData $data * @return $this */ public function setUnfilteredData($data); diff --git a/test/FactoryTest.php b/test/FactoryTest.php index f588b65a..d9d53fa4 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -34,7 +34,7 @@ class FactoryTest extends TestCase { use ProphecyTrait; - public function testCreateInputWithInvalidDataTypeThrowsInvalidArgumentException() + public function testCreateInputWithInvalidDataTypeThrowsInvalidArgumentException(): void { $factory = $this->createDefaultFactory(); @@ -44,10 +44,10 @@ public function testCreateInputWithInvalidDataTypeThrowsInvalidArgumentException $factory->createInput('invalid_value'); } - public function testCreateInputWithTypeAsAnUnknownPluginAndNotExistsAsClassNameThrowException() + public function testCreateInputWithTypeAsAnUnknownPluginAndNotExistsAsClassNameThrowException(): void { $type = 'foo'; - /** @var InputFilterPluginManager|MockObject $pluginManager */ + /** @var InputFilterPluginManager&MockObject $pluginManager */ $pluginManager = $this->getMockBuilder(InputFilterPluginManager::class) ->disableOriginalConstructor() ->getMock(); @@ -67,7 +67,7 @@ public function testCreateInputWithTypeAsAnUnknownPluginAndNotExistsAsClassNameT ]); } - public function testGetInputFilterManagerSettedByItsSetter() + public function testGetInputFilterManagerSettedByItsSetter(): void { $pluginManager = $this->getMockBuilder(InputFilterPluginManager::class) ->disableOriginalConstructor() @@ -77,7 +77,7 @@ public function testGetInputFilterManagerSettedByItsSetter() $this->assertSame($pluginManager, $factory->getInputFilterManager()); } - public function testGetInputFilterManagerWhenYouConstructFactoryWithIt() + public function testGetInputFilterManagerWhenYouConstructFactoryWithIt(): void { $pluginManager = $this->getMockBuilder(InputFilterPluginManager::class) ->disableOriginalConstructor() @@ -86,7 +86,7 @@ public function testGetInputFilterManagerWhenYouConstructFactoryWithIt() $this->assertSame($pluginManager, $factory->getInputFilterManager()); } - public function testCreateInputWithTypeAsAnInvalidPluginInstanceThrowException() + public function testCreateInputWithTypeAsAnInvalidPluginInstanceThrowException(): void { $type = 'fooPlugin'; $pluginManager = $this->createInputFilterPluginManagerMockForPlugin($type, 'invalid_value'); @@ -102,7 +102,7 @@ public function testCreateInputWithTypeAsAnInvalidPluginInstanceThrowException() ]); } - public function testCreateInputWithTypeAsAnInvalidClassInstanceThrowException() + public function testCreateInputWithTypeAsAnInvalidClassInstanceThrowException(): void { $factory = $this->createDefaultFactory(); $type = 'stdClass'; @@ -117,7 +117,7 @@ public function testCreateInputWithTypeAsAnInvalidClassInstanceThrowException() ]); } - public function testCreateInputWithFiltersAsAnInvalidTypeThrowException() + public function testCreateInputWithFiltersAsAnInvalidTypeThrowException(): void { $factory = $this->createDefaultFactory(); @@ -126,17 +126,19 @@ public function testCreateInputWithFiltersAsAnInvalidTypeThrowException() 'expects the value associated with "filters" to be an array/Traversable' . ' of filters or filter specifications, or a FilterChain; received "string"' ); + /** @psalm-suppress InvalidArgument */ $factory->createInput([ 'filters' => 'invalid_value', ]); } - public function testCreateInputWithFiltersAsAnSpecificationWithMissingNameThrowException() + public function testCreateInputWithFiltersAsAnSpecificationWithMissingNameThrowException(): void { $factory = $this->createDefaultFactory(); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Invalid filter specification provided; does not include "name" key'); + /** @psalm-suppress InvalidArgument */ $factory->createInput([ 'filters' => [ [ @@ -146,7 +148,7 @@ public function testCreateInputWithFiltersAsAnSpecificationWithMissingNameThrowE ]); } - public function testCreateInputWithFiltersAsAnCollectionOfInvalidTypesThrowException() + public function testCreateInputWithFiltersAsAnCollectionOfInvalidTypesThrowException(): void { $factory = $this->createDefaultFactory(); @@ -161,7 +163,7 @@ public function testCreateInputWithFiltersAsAnCollectionOfInvalidTypesThrowExcep ]); } - public function testCreateInputWithValidatorsAsAnInvalidTypeThrowException() + public function testCreateInputWithValidatorsAsAnInvalidTypeThrowException(): void { $factory = $this->createDefaultFactory(); @@ -170,17 +172,19 @@ public function testCreateInputWithValidatorsAsAnInvalidTypeThrowException() 'expects the value associated with "validators" to be an array/Traversable of validators or validator ' . 'specifications, or a ValidatorChain; received "string"' ); + /** @psalm-suppress InvalidArgument */ $factory->createInput([ 'validators' => 'invalid_value', ]); } - public function testCreateInputWithValidatorsAsAnSpecificationWithMissingNameThrowException() + public function testCreateInputWithValidatorsAsAnSpecificationWithMissingNameThrowException(): void { $factory = $this->createDefaultFactory(); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Invalid validator specification provided; does not include "name" key'); + /** @psalm-suppress InvalidArgument */ $factory->createInput([ 'validators' => [ [ @@ -190,7 +194,7 @@ public function testCreateInputWithValidatorsAsAnSpecificationWithMissingNameThr ]); } - /** @psalm-return array */ + /** @psalm-return array */ public function inputTypeSpecificationProvider(): array { return [ @@ -202,8 +206,9 @@ public function inputTypeSpecificationProvider(): array /** * @dataProvider inputTypeSpecificationProvider + * @psalm-param 'continue_if_empty'|'fallback_value' $specificationKey */ - public function testCreateInputWithSpecificInputTypeSettingsThrowException(string $specificationKey) + public function testCreateInputWithSpecificInputTypeSettingsThrowException(string $specificationKey): void { $factory = $this->createDefaultFactory(); $type = 'pluginInputInterface'; @@ -218,13 +223,14 @@ public function testCreateInputWithSpecificInputTypeSettingsThrowException(strin $this->expectExceptionMessage( sprintf('"%s" can only set to inputs of type "Laminas\InputFilter\Input"', $specificationKey) ); + /** @psalm-suppress ArgumentTypeCoercion */ $factory->createInput([ 'type' => $type, $specificationKey => true, ]); } - public function testCreateInputWithValidatorsAsAnCollectionOfInvalidTypesThrowException() + public function testCreateInputWithValidatorsAsAnCollectionOfInvalidTypesThrowException(): void { $factory = $this->createDefaultFactory(); @@ -232,6 +238,7 @@ public function testCreateInputWithValidatorsAsAnCollectionOfInvalidTypesThrowEx $this->expectExceptionMessage( 'Invalid validator specification provided; was neither a validator instance nor an array specification' ); + /** @psalm-suppress InvalidArgument */ $factory->createInput([ 'validators' => [ 'invalid value', @@ -239,7 +246,7 @@ public function testCreateInputWithValidatorsAsAnCollectionOfInvalidTypesThrowEx ]); } - public function testCreateInputFilterWithInvalidDataTypeThrowsInvalidArgumentException() + public function testCreateInputFilterWithInvalidDataTypeThrowsInvalidArgumentException(): void { $factory = $this->createDefaultFactory(); @@ -249,19 +256,19 @@ public function testCreateInputFilterWithInvalidDataTypeThrowsInvalidArgumentExc $factory->createInputFilter('invalid_value'); } - public function testFactoryComposesFilterChainByDefault() + public function testFactoryComposesFilterChainByDefault(): void { $factory = $this->createDefaultFactory(); $this->assertInstanceOf(Filter\FilterChain::class, $factory->getDefaultFilterChain()); } - public function testFactoryComposesValidatorChainByDefault() + public function testFactoryComposesValidatorChainByDefault(): void { $factory = $this->createDefaultFactory(); $this->assertInstanceOf(Validator\ValidatorChain::class, $factory->getDefaultValidatorChain()); } - public function testFactoryAllowsInjectingFilterChain() + public function testFactoryAllowsInjectingFilterChain(): void { $factory = $this->createDefaultFactory(); $filterChain = new Filter\FilterChain(); @@ -269,7 +276,7 @@ public function testFactoryAllowsInjectingFilterChain() $this->assertSame($filterChain, $factory->getDefaultFilterChain()); } - public function testFactoryAllowsInjectingValidatorChain() + public function testFactoryAllowsInjectingValidatorChain(): void { $factory = $this->createDefaultFactory(); $validatorChain = new Validator\ValidatorChain(); @@ -277,7 +284,7 @@ public function testFactoryAllowsInjectingValidatorChain() $this->assertSame($validatorChain, $factory->getDefaultValidatorChain()); } - public function testFactoryUsesComposedFilterChainWhenCreatingNewInputObjects() + public function testFactoryUsesComposedFilterChainWhenCreatingNewInputObjects(): void { $smMock = $this->createMock(ContainerInterface::class); @@ -295,7 +302,7 @@ public function testFactoryUsesComposedFilterChainWhenCreatingNewInputObjects() $this->assertSame($pluginManager, $inputFilterChain->getPluginManager()); } - public function testFactoryUsesComposedValidatorChainWhenCreatingNewInputObjects() + public function testFactoryUsesComposedValidatorChainWhenCreatingNewInputObjects(): void { $smMock = $this->createMock(ContainerInterface::class); $factory = $this->createDefaultFactory(); @@ -313,7 +320,7 @@ public function testFactoryUsesComposedValidatorChainWhenCreatingNewInputObjects } // @codingStandardsIgnoreStart - public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjectsWhenCreatingNewInputFilterObjects() + public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjectsWhenCreatingNewInputFilterObjects(): void { // @codingStandardsIgnoreEnd $smMock = $this->createMock(ContainerInterface::class); @@ -342,7 +349,7 @@ public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjec $this->assertSame($validatorPlugins, $inputValidatorChain->getPluginManager()); } - public function testFactoryWillCreateInputWithSuggestedFilters() + public function testFactoryWillCreateInputWithSuggestedFilters(): void { $factory = $this->createDefaultFactory(); $htmlEntities = new Filter\HtmlEntities(); @@ -384,7 +391,7 @@ public function testFactoryWillCreateInputWithSuggestedFilters() } } - public function testFactoryWillCreateInputWithSuggestedValidators() + public function testFactoryWillCreateInputWithSuggestedValidators(): void { $factory = $this->createDefaultFactory(); $digits = new Validator\Digits(); @@ -431,7 +438,7 @@ public function testFactoryWillCreateInputWithSuggestedValidators() $this->assertEquals(3, $index); } - public function testFactoryWillCreateInputWithSuggestedRequiredFlagAndAlternativeAllowEmptyFlag() + public function testFactoryWillCreateInputWithSuggestedRequiredFlagAndAlternativeAllowEmptyFlag(): void { $factory = $this->createDefaultFactory(); $input = $factory->createInput([ @@ -444,7 +451,7 @@ public function testFactoryWillCreateInputWithSuggestedRequiredFlagAndAlternativ $this->assertFalse($input->allowEmpty()); } - public function testFactoryWillCreateInputWithSuggestedAllowEmptyFlagAndImpliesRequiredFlag() + public function testFactoryWillCreateInputWithSuggestedAllowEmptyFlagAndImpliesRequiredFlag(): void { $factory = $this->createDefaultFactory(); $input = $factory->createInput([ @@ -456,7 +463,7 @@ public function testFactoryWillCreateInputWithSuggestedAllowEmptyFlagAndImpliesR $this->assertFalse($input->isRequired()); } - public function testFactoryWillCreateInputWithSuggestedName() + public function testFactoryWillCreateInputWithSuggestedName(): void { $factory = $this->createDefaultFactory(); $input = $factory->createInput([ @@ -466,7 +473,7 @@ public function testFactoryWillCreateInputWithSuggestedName() $this->assertEquals('foo', $input->getName()); } - public function testFactoryWillCreateInputWithContinueIfEmptyFlag() + public function testFactoryWillCreateInputWithContinueIfEmptyFlag(): void { $factory = $this->createDefaultFactory(); $input = $factory->createInput([ @@ -477,7 +484,7 @@ public function testFactoryWillCreateInputWithContinueIfEmptyFlag() $this->assertTrue($input->continueIfEmpty()); } - public function testFactoryAcceptsInputInterface() + public function testFactoryAcceptsInputInterface(): void { $factory = $this->createDefaultFactory(); $input = new Input(); @@ -491,7 +498,7 @@ public function testFactoryAcceptsInputInterface() $this->assertEquals($input, $inputFilter->get('foo')); } - public function testFactoryAcceptsInputFilterInterface() + public function testFactoryAcceptsInputFilterInterface(): void { $factory = $this->createDefaultFactory(); $input = new InputFilter(); @@ -505,7 +512,7 @@ public function testFactoryAcceptsInputFilterInterface() $this->assertEquals($input, $inputFilter->get('foo')); } - public function testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfiguration() + public function testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfiguration(): void { $factory = $this->createDefaultFactory(); $inputFilter = $factory->createInputFilter([ @@ -621,7 +628,7 @@ public function testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfi } } - public function testFactoryWillCreateInputFilterMatchingInputNameWhenNotSpecified() + public function testFactoryWillCreateInputFilterMatchingInputNameWhenNotSpecified(): void { $factory = $this->createDefaultFactory(); $inputFilter = $factory->createInputFilter([ @@ -632,7 +639,7 @@ public function testFactoryWillCreateInputFilterMatchingInputNameWhenNotSpecifie $this->assertInstanceOf(Input::class, $inputFilter->get('foo')); } - public function testFactoryAllowsPassingValidatorChainsInInputSpec() + public function testFactoryAllowsPassingValidatorChainsInInputSpec(): void { $factory = $this->createDefaultFactory(); $chain = new Validator\ValidatorChain(); @@ -645,7 +652,7 @@ public function testFactoryAllowsPassingValidatorChainsInInputSpec() $this->assertSame($chain, $test); } - public function testFactoryAllowsPassingFilterChainsInInputSpec() + public function testFactoryAllowsPassingFilterChainsInInputSpec(): void { $factory = $this->createDefaultFactory(); $chain = new Filter\FilterChain(); @@ -658,7 +665,7 @@ public function testFactoryAllowsPassingFilterChainsInInputSpec() $this->assertSame($chain, $test); } - public function testFactoryAcceptsCollectionInputFilter() + public function testFactoryAcceptsCollectionInputFilter(): void { $factory = $this->createDefaultFactory(); @@ -676,7 +683,7 @@ public function testFactoryAcceptsCollectionInputFilter() $this->assertEquals(3, $inputFilter->getCount()); } - public function testFactoryWillCreateInputWithErrorMessage() + public function testFactoryWillCreateInputWithErrorMessage(): void { $factory = $this->createDefaultFactory(); $input = $factory->createInput([ @@ -686,7 +693,7 @@ public function testFactoryWillCreateInputWithErrorMessage() $this->assertEquals('My custom error message', $input->getErrorMessage()); } - public function testFactoryWillNotGetPrioritySetting() + public function testFactoryWillNotGetPrioritySetting(): void { //Reminder: Priority at which to enqueue filter; defaults to 1000 (higher executes earlier) $factory = $this->createDefaultFactory(); @@ -731,7 +738,7 @@ public function testFactoryWillNotGetPrioritySetting() $this->assertSame(3, $index); } - public function testFactoryValidatorsPriority() + public function testFactoryValidatorsPriority(): void { $order = 0; @@ -785,7 +792,7 @@ public function testFactoryValidatorsPriority() self::assertTrue($input->isValid()); } - public function testConflictNameWithInputFilterType() + public function testConflictNameWithInputFilterType(): void { $factory = $this->createDefaultFactory(); @@ -801,7 +808,7 @@ public function testConflictNameWithInputFilterType() $this->assertTrue($inputFilter->has('type')); } - public function testCustomFactoryInCollection() + public function testCustomFactoryInCollection(): void { $factory = new TestAsset\CustomFactory(); /** @var CollectionInputFilter $inputFilter */ @@ -812,10 +819,7 @@ public function testCustomFactoryInCollection() $this->assertInstanceOf(TestAsset\CustomFactory::class, $inputFilter->getFactory()); } - /** - * @group 4838 - */ - public function testCanSetInputErrorMessage() + public function testCanSetInputErrorMessage(): void { $factory = $this->createDefaultFactory(); $input = $factory->createInput([ @@ -840,7 +844,7 @@ public function testSetInputFilterManagerWithServiceManager(): void self::assertSame($filterPluginManager, $factory->getDefaultFilterChain()->getPluginManager()); } - public function testSetInputFilterManagerWithoutServiceManager() + public function testSetInputFilterManagerWithoutServiceManager(): void { $smMock = $this->createMock(ContainerInterface::class); $inputFilterManager = new InputFilterPluginManager($smMock); @@ -848,7 +852,7 @@ public function testSetInputFilterManagerWithoutServiceManager() $this->assertSame($inputFilterManager, $factory->getInputFilterManager()); } - public function testSetInputFilterManagerOnConstruct() + public function testSetInputFilterManagerOnConstruct(): void { $smMock = $this->createMock(ContainerInterface::class); $inputFilterManager = new InputFilterPluginManager($smMock); @@ -857,10 +861,9 @@ public function testSetInputFilterManagerOnConstruct() } /** - * @group 5691 * @covers \Laminas\InputFilter\Factory::createInput */ - public function testSetsBreakChainOnFailure() + public function testSetsBreakChainOnFailure(): void { $factory = $this->createDefaultFactory(); @@ -869,7 +872,7 @@ public function testSetsBreakChainOnFailure() $this->assertFalse($factory->createInput(['break_on_failure' => false])->breakOnFailure()); } - public function testCanCreateInputFilterWithNullInputs() + public function testCanCreateInputFilterWithNullInputs(): void { $factory = $this->createDefaultFactory(); @@ -890,10 +893,7 @@ public function testCanCreateInputFilterWithNullInputs() $this->assertTrue($inputFilter->has('baz')); } - /** - * @group 7010 - */ - public function testCanCreateInputFromProvider() + public function testCanCreateInputFromProvider(): void { /** @var InputProviderInterface|MockObject $provider */ $provider = $this->getMockBuilder(InputProviderInterface::class) @@ -911,10 +911,7 @@ public function testCanCreateInputFromProvider() $this->assertInstanceOf(InputInterface::class, $input); } - /** - * @group 7010 - */ - public function testCanCreateInputFilterFromProvider() + public function testCanCreateInputFilterFromProvider(): void { /** @var InputFilterProviderInterface|MockObject $provider */ $provider = $this->getMockBuilder(InputFilterProviderInterface::class) @@ -941,7 +938,7 @@ public function testCanCreateInputFilterFromProvider() $this->assertInstanceOf(InputFilterInterface::class, $inputFilter); } - public function testSuggestedTypeMayBePluginNameInInputFilterPluginManager() + public function testSuggestedTypeMayBePluginNameInInputFilterPluginManager(): void { $serviceManager = new ServiceManager\ServiceManager(); $pluginManager = new InputFilterPluginManager($serviceManager); @@ -954,7 +951,7 @@ public function testSuggestedTypeMayBePluginNameInInputFilterPluginManager() $this->assertSame('bar', $input->getName()); } - public function testInputFromPluginManagerMayBeFurtherConfiguredWithSpec() + public function testInputFromPluginManagerMayBeFurtherConfiguredWithSpec(): void { $pluginManager = new InputFilterPluginManager(new ServiceManager\ServiceManager()); $pluginManager->setService('bar', $barInput = new Input('bar')); @@ -971,7 +968,7 @@ public function testInputFromPluginManagerMayBeFurtherConfiguredWithSpec() $this->assertSame('bar', $input->getName()); } - public function testCreateInputFilterConfiguredNameWhenSpecIsIntegerIndexed() + public function testCreateInputFilterConfiguredNameWhenSpecIsIntegerIndexed(): void { $factory = $this->createDefaultFactory(); $inputFilter = $factory->createInputFilter([ @@ -984,7 +981,7 @@ public function testCreateInputFilterConfiguredNameWhenSpecIsIntegerIndexed() $this->assertTrue($inputFilter->has('foo')); } - public function testCreateInputFilterUsesAssociatedNameMappingOverConfiguredName() + public function testCreateInputFilterUsesAssociatedNameMappingOverConfiguredName(): void { $factory = $this->createDefaultFactory(); $inputFilter = $factory->createInputFilter([ @@ -998,7 +995,7 @@ public function testCreateInputFilterUsesAssociatedNameMappingOverConfiguredName $this->assertFalse($inputFilter->has('bar')); } - public function testCreateInputFilterUsesConfiguredNameForNestedInputFilters() + public function testCreateInputFilterUsesConfiguredNameForNestedInputFilters(): void { $factory = $this->createDefaultFactory(); $inputFilter = $factory->createInputFilter([ @@ -1040,25 +1037,21 @@ public function testCreateInputFilterUsesConfiguredNameForNestedInputFilters() $this->assertTrue($collectionInputFilter->has('bat')); } - public function testClearDefaultFilterChain() + public function testClearDefaultFilterChain(): void { $factory = $this->createDefaultFactory(); $factory->clearDefaultFilterChain(); $this->assertNull($factory->getDefaultFilterChain()); } - public function testClearDefaultValidatorChain() + public function testClearDefaultValidatorChain(): void { $factory = $this->createDefaultFactory(); $factory->clearDefaultValidatorChain(); $this->assertNull($factory->getDefaultValidatorChain()); } - /** - * @see https://github.com/zendframework/zend-inputfilter/issues/8 - * @see https://github.com/zendframework/zend-inputfilter/issues/155 - */ - public function testWhenCreateInputPullsInputFromThePluginManagerItMustNotOverwriteFilterAndValidatorChains() + public function testWhenCreateInputPullsInputFromThePluginManagerItMustNotOverwriteFilterAndValidatorChains(): void { $input = $this->prophesize(InputInterface::class); $input->setFilterChain(Argument::any())->shouldNotBeCalled(); @@ -1093,7 +1086,7 @@ public function testWhenCreateInputPullsInputFromThePluginManagerItMustNotOverwr $this->assertSame($input->reveal(), $factory->createInput($spec)); } - public function testFactoryCanCreateCollectionInputFilterWithRequiredMessage() + public function testFactoryCanCreateCollectionInputFilterWithRequiredMessage(): void { $factory = $this->createDefaultFactory(); $message = 'this is the validation message'; @@ -1115,10 +1108,7 @@ public function testFactoryCanCreateCollectionInputFilterWithRequiredMessage() $this->assertSame($message, $messageTemplates[Validator\NotEmpty::IS_EMPTY]); } - /** - * @return Factory - */ - protected function createDefaultFactory() + protected function createDefaultFactory(): Factory { return new Factory(); } @@ -1126,11 +1116,11 @@ protected function createDefaultFactory() /** * @param string $pluginName * @param mixed $pluginValue - * @return MockObject|InputFilterPluginManager + * @return MockObject&InputFilterPluginManager */ protected function createInputFilterPluginManagerMockForPlugin($pluginName, $pluginValue) { - /** @var InputFilterPluginManager|MockObject $pluginManager */ + /** @var InputFilterPluginManager&MockObject $pluginManager */ $pluginManager = $this->getMockBuilder(InputFilterPluginManager::class) ->disableOriginalConstructor() ->getMock(); diff --git a/test/FileInput/TestAsset/FileUploadMock.php b/test/FileInput/TestAsset/FileUploadMock.php index d802e218..30c25b0d 100644 --- a/test/FileInput/TestAsset/FileUploadMock.php +++ b/test/FileInput/TestAsset/FileUploadMock.php @@ -15,7 +15,7 @@ public function isValid($value) return true; } - /** @return array */ + /** @return array */ public function getMessages() { return []; diff --git a/test/InputTest.php b/test/InputTest.php index 7fad50de..e0608f08 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -24,7 +24,7 @@ use function json_encode; /** - * @covers \Laminas\InputFilter\Input + * @psalm-suppress DeprecatedMethod */ class InputTest extends TestCase { From 5195d0e4bba3f760fab62ebd0d925dd9f0653dab Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 19:38:27 +0100 Subject: [PATCH 02/20] Baseline introduced errors Signed-off-by: George Steel --- psalm-baseline.xml | 122 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 18 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 76088543..94ab2cd6 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -36,8 +36,12 @@ - - + + $messages + + + array<string, array<array-key, string>> + $input @@ -57,11 +61,33 @@ - + + setData + setData + + + $name + + + array<array-key, array<string, array<array-key, string>>> + $data - + + $this->collectionMessages + $this->collectionMessages + + + array<array-key, array<string, mixed>> + array<array-key, array<string, mixed>> + + + $name + + + $name + @@ -77,7 +103,6 @@ $key $options $priority - $priority $value['type'] @@ -86,7 +111,6 @@ $options $options $priority - $priority $value @@ -183,8 +207,6 @@ $this->allowEmpty - $this->allowEmpty - $this->continueIfEmpty $this->continueIfEmpty $this->notEmptyValidator $this->notEmptyValidator @@ -260,7 +282,12 @@ - + + setData + + + array<string, mixed>|null + @@ -345,14 +372,29 @@ + + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + $input $input new stdClass() new stdClass() - + public function addMethodArgumentsProvider(): array + setData @@ -415,7 +457,8 @@ $set[5] $set[6] - + + $data $inputName $inputName $inputName @@ -474,6 +517,10 @@ null + + $data + $data + $expectedInputName $expectedInputName @@ -489,6 +536,24 @@ $expectedType $inputFilter + + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + setData + new stdClass() testDataVsValid @@ -532,6 +597,9 @@ $data + + $data + $set[3] @@ -561,9 +629,13 @@ $dataSets - + $baseInputFilter $baseInputFilter + $data + $data + $data + $data expects @@ -574,6 +646,10 @@ method method + + setInputFilter + setInputFilter + @@ -608,9 +684,6 @@ getPluginManager method method - method - method - method will will @@ -627,9 +700,6 @@ breakOnFailure expects expects - expects - expects - expects getErrorMessage getErrorMessage getFilterChain @@ -861,6 +931,10 @@ + + setData + setData + $dataSets @@ -1053,6 +1127,14 @@ + + setData + setData + setData + setData + setData + setData + assertGetValuesThrows testIteratorBehavesTheSameAsArray @@ -1063,6 +1145,10 @@ testValidatesSuccessfullyWhenValidNonEmptyDataSetProvided testValidationFailureWhenInvalidDataSetIsProvided + + setData + setData + From 46739743f9a942b2f3586f259725327d59dd3cd2 Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 20:26:15 +0100 Subject: [PATCH 03/20] Adds void type hints to tests Signed-off-by: George Steel --- test/ArrayInputTest.php | 8 +- test/BaseInputFilterTest.php | 66 ++++++++-------- test/CollectionInputFilterTest.php | 2 +- test/ConfigProviderTest.php | 6 +- .../HttpServerFileInputDecoratorTest.php | 46 +++++------ test/FileInput/PsrFileInputDecoratorTest.php | 36 ++++----- .../InputFilterAbstractServiceFactoryTest.php | 20 ++--- test/InputFilterAwareTraitTest.php | 4 +- test/InputFilterPluginManagerFactoryTest.php | 12 +-- test/InputFilterPluginManagerTest.php | 18 ++--- test/InputFilterTest.php | 6 +- test/InputTest.php | 76 +++++++++---------- test/ModuleTest.php | 10 +-- test/OptionalInputFilterTest.php | 14 ++-- 14 files changed, 162 insertions(+), 162 deletions(-) diff --git a/test/ArrayInputTest.php b/test/ArrayInputTest.php index 5ed24178..1a288418 100644 --- a/test/ArrayInputTest.php +++ b/test/ArrayInputTest.php @@ -22,12 +22,12 @@ protected function setUp(): void $this->input = new ArrayInput('foo'); } - public function testDefaultGetValue() + public function testDefaultGetValue(): void { $this->assertCount(0, $this->input->getValue()); } - public function testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEmptyArrays() + public function testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEmptyArrays(): void { $input = $this->input; $input->setRequired(true); @@ -37,7 +37,7 @@ public function testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEm $this->assertRequiredValidationErrorMessage($input); } - public function testArrayInputMarkedRequiredWithoutAFallbackUsesProvidedErrorMessageOnFailureDueToEmptyArray() + public function testArrayInputMarkedRequiredWithoutAFallbackUsesProvidedErrorMessageOnFailureDueToEmptyArray(): void { $expected = 'error message'; @@ -54,7 +54,7 @@ public function testArrayInputMarkedRequiredWithoutAFallbackUsesProvidedErrorMes $this->assertEquals($expected, $message); } - public function testSetValueWithInvalidInputTypeThrowsInvalidArgumentException() + public function testSetValueWithInvalidInputTypeThrowsInvalidArgumentException(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Value must be an array, string given'); diff --git a/test/BaseInputFilterTest.php b/test/BaseInputFilterTest.php index aaf1061a..68bb7141 100644 --- a/test/BaseInputFilterTest.php +++ b/test/BaseInputFilterTest.php @@ -39,13 +39,13 @@ protected function setUp(): void $this->inputFilter = new BaseInputFilter(); } - public function testInputFilterIsEmptyByDefault() + public function testInputFilterIsEmptyByDefault(): void { $filter = $this->inputFilter; $this->assertEquals(0, count($filter)); } - public function testAddWithInvalidInputTypeThrowsInvalidArgumentException() + public function testAddWithInvalidInputTypeThrowsInvalidArgumentException(): void { $inputFilter = $this->inputFilter; @@ -58,7 +58,7 @@ public function testAddWithInvalidInputTypeThrowsInvalidArgumentException() $inputFilter->add(new stdClass()); } - public function testGetThrowExceptionIfInputDoesNotExists() + public function testGetThrowExceptionIfInputDoesNotExists(): void { $inputFilter = $this->inputFilter; @@ -67,7 +67,7 @@ public function testGetThrowExceptionIfInputDoesNotExists() $inputFilter->get('not exists'); } - public function testReplaceWithInvalidInputTypeThrowsInvalidArgumentException() + public function testReplaceWithInvalidInputTypeThrowsInvalidArgumentException(): void { $inputFilter = $this->inputFilter; $inputFilter->add(new Input('foo'), 'replace_me'); @@ -81,7 +81,7 @@ public function testReplaceWithInvalidInputTypeThrowsInvalidArgumentException() $inputFilter->replace(new stdClass(), 'replace_me'); } - public function testReplaceThrowExceptionIfInputToReplaceDoesNotExists() + public function testReplaceThrowExceptionIfInputToReplaceDoesNotExists(): void { $inputFilter = $this->inputFilter; @@ -90,7 +90,7 @@ public function testReplaceThrowExceptionIfInputToReplaceDoesNotExists() $inputFilter->replace(new Input('foo'), 'not exists'); } - public function testGetValueThrowExceptionIfInputDoesNotExists() + public function testGetValueThrowExceptionIfInputDoesNotExists(): void { $inputFilter = $this->inputFilter; @@ -99,7 +99,7 @@ public function testGetValueThrowExceptionIfInputDoesNotExists() $inputFilter->getValue('not exists'); } - public function testGetRawValueThrowExceptionIfInputDoesNotExists() + public function testGetRawValueThrowExceptionIfInputDoesNotExists(): void { $inputFilter = $this->inputFilter; @@ -108,7 +108,7 @@ public function testGetRawValueThrowExceptionIfInputDoesNotExists() $inputFilter->getRawValue('not exists'); } - public function testSetDataWithInvalidDataTypeThrowsInvalidArgumentException() + public function testSetDataWithInvalidDataTypeThrowsInvalidArgumentException(): void { $inputFilter = $this->inputFilter; @@ -118,7 +118,7 @@ public function testSetDataWithInvalidDataTypeThrowsInvalidArgumentException() $inputFilter->setData(new stdClass()); } - public function testIsValidThrowExceptionIfDataWasNotSetYet() + public function testIsValidThrowExceptionIfDataWasNotSetYet(): void { $inputFilter = $this->inputFilter; @@ -127,7 +127,7 @@ public function testIsValidThrowExceptionIfDataWasNotSetYet() $inputFilter->isValid(); } - public function testSetValidationGroupSkipsRecursionWhenInputIsNotAnInputFilter() + public function testSetValidationGroupSkipsRecursionWhenInputIsNotAnInputFilter(): void { $inputFilter = $this->inputFilter; @@ -143,7 +143,7 @@ public function testSetValidationGroupSkipsRecursionWhenInputIsNotAnInputFilter( $this->assertEquals(['fooInput'], $p->getValue($inputFilter)); } - public function testSetValidationGroupAllowsSpecifyingArrayOfInputsToNestedInputFilter() + public function testSetValidationGroupAllowsSpecifyingArrayOfInputsToNestedInputFilter(): void { $inputFilter = $this->inputFilter; @@ -168,7 +168,7 @@ public function testSetValidationGroupAllowsSpecifyingArrayOfInputsToNestedInput $this->assertEquals(['nested-input1', 'nested-input2'], $p->getValue($nestedInputFilter)); } - public function testSetValidationGroupThrowExceptionIfInputFilterNotExists() + public function testSetValidationGroupThrowExceptionIfInputFilterNotExists(): void { $inputFilter = $this->inputFilter; @@ -179,7 +179,7 @@ public function testSetValidationGroupThrowExceptionIfInputFilterNotExists() $inputFilter->setValidationGroup(['notExistInputFilter' => 'anotherNotExistsInputFilter']); } - public function testSetValidationGroupThrowExceptionIfInputFilterInArgumentListNotExists() + public function testSetValidationGroupThrowExceptionIfInputFilterInArgumentListNotExists(): void { $inputFilter = $this->inputFilter; @@ -190,7 +190,7 @@ public function testSetValidationGroupThrowExceptionIfInputFilterInArgumentListN $inputFilter->setValidationGroup('notExistInputFilter'); } - public function testHasUnknownThrowExceptionIfDataWasNotSetYet() + public function testHasUnknownThrowExceptionIfDataWasNotSetYet(): void { $inputFilter = $this->inputFilter; @@ -198,7 +198,7 @@ public function testHasUnknownThrowExceptionIfDataWasNotSetYet() $inputFilter->hasUnknown(); } - public function testGetUnknownThrowExceptionIfDataWasNotSetYet() + public function testGetUnknownThrowExceptionIfDataWasNotSetYet(): void { $inputFilter = $this->inputFilter; @@ -242,7 +242,7 @@ public function testAddHasGet( * @dataProvider addMethodArgumentsProvider * @param array|object $input */ - public function testAddRemove($input, ?string $name, ?string $expectedInputName) + public function testAddRemove($input, ?string $name, ?string $expectedInputName): void { $inputFilter = $this->inputFilter; @@ -256,7 +256,7 @@ public function testAddRemove($input, ?string $name, ?string $expectedInputName) $this->assertCount($currentNumberOfFilters - 1, $inputFilter, 'Number of filters must be decreased by 1'); } - public function testAddingInputWithNameDoesNotInjectNameInInput() + public function testAddingInputWithNameDoesNotInjectNameInInput(): void { $inputFilter = $this->inputFilter; @@ -272,7 +272,7 @@ public function testAddingInputWithNameDoesNotInjectNameInInput() * @dataProvider inputProvider * @param array|object $input */ - public function testReplace($input, ?string $inputName, object $expectedInput) + public function testReplace($input, ?string $inputName, object $expectedInput): void { $inputFilter = $this->inputFilter; $nameToReplace = 'replace_me'; @@ -367,7 +367,7 @@ public function testSetTraversableDataAndGetRawValueGetValue( ); } - public function testResetEmptyValidationGroupRecursively() + public function testResetEmptyValidationGroupRecursively(): void { $data = [ 'flat' => 'foo', @@ -439,7 +439,7 @@ public function contextProvider(): array * @param array|ArrayObject $data * @param string|array $expectedContext */ - public function testValidationContext($data, ?string $customContext, $expectedContext) + public function testValidationContext($data, ?string $customContext, $expectedContext): void { $filter = $this->inputFilter; @@ -454,7 +454,7 @@ public function testValidationContext($data, ?string $customContext, $expectedCo ); } - public function testBuildValidationContextUsingInputGetRawValue() + public function testBuildValidationContextUsingInputGetRawValue(): void { $data = []; $expectedContext = ['fooInput' => 'fooRawValue']; @@ -471,7 +471,7 @@ public function testBuildValidationContextUsingInputGetRawValue() ); } - public function testContextIsTheSameWhenARequiredInputIsGivenAndOptionalInputIsMissing() + public function testContextIsTheSameWhenARequiredInputIsGivenAndOptionalInputIsMissing(): void { $data = [ 'inputRequired' => 'inputRequiredValue', @@ -495,7 +495,7 @@ public function testContextIsTheSameWhenARequiredInputIsGivenAndOptionalInputIsM ); } - public function testValidationSkipsFieldsMarkedNotRequiredWhenNoDataPresent() + public function testValidationSkipsFieldsMarkedNotRequiredWhenNoDataPresent(): void { $filter = $this->inputFilter; @@ -544,7 +544,7 @@ public function testUnknown(array $inputs, array $data, bool $hasUnknown, array $this->assertEquals($hasUnknown, $inputFilter->hasUnknown(), 'hasUnknown() value not match'); } - public function testGetInputs() + public function testGetInputs(): void { $filter = $this->inputFilter; @@ -564,7 +564,7 @@ public function testGetInputs() /** * @group 4996 */ - public function testAddingExistingInputWillMergeIntoExisting() + public function testAddingExistingInputWillMergeIntoExisting(): void { $filter = $this->inputFilter; @@ -582,7 +582,7 @@ public function testAddingExistingInputWillMergeIntoExisting() /** * @group 6431 */ - public function testMerge() + public function testMerge(): void { $inputFilter = $this->inputFilter; $originInputFilter = new BaseInputFilter(); @@ -604,7 +604,7 @@ public function testMerge() ); } - public function testNestedInputFilterShouldAllowNonArrayValueForData() + public function testNestedInputFilterShouldAllowNonArrayValueForData(): void { $filter1 = new BaseInputFilter(); $nestedFilter = new BaseInputFilter(); @@ -622,7 +622,7 @@ public function testNestedInputFilterShouldAllowNonArrayValueForData() self::assertNull($filter1->getValues()['nested']['nestedField1']); } - public function testInstanceOfUnfilteredDataInterface() + public function testInstanceOfUnfilteredDataInterface(): void { $baseInputFilter = new BaseInputFilter(); @@ -633,21 +633,21 @@ public function testInstanceOfUnfilteredDataInterface() ); } - public function testGetUnfilteredDataReturnsArray() + public function testGetUnfilteredDataReturnsArray(): void { $baseInputFilter = new BaseInputFilter(); self::assertIsArray($baseInputFilter->getUnfilteredData()); } - public function testSetUnfilteredDataReturnsBaseInputFilter() + public function testSetUnfilteredDataReturnsBaseInputFilter(): void { $baseInputFilter = new BaseInputFilter(); self::assertInstanceOf(BaseInputFilter::class, $baseInputFilter->setUnfilteredData([])); } - public function testSettingAndReturningDataArrayUnfilteredDataInterface() + public function testSettingAndReturningDataArrayUnfilteredDataInterface(): void { $testArray = [ 'foo' => 'bar', @@ -659,7 +659,7 @@ public function testSettingAndReturningDataArrayUnfilteredDataInterface() self::assertSame($testArray, $baseInputFilter->getUnfilteredData()); } - public function testSettingAndReturnDataArrayUsingSetDataForUnfilteredDataInterface() + public function testSettingAndReturnDataArrayUsingSetDataForUnfilteredDataInterface(): void { $testArray = [ 'foo' => 'bar', @@ -671,7 +671,7 @@ public function testSettingAndReturnDataArrayUsingSetDataForUnfilteredDataInterf self::assertSame($testArray, $baseInputFilter->getUnfilteredData()); } - public function testSetDataUsingSetDataAndApplyFiltersReturningSameAsOriginalForUnfilteredData() + public function testSetDataUsingSetDataAndApplyFiltersReturningSameAsOriginalForUnfilteredData(): void { $filteredArray = [ 'bar' => 'foo', diff --git a/test/CollectionInputFilterTest.php b/test/CollectionInputFilterTest.php index 6199fbdf..cc736b36 100644 --- a/test/CollectionInputFilterTest.php +++ b/test/CollectionInputFilterTest.php @@ -38,7 +38,7 @@ protected function setUp(): void $this->inputFilter = new CollectionInputFilter(); } - public function testSetInputFilterWithInvalidTypeThrowsInvalidArgumentException() + public function testSetInputFilterWithInvalidTypeThrowsInvalidArgumentException(): void { $inputFilter = $this->inputFilter; diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 6824f3e2..92955e4c 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -10,7 +10,7 @@ final class ConfigProviderTest extends TestCase { - public function testProvidesExpectedConfiguration() + public function testProvidesExpectedConfiguration(): void { $provider = new ConfigProvider(); @@ -27,7 +27,7 @@ public function testProvidesExpectedConfiguration() $this->assertEquals($expected, $provider->getDependencyConfig()); } - public function testProvidesExpectedInputFilterConfiguration() + public function testProvidesExpectedInputFilterConfiguration(): void { $provider = new ConfigProvider(); @@ -40,7 +40,7 @@ public function testProvidesExpectedInputFilterConfiguration() $this->assertEquals($expected, $provider->getInputFilterConfig()); } - public function testInvocationProvidesDependencyConfiguration() + public function testInvocationProvidesDependencyConfiguration(): void { $provider = new ConfigProvider(); diff --git a/test/FileInput/HttpServerFileInputDecoratorTest.php b/test/FileInput/HttpServerFileInputDecoratorTest.php index fe86f4c7..8c7f196f 100644 --- a/test/FileInput/HttpServerFileInputDecoratorTest.php +++ b/test/FileInput/HttpServerFileInputDecoratorTest.php @@ -30,12 +30,12 @@ protected function setUp(): void $this->input->setAutoPrependUploadValidator(false); } - public function testRetrievingValueFiltersTheValue() + public function testRetrievingValueFiltersTheValue(): void { $this->markTestSkipped('Test are not enabled in FileInputTest'); } - public function testRetrievingValueFiltersTheValueOnlyAfterValidating() + public function testRetrievingValueFiltersTheValueOnlyAfterValidating(): void { $value = ['tmp_name' => 'bar']; $this->input->setValue($value); @@ -51,7 +51,7 @@ public function testRetrievingValueFiltersTheValueOnlyAfterValidating() $this->assertEquals($newValue, $this->input->getValue()); } - public function testCanFilterArrayOfMultiFileData() + public function testCanFilterArrayOfMultiFileData(): void { $values = [ ['tmp_name' => 'foo'], @@ -79,7 +79,7 @@ public function testCanFilterArrayOfMultiFileData() ); } - public function testCanRetrieveRawValue() + public function testCanRetrieveRawValue(): void { $value = ['tmp_name' => 'bar']; $this->input->setValue($value); @@ -90,12 +90,12 @@ public function testCanRetrieveRawValue() $this->assertEquals($value, $this->input->getRawValue()); } - public function testValidationOperatesOnFilteredValue() + public function testValidationOperatesOnFilteredValue(): void { $this->markTestSkipped('Test is not enabled in FileInputTest'); } - public function testValidationOperatesBeforeFiltering() + public function testValidationOperatesBeforeFiltering(): void { $badValue = [ 'tmp_name' => ' ' . __FILE__ . ' ', @@ -113,13 +113,13 @@ public function testValidationOperatesBeforeFiltering() $this->assertEquals($badValue, $this->input->getValue()); } - public function testAutoPrependUploadValidatorIsOnByDefault() + public function testAutoPrependUploadValidatorIsOnByDefault(): void { $input = new FileInput('foo'); $this->assertTrue($input->getAutoPrependUploadValidator()); } - public function testUploadValidatorIsAddedWhenIsValidIsCalled() + public function testUploadValidatorIsAddedWhenIsValidIsCalled(): void { $this->input->setAutoPrependUploadValidator(true); $this->assertTrue($this->input->getAutoPrependUploadValidator()); @@ -139,7 +139,7 @@ public function testUploadValidatorIsAddedWhenIsValidIsCalled() $this->assertInstanceOf(Validator\File\UploadFile::class, $validators[0]['instance']); } - public function testUploadValidatorIsNotAddedWhenIsValidIsCalled() + public function testUploadValidatorIsNotAddedWhenIsValidIsCalled(): void { $this->assertFalse($this->input->getAutoPrependUploadValidator()); $this->assertTrue($this->input->isRequired()); @@ -154,7 +154,7 @@ public function testUploadValidatorIsNotAddedWhenIsValidIsCalled() $this->assertEquals(0, count($validatorChain->getValidators())); } - public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists() + public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists(): void { $this->input->setAutoPrependUploadValidator(true); $this->assertTrue($this->input->getAutoPrependUploadValidator()); @@ -180,7 +180,7 @@ public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists() $this->assertEquals($uploadMock, $validators[0]['instance']); } - public function testValidationsRunWithoutFileArrayDueToAjaxPost() + public function testValidationsRunWithoutFileArrayDueToAjaxPost(): void { $this->input->setAutoPrependUploadValidator(true); $this->assertTrue($this->input->getAutoPrependUploadValidator()); @@ -198,7 +198,7 @@ public function testValidationsRunWithoutFileArrayDueToAjaxPost() $this->assertFalse($this->input->isValid()); } - public function testValidationsRunWithoutFileArrayIsSend() + public function testValidationsRunWithoutFileArrayIsSend(): void { $this->input->setAutoPrependUploadValidator(true); $this->assertTrue($this->input->getAutoPrependUploadValidator()); @@ -216,13 +216,13 @@ public function testValidationsRunWithoutFileArrayIsSend() } /** @param mixed $value */ - public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null) + public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null): void { $this->markTestSkipped('Test is not enabled in FileInputTest'); } /** @param mixed $value */ - public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value = null) + public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value = null): void { $this->markTestSkipped('Test is not enabled in FileInputTest'); } @@ -238,7 +238,7 @@ public function testFallbackValueVsIsValidRules( $originalValue = null, ?bool $isValid = null, $expectedValue = null - ) { + ): void { $this->markTestSkipped('Input::setFallbackValue is not implemented on FileInput'); } @@ -246,17 +246,17 @@ public function testFallbackValueVsIsValidRules( public function testFallbackValueVsIsValidRulesWhenValueNotSet( ?bool $required = null, $fallbackValue = null - ) { + ): void { $this->markTestSkipped('Input::setFallbackValue is not implemented on FileInput'); } - public function testIsEmptyFileNotArray() + public function testIsEmptyFileNotArray(): void { $rawValue = 'file'; $this->assertTrue($this->input->isEmptyFile($rawValue)); } - public function testIsEmptyFileUploadNoFile() + public function testIsEmptyFileUploadNoFile(): void { $rawValue = [ 'tmp_name' => '', @@ -265,7 +265,7 @@ public function testIsEmptyFileUploadNoFile() $this->assertTrue($this->input->isEmptyFile($rawValue)); } - public function testIsEmptyFileOk() + public function testIsEmptyFileOk(): void { $rawValue = [ 'tmp_name' => 'name', @@ -274,7 +274,7 @@ public function testIsEmptyFileOk() $this->assertFalse($this->input->isEmptyFile($rawValue)); } - public function testIsEmptyMultiFileUploadNoFile() + public function testIsEmptyMultiFileUploadNoFile(): void { $rawValue = [ [ @@ -285,7 +285,7 @@ public function testIsEmptyMultiFileUploadNoFile() $this->assertTrue($this->input->isEmptyFile($rawValue)); } - public function testIsEmptyFileMultiFileOk() + public function testIsEmptyFileMultiFileOk(): void { $rawValue = [ [ @@ -300,7 +300,7 @@ public function testIsEmptyFileMultiFileOk() $this->assertFalse($this->input->isEmptyFile($rawValue)); } - public function testDefaultInjectedUploadValidatorRespectsRelease2Convention() + public function testDefaultInjectedUploadValidatorRespectsRelease2Convention(): void { $input = new FileInput('foo'); $validatorChain = $input->getValidatorChain(); @@ -314,7 +314,7 @@ public function testDefaultInjectedUploadValidatorRespectsRelease2Convention() /** * Specific FileInput::merge extras */ - public function testFileInputMerge() + public function testFileInputMerge(): void { $source = new FileInput(); $source->setAutoPrependUploadValidator(true); diff --git a/test/FileInput/PsrFileInputDecoratorTest.php b/test/FileInput/PsrFileInputDecoratorTest.php index b0cb35c4..1057d620 100644 --- a/test/FileInput/PsrFileInputDecoratorTest.php +++ b/test/FileInput/PsrFileInputDecoratorTest.php @@ -37,12 +37,12 @@ protected function setUp(): void $this->input->setAutoPrependUploadValidator(false); } - public function testRetrievingValueFiltersTheValue() + public function testRetrievingValueFiltersTheValue(): void { $this->markTestSkipped('Test is not enabled in PsrFileInputTest'); } - public function testRetrievingValueFiltersTheValueOnlyAfterValidating() + public function testRetrievingValueFiltersTheValueOnlyAfterValidating(): void { $upload = $this->prophesize(UploadedFileInterface::class); $upload->getError()->willReturn(UPLOAD_ERR_OK); @@ -66,7 +66,7 @@ public function testRetrievingValueFiltersTheValueOnlyAfterValidating() $this->assertEquals($filteredUpload->reveal(), $this->input->getValue()); } - public function testCanFilterArrayOfMultiFileData() + public function testCanFilterArrayOfMultiFileData(): void { $values = []; for ($i = 0; $i < 3; $i += 1) { @@ -100,7 +100,7 @@ public function testCanFilterArrayOfMultiFileData() ); } - public function testCanRetrieveRawValue() + public function testCanRetrieveRawValue(): void { $value = $this->prophesize(UploadedFileInterface::class); $value->getError()->shouldNotBeCalled(); @@ -113,12 +113,12 @@ public function testCanRetrieveRawValue() $this->assertEquals($value->reveal(), $this->input->getRawValue()); } - public function testValidationOperatesOnFilteredValue() + public function testValidationOperatesOnFilteredValue(): void { $this->markTestSkipped('Test is not enabled in PsrFileInputTest'); } - public function testValidationOperatesBeforeFiltering() + public function testValidationOperatesBeforeFiltering(): void { $badValue = $this->prophesize(UploadedFileInterface::class); $badValue->getError()->willReturn(UPLOAD_ERR_NO_FILE); @@ -133,13 +133,13 @@ public function testValidationOperatesBeforeFiltering() $this->assertEquals($badValue->reveal(), $this->input->getValue()); } - public function testAutoPrependUploadValidatorIsOnByDefault() + public function testAutoPrependUploadValidatorIsOnByDefault(): void { $input = new FileInput('foo'); $this->assertTrue($input->getAutoPrependUploadValidator()); } - public function testUploadValidatorIsAddedDuringIsValidWhenAutoPrependUploadValidatorIsEnabled() + public function testUploadValidatorIsAddedDuringIsValidWhenAutoPrependUploadValidatorIsEnabled(): void { $this->input->setAutoPrependUploadValidator(true); $this->assertTrue($this->input->getAutoPrependUploadValidator()); @@ -159,7 +159,7 @@ public function testUploadValidatorIsAddedDuringIsValidWhenAutoPrependUploadVali $this->assertInstanceOf(Validator\File\UploadFile::class, $validators[0]['instance']); } - public function testUploadValidatorIsNotAddedByDefaultDuringIsValidWhenAutoPrependUploadValidatorIsDisabled() + public function testUploadValidatorIsNotAddedByDefaultDuringIsValidWhenAutoPrependUploadValidatorIsDisabled(): void { $this->assertFalse($this->input->getAutoPrependUploadValidator()); $this->assertTrue($this->input->isRequired()); @@ -178,7 +178,7 @@ public function testUploadValidatorIsNotAddedByDefaultDuringIsValidWhenAutoPrepe $this->assertEquals(0, count($validatorChain->getValidators())); } - public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists() + public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists(): void { $this->input->setAutoPrependUploadValidator(true); $this->assertTrue($this->input->getAutoPrependUploadValidator()); @@ -208,13 +208,13 @@ public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists() } /** @param mixed $value */ - public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null) + public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null): void { $this->markTestSkipped('Test is not enabled in PsrFileInputTest'); } /** @param mixed $value */ - public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value = null) + public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value = null): void { $this->markTestSkipped('Test is not enabled in PsrFileInputTest'); } @@ -238,25 +238,25 @@ public function testFallbackValueVsIsValidRules( public function testFallbackValueVsIsValidRulesWhenValueNotSet( ?bool $required = null, $fallbackValue = null - ) { + ): void { $this->markTestSkipped('Input::setFallbackValue is not implemented on PsrFileInput'); } - public function testIsEmptyFileUploadNoFile() + public function testIsEmptyFileUploadNoFile(): void { $upload = $this->prophesize(UploadedFileInterface::class); $upload->getError()->willReturn(UPLOAD_ERR_NO_FILE); $this->assertTrue($this->input->isEmptyFile($upload->reveal())); } - public function testIsEmptyFileOk() + public function testIsEmptyFileOk(): void { $upload = $this->prophesize(UploadedFileInterface::class); $upload->getError()->willReturn(UPLOAD_ERR_OK); $this->assertFalse($this->input->isEmptyFile($upload->reveal())); } - public function testIsEmptyMultiFileUploadNoFile() + public function testIsEmptyMultiFileUploadNoFile(): void { $upload = $this->prophesize(UploadedFileInterface::class); $upload->getError()->willReturn(UPLOAD_ERR_NO_FILE); @@ -266,7 +266,7 @@ public function testIsEmptyMultiFileUploadNoFile() $this->assertTrue($this->input->isEmptyFile($rawValue)); } - public function testIsEmptyFileMultiFileOk() + public function testIsEmptyFileMultiFileOk(): void { $rawValue = []; for ($i = 0; $i < 2; $i += 1) { @@ -281,7 +281,7 @@ public function testIsEmptyFileMultiFileOk() /** * Specific PsrFileInput::merge extras */ - public function testPsrFileInputMerge() + public function testPsrFileInputMerge(): void { $source = new FileInput(); $source->setAutoPrependUploadValidator(true); diff --git a/test/InputFilterAbstractServiceFactoryTest.php b/test/InputFilterAbstractServiceFactoryTest.php index 11eaf545..dab94502 100644 --- a/test/InputFilterAbstractServiceFactoryTest.php +++ b/test/InputFilterAbstractServiceFactoryTest.php @@ -45,14 +45,14 @@ protected function setUp(): void $this->factory = new InputFilterAbstractServiceFactory(); } - public function testCannotCreateServiceIfNoConfigServicePresent() + public function testCannotCreateServiceIfNoConfigServicePresent(): void { $method = 'canCreate'; $args = [$this->services, 'filter']; $this->assertFalse(call_user_func_array([$this->factory, $method], $args)); } - public function testCannotCreateServiceIfConfigServiceDoesNotHaveInputFiltersConfiguration() + public function testCannotCreateServiceIfConfigServiceDoesNotHaveInputFiltersConfiguration(): void { $this->services->setService('config', []); $method = 'canCreate'; @@ -61,7 +61,7 @@ public function testCannotCreateServiceIfConfigServiceDoesNotHaveInputFiltersCon $this->assertFalse(call_user_func_array([$this->factory, $method], $args)); } - public function testCannotCreateServiceIfConfigInputFiltersDoesNotContainMatchingServiceName() + public function testCannotCreateServiceIfConfigInputFiltersDoesNotContainMatchingServiceName(): void { $this->services->setService('config', [ 'input_filter_specs' => [], @@ -71,7 +71,7 @@ public function testCannotCreateServiceIfConfigInputFiltersDoesNotContainMatchin $this->assertFalse(call_user_func_array([$this->factory, $method], $args)); } - public function testCanCreateServiceIfConfigInputFiltersContainsMatchingServiceName() + public function testCanCreateServiceIfConfigInputFiltersContainsMatchingServiceName(): void { $this->services->setService('config', [ 'input_filter_specs' => [ @@ -83,7 +83,7 @@ public function testCanCreateServiceIfConfigInputFiltersContainsMatchingServiceN $this->assertTrue(call_user_func_array([$this->factory, $method], $args)); } - public function testCreatesInputFilterInstance() + public function testCreatesInputFilterInstance(): void { $this->services->setService('config', [ 'input_filter_specs' => [ @@ -99,7 +99,7 @@ public function testCreatesInputFilterInstance() /** * @depends testCreatesInputFilterInstance */ - public function testUsesConfiguredValidationAndFilterManagerServicesWhenCreatingInputFilter() + public function testUsesConfiguredValidationAndFilterManagerServicesWhenCreatingInputFilter(): void { $filters = new FilterPluginManager($this->services); $filter = function () { @@ -150,7 +150,7 @@ public function testUsesConfiguredValidationAndFilterManagerServicesWhenCreating $this->assertEquals(1, count($validatorChain)); } - public function testRetrieveInputFilterFromInputFilterPluginManager() + public function testRetrieveInputFilterFromInputFilterPluginManager(): void { $this->services->setService('config', [ 'input_filter_specs' => [ @@ -190,7 +190,7 @@ public function testRetrieveInputFilterFromInputFilterPluginManager() /** * @depends testCreatesInputFilterInstance */ - public function testInjectsInputFilterManagerFromServiceManager() + public function testInjectsInputFilterManagerFromServiceManager(): void { $this->services->setService('config', [ 'input_filter_specs' => [ @@ -208,7 +208,7 @@ public function testInjectsInputFilterManagerFromServiceManager() /** * @group zendframework/zend-servicemanager#123 */ - public function testAllowsPassingNonPluginManagerContainerToFactoryWithServiceManagerV2() + public function testAllowsPassingNonPluginManagerContainerToFactoryWithServiceManagerV2(): void { $this->services->setService('config', [ 'input_filter_specs' => [ @@ -226,7 +226,7 @@ public function testAllowsPassingNonPluginManagerContainerToFactoryWithServiceMa /** * @see https://github.com/zendframework/zend-inputfilter/issues/155 */ - public function testWillUseCustomFiltersWhenProvided() + public function testWillUseCustomFiltersWhenProvided(): void { $filter = $this->prophesize(Filter\FilterInterface::class)->reveal(); diff --git a/test/InputFilterAwareTraitTest.php b/test/InputFilterAwareTraitTest.php index 456de563..502b6bde 100644 --- a/test/InputFilterAwareTraitTest.php +++ b/test/InputFilterAwareTraitTest.php @@ -13,7 +13,7 @@ */ class InputFilterAwareTraitTest extends TestCase { - public function testSetInputFilter() + public function testSetInputFilter(): void { $object = $this->getObjectForTrait(InputFilterAwareTrait::class); @@ -29,7 +29,7 @@ public function testSetInputFilter() $this->assertSame($inputFilter, $p->getValue($object)); } - public function testGetInputFilter() + public function testGetInputFilter(): void { $object = $this->getObjectForTrait(InputFilterAwareTrait::class); diff --git a/test/InputFilterPluginManagerFactoryTest.php b/test/InputFilterPluginManagerFactoryTest.php index 0215ee01..70cf3590 100644 --- a/test/InputFilterPluginManagerFactoryTest.php +++ b/test/InputFilterPluginManagerFactoryTest.php @@ -16,7 +16,7 @@ class InputFilterPluginManagerFactoryTest extends TestCase { use ProphecyTrait; - public function testFactoryReturnsPluginManager() + public function testFactoryReturnsPluginManager(): void { $container = $this->prophesize(ContainerInterface::class)->reveal(); $factory = new InputFilterPluginManagerFactory(); @@ -44,7 +44,7 @@ public function pluginProvider(): array * @dataProvider pluginProvider * @psalm-param class-string $pluginType */ - public function testFactoryConfiguresPluginManagerUnderContainerInterop(string $pluginType) + public function testFactoryConfiguresPluginManagerUnderContainerInterop(string $pluginType): void { $container = $this->prophesize(ContainerInterface::class)->reveal(); $plugin = $this->prophesize($pluginType)->reveal(); @@ -58,7 +58,7 @@ public function testFactoryConfiguresPluginManagerUnderContainerInterop(string $ $this->assertSame($plugin, $filters->get('test')); } - public function testConfiguresInputFilterServicesWhenFound() + public function testConfiguresInputFilterServicesWhenFound(): void { $inputFilter = $this->prophesize(InputFilterInterface::class)->reveal(); $config = [ @@ -91,7 +91,7 @@ public function testConfiguresInputFilterServicesWhenFound() $this->assertSame($inputFilter, $inputFilters->get('test-too')); } - public function testDoesNotConfigureInputFilterServicesWhenServiceListenerPresent() + public function testDoesNotConfigureInputFilterServicesWhenServiceListenerPresent(): void { $container = $this->prophesize(ServiceLocatorInterface::class); $container->willImplement(ContainerInterface::class); @@ -108,7 +108,7 @@ public function testDoesNotConfigureInputFilterServicesWhenServiceListenerPresen $this->assertFalse($inputFilters->has('test-too')); } - public function testDoesNotConfigureInputFilterServicesWhenConfigServiceNotPresent() + public function testDoesNotConfigureInputFilterServicesWhenConfigServiceNotPresent(): void { $container = $this->prophesize(ServiceLocatorInterface::class); $container->willImplement(ContainerInterface::class); @@ -123,7 +123,7 @@ public function testDoesNotConfigureInputFilterServicesWhenConfigServiceNotPrese $this->assertInstanceOf(InputFilterPluginManager::class, $inputFilters); } - public function testDoesNotConfigureInputFilterServicesWhenConfigServiceDoesNotContainInputFiltersConfig() + public function testDoesNotConfigureInputFilterServicesWhenConfigServiceDoesNotContainInputFiltersConfig(): void { $container = $this->prophesize(ServiceLocatorInterface::class); $container->willImplement(ContainerInterface::class); diff --git a/test/InputFilterPluginManagerTest.php b/test/InputFilterPluginManagerTest.php index 4d9d5231..194e6af9 100644 --- a/test/InputFilterPluginManagerTest.php +++ b/test/InputFilterPluginManagerTest.php @@ -41,12 +41,12 @@ protected function setUp(): void $this->manager = new InputFilterPluginManager($this->services); } - public function testIsASubclassOfAbstractPluginManager() + public function testIsASubclassOfAbstractPluginManager(): void { $this->assertInstanceOf(AbstractPluginManager::class, $this->manager); } - public function testIsNotSharedByDefault() + public function testIsNotSharedByDefault(): void { $r = new ReflectionObject($this->manager); $p = $r->getProperty('sharedByDefault'); @@ -54,7 +54,7 @@ public function testIsNotSharedByDefault() $this->assertFalse($p->getValue($this->manager)); } - public function testRegisteringInvalidElementRaisesException() + public function testRegisteringInvalidElementRaisesException(): void { $this->expectException($this->getServiceNotFoundException()); $this->expectExceptionMessage( @@ -63,7 +63,7 @@ public function testRegisteringInvalidElementRaisesException() $this->manager->setService('test', $this); } - public function testLoadingInvalidElementRaisesException() + public function testLoadingInvalidElementRaisesException(): void { $this->manager->setInvokableClass('test', static::class); $this->expectException($this->getServiceNotFoundException()); @@ -84,7 +84,7 @@ public function defaultInvokableClassesProvider(): array * @dataProvider defaultInvokableClassesProvider * @psalm-param class-string $expectedInstance */ - public function testDefaultInvokableClasses(string $alias, string $expectedInstance) + public function testDefaultInvokableClasses(string $alias, string $expectedInstance): void { /** @var object $service */ $service = $this->manager->get($alias); @@ -92,7 +92,7 @@ public function testDefaultInvokableClasses(string $alias, string $expectedInsta $this->assertInstanceOf($expectedInstance, $service, 'get() return type not match'); } - public function testInputFilterInvokableClassSMDependenciesArePopulatedWithoutServiceLocator() + public function testInputFilterInvokableClassSMDependenciesArePopulatedWithoutServiceLocator(): void { /** @var InputFilter $service */ $service = $this->manager->get('inputfilter'); @@ -105,7 +105,7 @@ public function testInputFilterInvokableClassSMDependenciesArePopulatedWithoutSe ); } - public function testInputFilterInvokableClassSMDependenciesArePopulatedWithServiceLocator() + public function testInputFilterInvokableClassSMDependenciesArePopulatedWithServiceLocator(): void { $filterManager = $this->getMockBuilder(FilterPluginManager::class) ->disableOriginalConstructor() @@ -166,7 +166,7 @@ public function serviceProvider(): array /** * @dataProvider serviceProvider */ - public function testGet(string $serviceName, object $service) + public function testGet(string $serviceName, object $service): void { $this->manager->setService($serviceName, $service); @@ -192,7 +192,7 @@ public function testServicesAreInitiatedIfImplementsInitializableInterface( $initializableProphecy->init()->shouldBeCalled(); } - public function testPopulateFactoryCanAcceptInputFilterAsFirstArgumentAndWillUseFactoryWhenItDoes() + public function testPopulateFactoryCanAcceptInputFilterAsFirstArgumentAndWillUseFactoryWhenItDoes(): void { $inputFilter = new InputFilter(); $this->manager->populateFactory($inputFilter); diff --git a/test/InputFilterTest.php b/test/InputFilterTest.php index ae08d90f..284eff21 100644 --- a/test/InputFilterTest.php +++ b/test/InputFilterTest.php @@ -24,13 +24,13 @@ protected function setUp(): void $this->inputFilter = new InputFilter(); } - public function testLazilyComposesAFactoryByDefault() + public function testLazilyComposesAFactoryByDefault(): void { $factory = $this->inputFilter->getFactory(); $this->assertInstanceOf(Factory::class, $factory); } - public function testCanComposeAFactory() + public function testCanComposeAFactory(): void { $factory = $this->createFactoryMock(); $this->inputFilter->setFactory($factory); @@ -87,7 +87,7 @@ protected function createFactoryMock() * * @see https://github.com/zendframework/zend-inputfilter/issues/159 */ - public function testNestedInputFilterShouldAllowNullValueForData() + public function testNestedInputFilterShouldAllowNullValueForData(): void { $filter1 = new InputFilter(); $filter1->add([ diff --git a/test/InputTest.php b/test/InputTest.php index e0608f08..6aa89cc8 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -68,68 +68,68 @@ public function assertRequiredValidationErrorMessage(Input $input, string $messa ); } - public function testConstructorRequiresAName() + public function testConstructorRequiresAName(): void { $this->assertEquals('foo', $this->input->getName()); } - public function testInputHasEmptyFilterChainByDefault() + public function testInputHasEmptyFilterChainByDefault(): void { $filters = $this->input->getFilterChain(); $this->assertInstanceOf(FilterChain::class, $filters); $this->assertEquals(0, count($filters)); } - public function testInputHasEmptyValidatorChainByDefault() + public function testInputHasEmptyValidatorChainByDefault(): void { $validators = $this->input->getValidatorChain(); $this->assertInstanceOf(ValidatorChain::class, $validators); $this->assertEquals(0, count($validators)); } - public function testCanInjectFilterChain() + public function testCanInjectFilterChain(): void { $chain = $this->createFilterChainMock(); $this->input->setFilterChain($chain); $this->assertSame($chain, $this->input->getFilterChain()); } - public function testCanInjectValidatorChain() + public function testCanInjectValidatorChain(): void { $chain = $this->createValidatorChainMock(); $this->input->setValidatorChain($chain); $this->assertSame($chain, $this->input->getValidatorChain()); } - public function testInputIsMarkedAsRequiredByDefault() + public function testInputIsMarkedAsRequiredByDefault(): void { $this->assertTrue($this->input->isRequired()); } - public function testRequiredFlagIsMutable() + public function testRequiredFlagIsMutable(): void { $this->input->setRequired(false); $this->assertFalse($this->input->isRequired()); } - public function testInputDoesNotAllowEmptyValuesByDefault() + public function testInputDoesNotAllowEmptyValuesByDefault(): void { $this->assertFalse($this->input->allowEmpty()); } - public function testAllowEmptyFlagIsMutable() + public function testAllowEmptyFlagIsMutable(): void { $this->input->setAllowEmpty(true); $this->assertTrue($this->input->allowEmpty()); } - public function testContinueIfEmptyFlagIsFalseByDefault() + public function testContinueIfEmptyFlagIsFalseByDefault(): void { $input = $this->input; $this->assertFalse($input->continueIfEmpty()); } - public function testContinueIfEmptyFlagIsMutable() + public function testContinueIfEmptyFlagIsMutable(): void { $input = $this->input; $input->setContinueIfEmpty(true); @@ -140,7 +140,7 @@ public function testContinueIfEmptyFlagIsMutable() * @dataProvider setValueProvider * @param mixed $fallbackValue */ - public function testSetFallbackValue($fallbackValue) + public function testSetFallbackValue($fallbackValue): void { $input = $this->input; @@ -155,7 +155,7 @@ public function testSetFallbackValue($fallbackValue) * @dataProvider setValueProvider * @param mixed $fallbackValue */ - public function testClearFallbackValue($fallbackValue) + public function testClearFallbackValue($fallbackValue): void { $input = $this->input; $input->setFallbackValue($fallbackValue); @@ -199,7 +199,7 @@ public function testFallbackValueVsIsValidRules( * @dataProvider fallbackValueVsIsValidProvider * @param string|string[] $fallbackValue */ - public function testFallbackValueVsIsValidRulesWhenValueNotSet(bool $required, $fallbackValue) + public function testFallbackValueVsIsValidRulesWhenValueNotSet(bool $required, $fallbackValue): void { $expectedValue = $fallbackValue; // Should always return the fallback value @@ -220,7 +220,7 @@ public function testFallbackValueVsIsValidRulesWhenValueNotSet(bool $required, $ $this->assertSame($expectedValue, $input->getValue(), 'getValue() value not match'); } - public function testRequiredWithoutFallbackAndValueNotSetThenFail() + public function testRequiredWithoutFallbackAndValueNotSetThenFail(): void { $input = $this->input; $input->setRequired(true); @@ -232,7 +232,7 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFail() $this->assertRequiredValidationErrorMessage($input); } - public function testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomErrorMessageWhenSet() + public function testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomErrorMessageWhenSet(): void { $input = $this->input; $input->setRequired(true); @@ -249,7 +249,7 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomEr * @group 28 * @group 60 */ - public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage() + public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage(): void { $input = $this->input; $input->setRequired(true); @@ -266,7 +266,7 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat * @group 28 * @group 69 */ - public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage() + public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage(): void { $input = new Input(); $input->setRequired(true); @@ -299,7 +299,7 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmpt * @group 28 * @group 60 */ - public function testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMessageWhenSet() + public function testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMessageWhenSet(): void { $input = $this->input; $input->setRequired(true); @@ -313,7 +313,7 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMess $this->assertSame(['FAILED TO VALIDATE'], $input->getMessages()); } - public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid() + public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid(): void { $input = $this->input; $input->setRequired(false); @@ -335,7 +335,7 @@ public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid() * @dataProvider emptyValueProvider * @param mixed $value */ - public function testNotEmptyValidatorNotInjectedIfContinueIfEmptyIsTrue($value) + public function testNotEmptyValidatorNotInjectedIfContinueIfEmptyIsTrue($value): void { $input = $this->input; $input->setContinueIfEmpty(true); @@ -346,12 +346,12 @@ public function testNotEmptyValidatorNotInjectedIfContinueIfEmptyIsTrue($value) $this->assertEmpty($validators); } - public function testDefaultGetValue() + public function testDefaultGetValue(): void { $this->assertNull($this->input->getValue()); } - public function testValueMayBeInjected() + public function testValueMayBeInjected(): void { $valueRaw = $this->getDummyValue(); @@ -359,7 +359,7 @@ public function testValueMayBeInjected() $this->assertEquals($valueRaw, $this->input->getValue()); } - public function testRetrievingValueFiltersTheValue() + public function testRetrievingValueFiltersTheValue(): void { $valueRaw = $this->getDummyValue(); $valueFiltered = $this->getDummyValue(false); @@ -372,7 +372,7 @@ public function testRetrievingValueFiltersTheValue() $this->assertSame($valueFiltered, $this->input->getValue()); } - public function testCanRetrieveRawValue() + public function testCanRetrieveRawValue(): void { $valueRaw = $this->getDummyValue(); @@ -384,7 +384,7 @@ public function testCanRetrieveRawValue() $this->assertEquals($valueRaw, $this->input->getRawValue()); } - public function testValidationOperatesOnFilteredValue() + public function testValidationOperatesOnFilteredValue(): void { $valueRaw = $this->getDummyValue(); $valueFiltered = $this->getDummyValue(false); @@ -404,12 +404,12 @@ public function testValidationOperatesOnFilteredValue() ); } - public function testBreakOnFailureFlagIsOffByDefault() + public function testBreakOnFailureFlagIsOffByDefault(): void { $this->assertFalse($this->input->breakOnFailure()); } - public function testBreakOnFailureFlagIsMutable() + public function testBreakOnFailureFlagIsMutable(): void { $this->input->setBreakOnFailure(true); $this->assertTrue($this->input->breakOnFailure()); @@ -419,7 +419,7 @@ public function testBreakOnFailureFlagIsMutable() * @dataProvider emptyValueProvider * @param mixed $value */ - public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value) + public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value): void { $this->assertTrue($this->input->isRequired()); $this->input->setValue($value); @@ -440,7 +440,7 @@ public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value) * @dataProvider emptyValueProvider * @param mixed $value */ - public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value) + public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value): void { $this->input->setRequired(true); $this->input->setValue($value); @@ -461,7 +461,7 @@ public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value) * @param mixed $valueRaw * @param mixed $valueFiltered */ - public function testDoNotInjectNotEmptyValidatorIfAnywhereInChain($valueRaw, $valueFiltered) + public function testDoNotInjectNotEmptyValidatorIfAnywhereInChain($valueRaw, $valueFiltered): void { $filterChain = $this->createFilterChainMock([[$valueRaw, $valueFiltered]]); $validatorChain = $this->input->getValidatorChain(); @@ -517,7 +517,7 @@ public function testIsRequiredVsAllowEmptyVsContinueIfEmptyVsIsValid( * @dataProvider setValueProvider * @param mixed $value */ - public function testSetValuePutInputInTheDesiredState($value) + public function testSetValuePutInputInTheDesiredState($value): void { $input = $this->input; $this->assertFalse($input->hasValue(), 'Input should not have value by default'); @@ -530,7 +530,7 @@ public function testSetValuePutInputInTheDesiredState($value) * @dataProvider setValueProvider * @param mixed $value */ - public function testResetValueReturnsInputValueToDefaultValue($value) + public function testResetValueReturnsInputValueToDefaultValue($value): void { $input = $this->input; $originalInput = clone $input; @@ -544,7 +544,7 @@ public function testResetValueReturnsInputValueToDefaultValue($value) $this->assertEquals($originalInput, $input, 'Input was not reset to the default value state'); } - public function testMerge() + public function testMerge(): void { $sourceRawValue = $this->getDummyValue(); @@ -589,7 +589,7 @@ public function testMerge() /** * Specific Input::merge extras */ - public function testInputMergeWithoutValues() + public function testInputMergeWithoutValues(): void { $source = new Input(); $source->setContinueIfEmpty(true); @@ -609,7 +609,7 @@ public function testInputMergeWithoutValues() /** * Specific Input::merge extras */ - public function testInputMergeWithSourceValue() + public function testInputMergeWithSourceValue(): void { $source = new Input(); $source->setContinueIfEmpty(true); @@ -630,7 +630,7 @@ public function testInputMergeWithSourceValue() /** * Specific Input::merge extras */ - public function testInputMergeWithTargetValue() + public function testInputMergeWithTargetValue(): void { $source = new Input(); $source->setContinueIfEmpty(true); @@ -648,7 +648,7 @@ public function testInputMergeWithTargetValue() $this->assertTrue($target->hasValue(), 'hasValue() value not match'); } - public function testNotEmptyMessageIsTranslated() + public function testNotEmptyMessageIsTranslated(): void { /** @var TranslatorInterface|MockObject $translator */ $translator = $this->createMock(TranslatorInterface::class); diff --git a/test/ModuleTest.php b/test/ModuleTest.php index a9a1c59b..3d3c0704 100644 --- a/test/ModuleTest.php +++ b/test/ModuleTest.php @@ -21,7 +21,7 @@ protected function setUp(): void $this->module = new Module(); } - public function testGetConfigMethodShouldReturnExpectedKeys() + public function testGetConfigMethodShouldReturnExpectedKeys(): void { $config = $this->module->getConfig(); @@ -32,7 +32,7 @@ public function testGetConfigMethodShouldReturnExpectedKeys() $this->assertArrayHasKey('input_filters', $config); } - public function testServiceManagerConfigShouldContainInputFilterManager() + public function testServiceManagerConfigShouldContainInputFilterManager(): void { $config = $this->module->getConfig(); @@ -42,7 +42,7 @@ public function testServiceManagerConfigShouldContainInputFilterManager() ); } - public function testServiceManagerConfigShouldContainAliasForInputFilterManager() + public function testServiceManagerConfigShouldContainAliasForInputFilterManager(): void { $config = $this->module->getConfig(); @@ -52,7 +52,7 @@ public function testServiceManagerConfigShouldContainAliasForInputFilterManager( ); } - public function testInputFilterConfigShouldContainAbstractServiceFactory() + public function testInputFilterConfigShouldContainAbstractServiceFactory(): void { $config = $this->module->getConfig(); @@ -62,7 +62,7 @@ public function testInputFilterConfigShouldContainAbstractServiceFactory() ); } - public function testInitMethodShouldRegisterPluginManagerSpecificationWithServiceListener() + public function testInitMethodShouldRegisterPluginManagerSpecificationWithServiceListener(): void { // Service listener $serviceListener = $this->prophesize(TestAsset\ServiceListenerInterface::class); diff --git a/test/OptionalInputFilterTest.php b/test/OptionalInputFilterTest.php index b15cc984..42a85edf 100644 --- a/test/OptionalInputFilterTest.php +++ b/test/OptionalInputFilterTest.php @@ -15,12 +15,12 @@ */ class OptionalInputFilterTest extends TestCase { - public function testValidatesSuccessfullyWhenSetDataIsNeverCalled() + public function testValidatesSuccessfullyWhenSetDataIsNeverCalled(): void { $this->assertTrue($this->getNestedCarInputFilter()->get('car')->isValid()); } - public function testValidatesSuccessfullyWhenValidNonEmptyDataSetProvided() + public function testValidatesSuccessfullyWhenValidNonEmptyDataSetProvided(): void { $data = [ 'car' => [ @@ -36,7 +36,7 @@ public function testValidatesSuccessfullyWhenValidNonEmptyDataSetProvided() $this->assertEquals($data, $inputFilter->getValues()); } - public function testValidatesSuccessfullyWhenEmptyDataSetProvided() + public function testValidatesSuccessfullyWhenEmptyDataSetProvided(): void { $data = [ 'car' => null, @@ -49,7 +49,7 @@ public function testValidatesSuccessfullyWhenEmptyDataSetProvided() $this->assertEquals($data, $inputFilter->getValues()); } - public function testValidatesSuccessfullyWhenNoDataProvided() + public function testValidatesSuccessfullyWhenNoDataProvided(): void { $data = []; @@ -60,7 +60,7 @@ public function testValidatesSuccessfullyWhenNoDataProvided() $this->assertEquals(['car' => null], $inputFilter->getValues()); } - public function testValidationFailureWhenInvalidDataSetIsProvided() + public function testValidationFailureWhenInvalidDataSetIsProvided(): void { $inputFilter = $this->getNestedCarInputFilter(); $inputFilter->setData([ @@ -73,7 +73,7 @@ public function testValidationFailureWhenInvalidDataSetIsProvided() $this->assertGetValuesThrows($inputFilter); } - public function testStateIsClearedBetweenValidationAttempts() + public function testStateIsClearedBetweenValidationAttempts(): void { $data = [ 'car' => null, @@ -90,7 +90,7 @@ public function testStateIsClearedBetweenValidationAttempts() * We are doing some boolean shenanigans in the implementation * we want to check that Iterator objects work the same as arrays */ - public function testIteratorBehavesTheSameAsArray() + public function testIteratorBehavesTheSameAsArray(): void { $optionalInputFilter = new OptionalInputFilter(); $optionalInputFilter->add(new Input('brand')); From d78d08f23448098b90381765a9db2bac757a8074 Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 20:58:20 +0100 Subject: [PATCH 04/20] Replace custom psalm type "InputData" for `array` The custom type won't work because of the lack of support for recursive types in psalm Signed-off-by: George Steel --- src/BaseInputFilter.php | 24 +++++++++++------------- src/CollectionInputFilter.php | 29 +++++++++++++---------------- src/InputFilterInterface.php | 5 ++--- src/OptionalInputFilter.php | 6 ++---- src/UnfilteredDataInterface.php | 6 ++---- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index 10e9b3d1..911ea3cf 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -13,6 +13,7 @@ use function array_key_exists; use function array_keys; use function array_merge; +use function assert; use function count; use function func_get_args; use function get_class; @@ -23,9 +24,6 @@ use function is_string; use function sprintf; -/** - * @psalm-import-type InputData from InputFilterInterface - */ class BaseInputFilter implements InputFilterInterface, UnknownInputsCapableInterface, @@ -33,10 +31,10 @@ class BaseInputFilter implements ReplaceableInputInterface, UnfilteredDataInterface { - /** @var InputData|null */ + /** @var array|null */ protected $data; - /** @var InputData */ + /** @var array */ protected $unfilteredData = []; /** @var array */ @@ -184,16 +182,15 @@ public function remove($name) /** * Set data to use when validating and filtering * - * @param InputData|Traversable|null $data null is cast to an empty array. + * @param array|Traversable|null $data null is cast to an empty array. * @throws Exception\InvalidArgumentException * @return InputFilterInterface - * @psalm-assert InputData $this->data + * @psalm-assert array $this->data */ public function setData($data) { // A null value indicates an empty set if (null === $data) { - /** @psalm-var InputData $data */ $data = []; } @@ -461,7 +458,7 @@ public function getRawValue($name) * List should be an associative array of named input/value pairs, * with the values unfiltered. * - * @return InputData|array + * @return array */ public function getRawValues() { @@ -523,6 +520,7 @@ protected function validateValidationGroup(array $inputs) */ protected function populate() { + assert($this->data !== null); foreach (array_keys($this->inputs) as $name) { $input = $this->inputs[$name]; @@ -547,7 +545,7 @@ protected function populate() continue; } - /** @psalm-var array|mixed $value */ + /** @psalm-var mixed $value */ $value = $this->data[$name]; if ($input instanceof InputFilterInterface) { @@ -555,8 +553,8 @@ protected function populate() if (! is_array($value) && ! $value instanceof Traversable) { $value = []; } + /** @psalm-var array $value */ - /** @psalm-var InputData $value */ $input->setData($value); continue; } @@ -631,7 +629,7 @@ public function merge(BaseInputFilter $inputFilter) } /** - * @return InputData + * @return array */ public function getUnfilteredData() { @@ -639,7 +637,7 @@ public function getUnfilteredData() } /** - * @param InputData $data + * @param array $data * @return $this */ public function setUnfilteredData($data) diff --git a/src/CollectionInputFilter.php b/src/CollectionInputFilter.php index 0cd42cb8..37f2537d 100644 --- a/src/CollectionInputFilter.php +++ b/src/CollectionInputFilter.php @@ -2,6 +2,7 @@ namespace Laminas\InputFilter; +use Laminas\Stdlib\ArrayUtils; use Laminas\Validator\NotEmpty; use Traversable; @@ -12,27 +13,18 @@ use function is_object; use function sprintf; -/** - * @psalm-import-type InputData from InputFilterInterface - */ class CollectionInputFilter extends InputFilter { - /** - * @var array|null - * @psalm-suppress NonInvariantDocblockPropertyType - */ - protected $data; - /** @var bool */ protected $isRequired = false; /** @var null|int */ protected $count; - /** @var array> */ + /** @var array */ protected $collectionValues = []; - /** @var array> */ + /** @var array */ protected $collectionRawValues = []; /** @var array>> */ @@ -156,15 +148,15 @@ public function getCount() } /** - * @param array|Traversable $data + * @param mixed $data * @psalm-suppress ImplementedParamTypeMismatch - * @psalm-assert array|Traversable $this->data + * @psalm-assert array $this->data * @return $this */ public function setData($data) { /** @psalm-suppress DocblockTypeContradiction, RedundantConditionGivenDocblockType */ - if (! (is_array($data) || $data instanceof Traversable)) { + if (! is_array($data) && ! $data instanceof Traversable) { throw new Exception\InvalidArgumentException(sprintf( '%s expects an array or Traversable collection; invalid collection of type %s provided', __METHOD__, @@ -172,8 +164,11 @@ public function setData($data) )); } + $data = ArrayUtils::iteratorToArray($data); + $this->setUnfilteredData($data); + /** @psalm-var mixed $item */ foreach ($data as $item) { /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ if (is_array($item) || $item instanceof Traversable) { @@ -251,6 +246,7 @@ public function isValid($context = null) return $valid; } + /** @psalm-var array $data */ foreach ($this->data as $key => $data) { $inputFilter->setData($data); @@ -288,7 +284,7 @@ public function setValidationGroup($name) } /** - * @return array> + * @return array */ public function getValues() { @@ -296,7 +292,7 @@ public function getValues() } /** - * @return array> + * @return array */ public function getRawValues() { @@ -346,6 +342,7 @@ public function getUnknown() $inputFilter = $this->getInputFilter(); $unknownInputs = []; + /** @psalm-var array $data */ foreach ($this->data as $key => $data) { $inputFilter->setData($data); diff --git a/src/InputFilterInterface.php b/src/InputFilterInterface.php index d75ba811..684b1038 100644 --- a/src/InputFilterInterface.php +++ b/src/InputFilterInterface.php @@ -33,7 +33,6 @@ * filters?: FilterChain|iterable, * validators?: ValidatorChain|iterable, * }&array - * @psalm-type InputData = array */ interface InputFilterInterface extends Countable { @@ -78,7 +77,7 @@ public function remove($name); /** * Set data to use when validating and filtering * - * @param InputData|Traversable|null $data + * @param array|Traversable|null $data * @return InputFilterInterface */ public function setData($data); @@ -158,7 +157,7 @@ public function getRawValue($name); * List should be an associative array of named input/value pairs, * with the values unfiltered. * - * @return InputData + * @return array */ public function getRawValues(); diff --git a/src/OptionalInputFilter.php b/src/OptionalInputFilter.php index beb7590d..f4c6d3f9 100644 --- a/src/OptionalInputFilter.php +++ b/src/OptionalInputFilter.php @@ -8,19 +8,17 @@ * InputFilter which only checks the containing Inputs when non-empty data is set, * else it reports valid * This is analog to {@see Input} with the option ->setRequired(false) - * - * @psalm-import-type InputData from InputFilterInterface */ class OptionalInputFilter extends InputFilter { /** * Set data to use when validating and filtering * - * @param InputData|Traversable|null $data must be a non-empty iterable in order trigger + * @param array|Traversable|null $data must be a non-empty iterable in order trigger * actual validation, else it is always valid * @return $this * @throws Exception\InvalidArgumentException - * @psalm-assert InputData $this->data + * @psalm-assert array $this->data */ public function setData($data) { diff --git a/src/UnfilteredDataInterface.php b/src/UnfilteredDataInterface.php index aed96265..d985796f 100644 --- a/src/UnfilteredDataInterface.php +++ b/src/UnfilteredDataInterface.php @@ -4,18 +4,16 @@ /** * Ensures Inputs store unfiltered data and are capable of returning it - * - * @psalm-import-type InputData from InputFilterInterface */ interface UnfilteredDataInterface { /** - * @return InputData + * @return array */ public function getUnfilteredData(); /** - * @param InputData $data + * @param array $data * @return $this */ public function setUnfilteredData($data); From f4200dac4ce51f60d58cdff5729b77ac2b200771 Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 21:11:34 +0100 Subject: [PATCH 05/20] Where traversable is an accepted type for input data, reduce to iterable pseudo type Signed-off-by: George Steel --- src/BaseInputFilter.php | 4 ++-- src/InputFilterInterface.php | 2 +- src/OptionalInputFilter.php | 6 ++---- test/BaseInputFilterTest.php | 4 ++-- test/InputTest.php | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index 911ea3cf..a64258c9 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -182,7 +182,7 @@ public function remove($name) /** * Set data to use when validating and filtering * - * @param array|Traversable|null $data null is cast to an empty array. + * @param iterable|null $data null is cast to an empty array. * @throws Exception\InvalidArgumentException * @return InputFilterInterface * @psalm-assert array $this->data @@ -553,7 +553,7 @@ protected function populate() if (! is_array($value) && ! $value instanceof Traversable) { $value = []; } - /** @psalm-var array $value */ + /** @psalm-var iterable $value */ $input->setData($value); continue; diff --git a/src/InputFilterInterface.php b/src/InputFilterInterface.php index 684b1038..efe7ee76 100644 --- a/src/InputFilterInterface.php +++ b/src/InputFilterInterface.php @@ -77,7 +77,7 @@ public function remove($name); /** * Set data to use when validating and filtering * - * @param array|Traversable|null $data + * @param iterable|null $data * @return InputFilterInterface */ public function setData($data); diff --git a/src/OptionalInputFilter.php b/src/OptionalInputFilter.php index f4c6d3f9..3ff29d29 100644 --- a/src/OptionalInputFilter.php +++ b/src/OptionalInputFilter.php @@ -2,8 +2,6 @@ namespace Laminas\InputFilter; -use Traversable; - /** * InputFilter which only checks the containing Inputs when non-empty data is set, * else it reports valid @@ -14,8 +12,8 @@ class OptionalInputFilter extends InputFilter /** * Set data to use when validating and filtering * - * @param array|Traversable|null $data must be a non-empty iterable in order trigger - * actual validation, else it is always valid + * @param iterable|null $data must be a non-empty iterable in order trigger + * actual validation, else it is always valid * @return $this * @throws Exception\InvalidArgumentException * @psalm-assert array $this->data diff --git a/test/BaseInputFilterTest.php b/test/BaseInputFilterTest.php index 68bb7141..1b3ee3d2 100644 --- a/test/BaseInputFilterTest.php +++ b/test/BaseInputFilterTest.php @@ -415,7 +415,7 @@ public function testResetEmptyValidationGroupRecursively(): void /** * @psalm-return array|ArrayObject, + * 0: iterable, * 1: null|string, * 2: array|string * }> @@ -436,7 +436,7 @@ public function contextProvider(): array /** * @dataProvider contextProvider - * @param array|ArrayObject $data + * @param iterable $data * @param string|array $expectedContext */ public function testValidationContext($data, ?string $customContext, $expectedContext): void diff --git a/test/InputTest.php b/test/InputTest.php index 6aa89cc8..3bd5472a 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -266,7 +266,7 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat * @group 28 * @group 69 */ - public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage(): void + public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage(): void // phpcs:ignore { $input = new Input(); $input->setRequired(true); From 8edf9a30ef5fa8ca5f95e71c7fcad882278c5a8c Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 21:57:12 +0100 Subject: [PATCH 06/20] Fix a range of low-hanging fruit and update baseline Signed-off-by: George Steel --- psalm-baseline.xml | 414 +------------------ src/Input.php | 1 + test/ArrayInputTest.php | 10 +- test/BaseInputFilterTest.php | 6 +- test/CollectionInputFilterTest.php | 42 +- test/FileInput/PsrFileInputDecoratorTest.php | 2 +- test/InputFilterPluginManagerTest.php | 14 +- test/InputTest.php | 28 +- test/OptionalInputFilterTest.php | 2 +- test/TestAsset/ModuleManagerInterface.php | 2 +- test/TestAsset/ServiceListenerInterface.php | 4 +- 11 files changed, 72 insertions(+), 453 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 94ab2cd6..566b7270 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -52,36 +52,23 @@ $input - - $this->data - isValid isValid - - setData - setData - $name array<array-key, array<string, array<array-key, string>>> - - $data - $this->collectionMessages $this->collectionMessages - - array<array-key, array<string, mixed>> - array<array-key, array<string, mixed>> - + $name @@ -221,9 +208,6 @@ $this->prepareRequiredValidationFailureMessage() - - clearFallbackValue - $value @@ -282,74 +266,39 @@ - - setData - array<string, mixed>|null - - FilterChain&MockObject - NotEmptyValidator&MockObject - ValidatorChain&MockObject + string[] - + $dataSets - parent::createFilterChainMock($valueMap) - parent::createNonEmptyValidatorMock($isValid, $value, $context) - parent::createValidatorChainMock($valueMap, $messages) - - FilterChain&MockObject - NotEmptyValidator&MockObject - ValidatorChain&MockObject - + $set $set $set - - function ($values) { - function ($values) { - - - testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEmptyArrays - testArrayInputMarkedRequiredWithoutAFallbackUsesProvidedErrorMessageOnFailureDueToEmptyArray - testDefaultGetValue - testSetValueWithInvalidInputTypeThrowsInvalidArgumentException - - + $this->input->getValue() - $values[0] - $values[0] - $values[1] - + $set['raw'] $set['raw'] $set[1] $set[2] $set[4] - $values[0] - $values[0] - $values[0] - $values[0] - $values[1] - $values[1] - + $set['raw'] $set['raw'] $set[1] $set[2] $set[4] - $values[0] - $values[0] - $values[1] $value @@ -365,27 +314,8 @@ isArray isArray - - FilterChain&MockObject - NotEmptyValidator&MockObject - ValidatorChain&MockObject - - - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - $input $input @@ -411,44 +341,6 @@ function ($inputTypeData) { function ($inputTypeData) { - - testAddHasGet - testAddRemove - testAddWithInvalidInputTypeThrowsInvalidArgumentException - testAddingExistingInputWillMergeIntoExisting - testAddingInputWithNameDoesNotInjectNameInInput - testBuildValidationContextUsingInputGetRawValue - testContextIsTheSameWhenARequiredInputIsGivenAndOptionalInputIsMissing - testGetInputs - testGetRawValueThrowExceptionIfInputDoesNotExists - testGetThrowExceptionIfInputDoesNotExists - testGetUnfilteredDataReturnsArray - testGetUnknownThrowExceptionIfDataWasNotSetYet - testGetValueThrowExceptionIfInputDoesNotExists - testHasUnknownThrowExceptionIfDataWasNotSetYet - testInputFilterIsEmptyByDefault - testInstanceOfUnfilteredDataInterface - testIsValidThrowExceptionIfDataWasNotSetYet - testMerge - testNestedInputFilterShouldAllowNonArrayValueForData - testReplace - testReplaceThrowExceptionIfInputToReplaceDoesNotExists - testReplaceWithInvalidInputTypeThrowsInvalidArgumentException - testResetEmptyValidationGroupRecursively - testSetDataAndGetRawValueGetValue - testSetDataUsingSetDataAndApplyFiltersReturningSameAsOriginalForUnfilteredData - testSetDataWithInvalidDataTypeThrowsInvalidArgumentException - testSetTraversableDataAndGetRawValueGetValue - testSetUnfilteredDataReturnsBaseInputFilter - testSetValidationGroupAllowsSpecifyingArrayOfInputsToNestedInputFilter - testSetValidationGroupSkipsRecursionWhenInputIsNotAnInputFilter - testSetValidationGroupThrowExceptionIfInputFilterInArgumentListNotExists - testSetValidationGroupThrowExceptionIfInputFilterNotExists - testSettingAndReturnDataArrayUsingSetDataForUnfilteredDataInterface - testSettingAndReturningDataArrayUnfilteredDataInterface - testValidationContext - testValidationSkipsFieldsMarkedNotRequiredWhenNoDataPresent - $data $dataTypes['Traversable']($data) @@ -517,10 +409,6 @@ null - - $data - $data - $expectedInputName $expectedInputName @@ -536,24 +424,6 @@ $expectedType $inputFilter - - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - setData - new stdClass() testDataVsValid @@ -570,36 +440,6 @@ function () use ($dataRaw, $dataFiltered) { function () use ($dataRaw, $dataFiltered, $errorMessage) { - - testAllowsComposingANotEmptyValidator - testCollectionValidationDoesNotReuseMessagesBetweenInputs - testCollectionValidationUsesCustomInputErrorMessages - testDataVsValid - testDuplicatedErrorMessages - testGetCountReturnsRightCountOnConsecutiveCallsWithDifferentData - testGetDefaultInputFilter - testGetUnknownFieldIsUnknown - testGetUnknownWhenAllFieldsAreKnownReturnsAnEmptyArray - testGetUnknownWhenDataAreNotProvidedThrowsRuntimeException - testLazyLoadsANotEmptyValidatorWhenNoneProvided - testNestingCollectionCountCached - testSetCount - testSetDataUsingSetDataAndRunningIsValidReturningSameAsOriginalForUnfilteredData - testSetInputFilter - testSetInputFilterWithInvalidTypeThrowsInvalidArgumentException - testSetRequired - testSetValidationGroupUsingFormStyle - testSettingDataAsArrayWithInvalidCollectionsRaisesException - testSettingDataAsTraversableWithInvalidCollectionsRaisesException - testSettingDataWithNonArrayNonTraversableRaisesException - testUsesMessageFromComposedNotEmptyValidatorWhenRequiredButCollectionIsEmpty - - - $data - - - $data - $set[3] @@ -629,13 +469,9 @@ $dataSets - + $baseInputFilter $baseInputFilter - $data - $data - $data - $data expects @@ -651,13 +487,6 @@ setInputFilter - - - testInvocationProvidesDependencyConfiguration - testProvidesExpectedConfiguration - testProvidesExpectedInputFilterConfiguration - - allowEmpty @@ -735,45 +564,12 @@ iterable - - testAutoPrependUploadValidatorIsOnByDefault - testCanFilterArrayOfMultiFileData - testCanRetrieveRawValue - testDefaultInjectedUploadValidatorRespectsRelease2Convention - testFallbackValueVsIsValidRules - testFallbackValueVsIsValidRulesWhenValueNotSet - testFileInputMerge - testIsEmptyFileMultiFileOk - testIsEmptyFileNotArray - testIsEmptyFileOk - testIsEmptyFileUploadNoFile - testIsEmptyMultiFileUploadNoFile - testNotEmptyValidatorAddedWhenIsValidIsCalled - testRequiredNotEmptyValidatorNotAddedWhenOneExists - testRequiredUploadValidatorValidatorNotAddedWhenOneExists - testRetrievingValueFiltersTheValue - testRetrievingValueFiltersTheValueOnlyAfterValidating - testUploadValidatorIsAddedWhenIsValidIsCalled - testUploadValidatorIsNotAddedWhenIsValidIsCalled - testValidationOperatesBeforeFiltering - testValidationOperatesOnFilteredValue - testValidationsRunWithoutFileArrayDueToAjaxPost - testValidationsRunWithoutFileArrayIsSend - array $input - - $this->createFilterChainMock([[$badValue, $filteredValue]]) - $this->createFilterChainMock([[$value, $newValue]]) - $this->createFilterChainMock([[$value, $newValue]]) - $this->createValidatorChainMock([[$badValue, null, false]]) - $this->createValidatorChainMock([[$expectedNormalizedValue, null, false]]) - $this->createValidatorChainMock([[$expectedNormalizedValue, null, false]]) - new FileInput('foo') @@ -783,38 +579,12 @@ UploadedFileInterface - - testAutoPrependUploadValidatorIsOnByDefault - testCanFilterArrayOfMultiFileData - testCanRetrieveRawValue - testFallbackValueVsIsValidRules - testFallbackValueVsIsValidRulesWhenValueNotSet - testIsEmptyFileMultiFileOk - testIsEmptyFileOk - testIsEmptyFileUploadNoFile - testIsEmptyMultiFileUploadNoFile - testNotEmptyValidatorAddedWhenIsValidIsCalled - testPsrFileInputMerge - testRequiredNotEmptyValidatorNotAddedWhenOneExists - testRequiredUploadValidatorValidatorNotAddedWhenOneExists - testRetrievingValueFiltersTheValue - testRetrievingValueFiltersTheValueOnlyAfterValidating - testUploadValidatorIsAddedDuringIsValidWhenAutoPrependUploadValidatorIsEnabled - testUploadValidatorIsNotAddedByDefaultDuringIsValidWhenAutoPrependUploadValidatorIsDisabled - testValidationOperatesBeforeFiltering - testValidationOperatesOnFilteredValue - [$upload, 'reveal'] $input - - $this->createFilterChainMock([[$badValue->reveal(), $filteredValue]]) - $this->createFilterChainMock([[$value->reveal(), $filteredValue]]) - $this->createValidatorChainMock([[$badValue->reveal(), null, false]]) - new FileInput('foo') @@ -826,18 +596,6 @@ function () { - - testAllowsPassingNonPluginManagerContainerToFactoryWithServiceManagerV2 - testCanCreateServiceIfConfigInputFiltersContainsMatchingServiceName - testCannotCreateServiceIfConfigInputFiltersDoesNotContainMatchingServiceName - testCannotCreateServiceIfConfigServiceDoesNotHaveInputFiltersConfiguration - testCannotCreateServiceIfNoConfigServicePresent - testCreatesInputFilterInstance - testInjectsInputFilterManagerFromServiceManager - testRetrieveInputFilterFromInputFilterPluginManager - testUsesConfiguredValidationAndFilterManagerServicesWhenCreatingInputFilter - testWillUseCustomFiltersWhenProvided - $filterChain $filterChain @@ -870,10 +628,6 @@ InputFilterAwareTrait::class InputFilterAwareTrait::class - - testGetInputFilter - testSetInputFilter - getInputFilter getInputFilter @@ -891,14 +645,6 @@ function () use ($inputFilter) { - - testConfiguresInputFilterServicesWhenFound - testDoesNotConfigureInputFilterServicesWhenConfigServiceDoesNotContainInputFiltersConfig - testDoesNotConfigureInputFilterServicesWhenConfigServiceNotPresent - testDoesNotConfigureInputFilterServicesWhenServiceListenerPresent - testFactoryConfiguresPluginManagerUnderContainerInterop - testFactoryReturnsPluginManager - array<string, array{0: class-string<InputInterface>}> @@ -909,18 +655,6 @@ $this->getServiceNotFoundException() - - testDefaultInvokableClasses - testGet - testInputFilterInvokableClassSMDependenciesArePopulatedWithServiceLocator - testInputFilterInvokableClassSMDependenciesArePopulatedWithoutServiceLocator - testIsASubclassOfAbstractPluginManager - testIsNotSharedByDefault - testLoadingInvalidElementRaisesException - testPopulateFactoryCanAcceptInputFilterAsFirstArgumentAndWillUseFactoryWhenItDoes - testRegisteringInvalidElementRaisesException - testServicesAreInitiatedIfImplementsInitializableInterface - getPluginManager @@ -931,19 +665,10 @@ - - setData - setData - $dataSets - - testCanComposeAFactory - testLazilyComposesAFactoryByDefault - testNestedInputFilterShouldAllowNullValueForData - $filter1->getValues()['nested']['nestedField1'] $filter1->getValues()['nested']['nestedField1'] @@ -957,10 +682,8 @@ - - $dataSets - - + + array_merge($emptyValues, $mixedValues) @@ -977,59 +700,15 @@ function ($value, $context = null) { function ($value, $context = null) { - - testAllowEmptyFlagIsMutable - testBreakOnFailureFlagIsMutable - testBreakOnFailureFlagIsOffByDefault - testCanInjectFilterChain - testCanInjectValidatorChain - testCanRetrieveRawValue - testClearFallbackValue - testConstructorRequiresAName - testContinueIfEmptyFlagIsFalseByDefault - testContinueIfEmptyFlagIsMutable - testDefaultGetValue - testDoNotInjectNotEmptyValidatorIfAnywhereInChain - testFallbackValueVsIsValidRules - testFallbackValueVsIsValidRulesWhenValueNotSet - testInputDoesNotAllowEmptyValuesByDefault - testInputHasEmptyFilterChainByDefault - testInputHasEmptyValidatorChainByDefault - testInputIsMarkedAsRequiredByDefault - testInputMergeWithSourceValue - testInputMergeWithTargetValue - testInputMergeWithoutValues - testIsRequiredVsAllowEmptyVsContinueIfEmptyVsIsValid - testMerge - testNotEmptyMessageIsTranslated - testNotEmptyValidatorAddedWhenIsValidIsCalled - testNotEmptyValidatorNotInjectedIfContinueIfEmptyIsTrue - testNotRequiredWithoutFallbackAndValueNotSetThenIsValid - testRequiredFlagIsMutable - testRequiredNotEmptyValidatorNotAddedWhenOneExists - testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage - testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMessageWhenSet - testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage - testRequiredWithoutFallbackAndValueNotSetThenFail - testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomErrorMessageWhenSet - testResetValueReturnsInputValueToDefaultValue - testRetrievingValueFiltersTheValue - testSetFallbackValue - testSetValuePutInputInTheDesiredState - testValidationOperatesOnFilteredValue - testValueMayBeInjected - $value['filtered'] $value['raw'] - - $isValidMethod - $isValidMethod + $tmpTemplate[4] $value - + method method method @@ -1050,8 +729,6 @@ willReturn willReturn willReturn - willReturnMap - willReturnMap with with with @@ -1059,26 +736,10 @@ with - - $chain - $chain - $filterChain - $filterChain - $filterChain - $filterChain - $notEmptyMock - $notEmptyMock - $source - $targetFilterChain - $targetValidatorChain - $this->createValidatorChainMock() - $this->createValidatorChainMock([[$originalValue, null, $isValid]]) - $this->createValidatorMock(null, null) - $this->createValidatorMock(true) + $translator - $validatorChain - + expects expects expects @@ -1087,18 +748,6 @@ expects expects expects - getFilterChain - getValidatorChain - method - method - method - method - method - method - method - method - method - method isArray @@ -1108,13 +757,6 @@ $moduleManager->reveal() - - testGetConfigMethodShouldReturnExpectedKeys - testInitMethodShouldRegisterPluginManagerSpecificationWithServiceListener - testInputFilterConfigShouldContainAbstractServiceFactory - testServiceManagerConfigShouldContainAliasForInputFilterManager - testServiceManagerConfigShouldContainInputFilterManager - $config['input_filters']['abstract_factories'] $config['service_manager']['aliases'] @@ -1127,24 +769,6 @@ - - setData - setData - setData - setData - setData - setData - - - assertGetValuesThrows - testIteratorBehavesTheSameAsArray - testStateIsClearedBetweenValidationAttempts - testValidatesSuccessfullyWhenEmptyDataSetProvided - testValidatesSuccessfullyWhenNoDataProvided - testValidatesSuccessfullyWhenSetDataIsNeverCalled - testValidatesSuccessfullyWhenValidNonEmptyDataSetProvided - testValidationFailureWhenInvalidDataSetIsProvided - setData setData @@ -1168,14 +792,4 @@ $name - - - getEvent - - - - - addServiceManager - - diff --git a/src/Input.php b/src/Input.php index 4158d913..6b208cdc 100644 --- a/src/Input.php +++ b/src/Input.php @@ -333,6 +333,7 @@ public function hasFallback() return $this->hasFallback; } + /** @return void */ public function clearFallbackValue() { $this->hasFallback = false; diff --git a/test/ArrayInputTest.php b/test/ArrayInputTest.php index 1a288418..46aa82b0 100644 --- a/test/ArrayInputTest.php +++ b/test/ArrayInputTest.php @@ -2,8 +2,12 @@ namespace LaminasTest\InputFilter; +use Laminas\Filter\FilterChain; use Laminas\InputFilter\ArrayInput; use Laminas\InputFilter\Exception\InvalidArgumentException; +use Laminas\Validator\NotEmpty; +use Laminas\Validator\ValidatorChain; +use PHPUnit\Framework\MockObject\MockObject; use Webmozart\Assert\Assert; use function array_map; @@ -118,7 +122,7 @@ public function mixedValueProvider(): array } /** - * @param array $valueMap + * @param list> $valueMap * @return FilterChain&MockObject */ protected function createFilterChainMock(array $valueMap = []) @@ -141,7 +145,7 @@ function ($values) { } /** - * @param array $valueMap + * @param list> $valueMap * @param string[] $messages * @return ValidatorChain&MockObject */ @@ -165,7 +169,7 @@ function ($values) { * @param bool $isValid * @param mixed $value * @param mixed $context - * @return NotEmptyValidator&MockObject + * @return NotEmpty&MockObject */ protected function createNonEmptyValidatorMock($isValid, $value, $context = null) { diff --git a/test/BaseInputFilterTest.php b/test/BaseInputFilterTest.php index 1b3ee3d2..9d91e23b 100644 --- a/test/BaseInputFilterTest.php +++ b/test/BaseInputFilterTest.php @@ -217,7 +217,7 @@ public function testAddHasGet( ?string $name, ?string $expectedInputName, object $expectedInput - ) { + ): void { $inputFilter = $this->inputFilter; $this->assertFalse( $inputFilter->has($expectedInputName), @@ -301,7 +301,7 @@ public function testSetDataAndGetRawValueGetValue( array $expectedInvalidInputs, array $expectedValidInputs, array $expectedMessages - ) { + ): void { $inputFilter = $this->inputFilter; foreach ($inputs as $inputName => $input) { $inputFilter->add($input, $inputName); @@ -353,7 +353,7 @@ public function testSetTraversableDataAndGetRawValueGetValue( array $expectedInvalidInputs, array $expectedValidInputs, array $expectedMessages - ) { + ): void { $dataTypes = $this->dataTypes(); $this->testSetDataAndGetRawValueGetValue( $inputs, diff --git a/test/CollectionInputFilterTest.php b/test/CollectionInputFilterTest.php index cc736b36..d03d5eab 100644 --- a/test/CollectionInputFilterTest.php +++ b/test/CollectionInputFilterTest.php @@ -54,14 +54,14 @@ public function testSetInputFilterWithInvalidTypeThrowsInvalidArgumentException( * @dataProvider inputFilterProvider * @param array|Traversable|InputFilterInterface $inputFilter */ - public function testSetInputFilter($inputFilter, string $expectedType) + public function testSetInputFilter($inputFilter, string $expectedType): void { $this->inputFilter->setInputFilter($inputFilter); $this->assertInstanceOf($expectedType, $this->inputFilter->getInputFilter(), 'getInputFilter() type not match'); } - public function testGetDefaultInputFilter() + public function testGetDefaultInputFilter(): void { $this->assertInstanceOf(BaseInputFilter::class, $this->inputFilter->getInputFilter()); } @@ -69,7 +69,7 @@ public function testGetDefaultInputFilter() /** * @dataProvider isRequiredProvider */ - public function testSetRequired(bool $value) + public function testSetRequired(bool $value): void { $this->inputFilter->setIsRequired($value); $this->assertEquals($value, $this->inputFilter->getIsRequired()); @@ -78,7 +78,7 @@ public function testSetRequired(bool $value) /** * @dataProvider countVsDataProvider */ - public function testSetCount(?int $count, ?array $data, int $expectedCount) + public function testSetCount(?int $count, ?array $data, int $expectedCount): void { if ($count !== null) { $this->inputFilter->setCount($count); @@ -93,7 +93,7 @@ public function testSetCount(?int $count, ?array $data, int $expectedCount) /** * @group 6160 */ - public function testGetCountReturnsRightCountOnConsecutiveCallsWithDifferentData() + public function testGetCountReturnsRightCountOnConsecutiveCallsWithDifferentData(): void { $collectionData1 = [ ['foo' => 'bar'], @@ -122,7 +122,7 @@ public function testDataVsValid( array $expectedValues, bool $expectedValid, array $expectedMessages - ) { + ): void { $this->inputFilter->setInputFilter($inputFilter); $this->inputFilter->setData($data); if ($count !== null) { @@ -205,7 +205,7 @@ function (&$set) { return $dataSets; } - public function testSetValidationGroupUsingFormStyle() + public function testSetValidationGroupUsingFormStyle(): void { $validationGroup = [ 'fooGroup', @@ -268,7 +268,7 @@ public function dataNestingCollection(): array /** * @dataProvider dataNestingCollection */ - public function testNestingCollectionCountCached(?int $count, bool $expectedIsValid) + public function testNestingCollectionCountCached(?int $count, bool $expectedIsValid): void { $firstInputFilter = new InputFilter(); @@ -414,14 +414,14 @@ protected function createBaseInputFilterMock( return $inputFilter; } - public function testGetUnknownWhenDataAreNotProvidedThrowsRuntimeException() + public function testGetUnknownWhenDataAreNotProvidedThrowsRuntimeException(): void { $this->expectException(RuntimeException::class); $this->inputFilter->getUnknown(); } - public function testGetUnknownWhenAllFieldsAreKnownReturnsAnEmptyArray() + public function testGetUnknownWhenAllFieldsAreKnownReturnsAnEmptyArray(): void { $inputFilter = new InputFilter(); $inputFilter->add([ @@ -442,7 +442,7 @@ public function testGetUnknownWhenAllFieldsAreKnownReturnsAnEmptyArray() $this->assertCount(0, $unknown); } - public function testGetUnknownFieldIsUnknown() + public function testGetUnknownFieldIsUnknown(): void { $inputFilter = new InputFilter(); $inputFilter->add([ @@ -482,7 +482,7 @@ public function invalidCollections(): array /** * @dataProvider invalidCollections */ - public function testSettingDataAsArrayWithInvalidCollectionsRaisesException(array $data) + public function testSettingDataAsArrayWithInvalidCollectionsRaisesException(array $data): void { $collectionInputFilter = $this->inputFilter; @@ -494,7 +494,7 @@ public function testSettingDataAsArrayWithInvalidCollectionsRaisesException(arra /** * @dataProvider invalidCollections */ - public function testSettingDataAsTraversableWithInvalidCollectionsRaisesException(array $data) + public function testSettingDataAsTraversableWithInvalidCollectionsRaisesException(array $data): void { $collectionInputFilter = $this->inputFilter; $data = new ArrayIterator($data); @@ -524,7 +524,7 @@ public function invalidDataType(): array * @dataProvider invalidDataType * @param mixed $data */ - public function testSettingDataWithNonArrayNonTraversableRaisesException($data) + public function testSettingDataWithNonArrayNonTraversableRaisesException($data): void { $collectionInputFilter = $this->inputFilter; @@ -533,7 +533,7 @@ public function testSettingDataWithNonArrayNonTraversableRaisesException($data) $collectionInputFilter->setData($data); } - public function testCollectionValidationDoesNotReuseMessagesBetweenInputs() + public function testCollectionValidationDoesNotReuseMessagesBetweenInputs(): void { $inputFilter = new InputFilter(); $inputFilter->add([ @@ -583,7 +583,7 @@ public function testCollectionValidationDoesNotReuseMessagesBetweenInputs() // @codingStandardsIgnoreEnd } - public function testCollectionValidationUsesCustomInputErrorMessages() + public function testCollectionValidationUsesCustomInputErrorMessages(): void { $inputFilter = new InputFilter(); $inputFilter->add([ @@ -632,7 +632,7 @@ public function testCollectionValidationUsesCustomInputErrorMessages() $this->assertContains('CUSTOM ERROR MESSAGE', $messages[1]['phone']); } - public function testDuplicatedErrorMessages() + public function testDuplicatedErrorMessages(): void { $factory = new Factory(); $inputFilter = $factory->createInputFilter( @@ -760,19 +760,19 @@ public function testDuplicatedErrorMessages() ], $inputFilter->getMessages()); } - public function testLazyLoadsANotEmptyValidatorWhenNoneProvided() + public function testLazyLoadsANotEmptyValidatorWhenNoneProvided(): void { $this->assertInstanceOf(NotEmpty::class, $this->inputFilter->getNotEmptyValidator()); } - public function testAllowsComposingANotEmptyValidator() + public function testAllowsComposingANotEmptyValidator(): void { $notEmptyValidator = new NotEmpty(); $this->inputFilter->setNotEmptyValidator($notEmptyValidator); $this->assertSame($notEmptyValidator, $this->inputFilter->getNotEmptyValidator()); } - public function testUsesMessageFromComposedNotEmptyValidatorWhenRequiredButCollectionIsEmpty() + public function testUsesMessageFromComposedNotEmptyValidatorWhenRequiredButCollectionIsEmpty(): void { $message = 'this is the validation message'; $notEmptyValidator = new NotEmpty(); @@ -790,7 +790,7 @@ public function testUsesMessageFromComposedNotEmptyValidatorWhenRequiredButColle ], $this->inputFilter->getMessages()); } - public function testSetDataUsingSetDataAndRunningIsValidReturningSameAsOriginalForUnfilteredData() + public function testSetDataUsingSetDataAndRunningIsValidReturningSameAsOriginalForUnfilteredData(): void { $filteredArray = [ [ diff --git a/test/FileInput/PsrFileInputDecoratorTest.php b/test/FileInput/PsrFileInputDecoratorTest.php index 1057d620..d3d3e012 100644 --- a/test/FileInput/PsrFileInputDecoratorTest.php +++ b/test/FileInput/PsrFileInputDecoratorTest.php @@ -230,7 +230,7 @@ public function testFallbackValueVsIsValidRules( $originalValue = null, ?bool $isValid = null, $expectedValue = null - ) { + ): void { $this->markTestSkipped('Input::setFallbackValue is not implemented on PsrFileInput'); } diff --git a/test/InputFilterPluginManagerTest.php b/test/InputFilterPluginManagerTest.php index 194e6af9..7a086b01 100644 --- a/test/InputFilterPluginManagerTest.php +++ b/test/InputFilterPluginManagerTest.php @@ -181,7 +181,7 @@ public function testServicesAreInitiatedIfImplementsInitializableInterface( string $serviceName, object $service, string $instanceOf - ) { + ): void { $initializableProphecy = $this->prophesize($instanceOf)->willImplement(InitializableInterface::class); $service = $initializableProphecy->reveal(); @@ -201,33 +201,33 @@ public function testPopulateFactoryCanAcceptInputFilterAsFirstArgumentAndWillUse } /** - * @return MockObject|InputFilterInterface + * @return MockObject&InputFilterInterface */ protected function createInputFilterInterfaceMock() { - /** @var InputFilterInterface|MockObject $inputFilter */ + /** @var InputFilterInterface&MockObject $inputFilter */ $inputFilter = $this->createMock(InputFilterInterface::class); return $inputFilter; } /** - * @return MockObject|InputInterface + * @return MockObject&InputInterface */ protected function createInputInterfaceMock() { - /** @var InputInterface|MockObject $input */ + /** @var InputInterface&MockObject $input */ $input = $this->createMock(InputInterface::class); return $input; } /** - * @return MockObject|ServiceLocatorInterface + * @return MockObject&ServiceLocatorInterface */ protected function createServiceLocatorInterfaceMock() { - /** @var ServiceLocatorInterface|MockObject $serviceLocator */ + /** @var ServiceLocatorInterface&MockObject $serviceLocator */ $serviceLocator = $this->createMock(ServiceLocatorInterface::class); return $serviceLocator; diff --git a/test/InputTest.php b/test/InputTest.php index 3bd5472a..1bcb8d8d 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -176,7 +176,7 @@ public function testFallbackValueVsIsValidRules( $originalValue, bool $isValid, $expectedValue - ) { + ): void { $input = $this->input; $input->setContinueIfEmpty(true); @@ -495,7 +495,7 @@ public function testIsRequiredVsAllowEmptyVsContinueIfEmptyVsIsValid( $value, bool $expectedIsValid, array $expectedMessages - ) { + ): void { $this->input->setRequired($required); $this->input->setAllowEmpty($allowEmpty); $this->input->setContinueIfEmpty($continueIfEmpty); @@ -896,23 +896,23 @@ public function mixedValueProvider(): array } /** - * @return InputInterface|MockObject + * @return InputInterface&MockObject */ protected function createInputInterfaceMock() { - /** @var InputInterface|MockObject $source */ + /** @var InputInterface&MockObject $source */ $source = $this->createMock(InputInterface::class); return $source; } /** - * @param array $valueMap - * @return FilterChain|MockObject + * @param list> $valueMap + * @return FilterChain&MockObject */ protected function createFilterChainMock(array $valueMap = []) { - /** @var FilterChain|MockObject $filterChain */ + /** @var FilterChain&MockObject $filterChain */ $filterChain = $this->createMock(FilterChain::class); $filterChain->method('filter') @@ -922,13 +922,13 @@ protected function createFilterChainMock(array $valueMap = []) } /** - * @param array $valueMap + * @param list> $valueMap * @param string[] $messages - * @return ValidatorChain|MockObject + * @return ValidatorChain&MockObject */ protected function createValidatorChainMock(array $valueMap = [], $messages = []) { - /** @var ValidatorChain|MockObject $validatorChain */ + /** @var ValidatorChain&MockObject $validatorChain */ $validatorChain = $this->createMock(ValidatorChain::class); if (empty($valueMap)) { @@ -951,11 +951,11 @@ protected function createValidatorChainMock(array $valueMap = [], $messages = [] * @param mixed $value * @param mixed $context * @param string[] $messages - * @return ValidatorInterface|MockObject + * @return ValidatorInterface&MockObject */ protected function createValidatorMock($isValid, $value = 'not-set', $context = null, $messages = []) { - /** @var ValidatorInterface|MockObject $validator */ + /** @var ValidatorInterface&MockObject $validator */ $validator = $this->createMock(ValidatorInterface::class); if (($isValid === false) || ($isValid === true)) { @@ -980,11 +980,11 @@ protected function createValidatorMock($isValid, $value = 'not-set', $context = * @param bool $isValid * @param mixed $value * @param mixed $context - * @return NotEmptyValidator|MockObject + * @return NotEmptyValidator&MockObject */ protected function createNonEmptyValidatorMock($isValid, $value, $context = null) { - /** @var NotEmptyValidator|MockObject $notEmptyMock */ + /** @var NotEmptyValidator&MockObject $notEmptyMock */ $notEmptyMock = $this->getMockBuilder(NotEmptyValidator::class) ->setMethods(['isValid']) ->getMock(); diff --git a/test/OptionalInputFilterTest.php b/test/OptionalInputFilterTest.php index 42a85edf..3df0d060 100644 --- a/test/OptionalInputFilterTest.php +++ b/test/OptionalInputFilterTest.php @@ -105,7 +105,7 @@ public function testIteratorBehavesTheSameAsArray(): void $this->assertTrue($optionalInputFilter->isValid()); } - protected function assertGetValuesThrows(InputFilterInterface $inputFilter) + protected function assertGetValuesThrows(InputFilterInterface $inputFilter): void { try { $inputFilter->getValues(); diff --git a/test/TestAsset/ModuleManagerInterface.php b/test/TestAsset/ModuleManagerInterface.php index 62dfd9b9..94fa7b40 100644 --- a/test/TestAsset/ModuleManagerInterface.php +++ b/test/TestAsset/ModuleManagerInterface.php @@ -4,5 +4,5 @@ interface ModuleManagerInterface { - public function getEvent(); + public function getEvent(): ModuleEventInterface; } diff --git a/test/TestAsset/ServiceListenerInterface.php b/test/TestAsset/ServiceListenerInterface.php index db06873e..f4587414 100644 --- a/test/TestAsset/ServiceListenerInterface.php +++ b/test/TestAsset/ServiceListenerInterface.php @@ -3,7 +3,7 @@ namespace LaminasTest\InputFilter\TestAsset; /** - * Stub interfact to mock when testing Module::init. + * Stub interface to mock when testing Module::init. * * Mimics method that will be called on ServiceListener. */ @@ -20,5 +20,5 @@ public function addServiceManager( $configKey, $interface, $method - ); + ): void; } From 5108ec3bdf4414b3ef44f7069df06c70589d71d5 Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 21:58:30 +0100 Subject: [PATCH 07/20] Remove irrelevant group annotations Signed-off-by: George Steel --- test/BaseInputFilterTest.php | 6 ------ test/CollectionInputFilterTest.php | 3 --- test/InputFilterAbstractServiceFactoryTest.php | 3 --- test/InputTest.php | 12 ------------ 4 files changed, 24 deletions(-) diff --git a/test/BaseInputFilterTest.php b/test/BaseInputFilterTest.php index 9d91e23b..3f5c4a7e 100644 --- a/test/BaseInputFilterTest.php +++ b/test/BaseInputFilterTest.php @@ -561,9 +561,6 @@ public function testGetInputs(): void $this->assertEquals('bar', $filters['bar']->getName()); } - /** - * @group 4996 - */ public function testAddingExistingInputWillMergeIntoExisting(): void { $filter = $this->inputFilter; @@ -579,9 +576,6 @@ public function testAddingExistingInputWillMergeIntoExisting(): void $this->assertFalse($filter->get('foo')->isRequired()); } - /** - * @group 6431 - */ public function testMerge(): void { $inputFilter = $this->inputFilter; diff --git a/test/CollectionInputFilterTest.php b/test/CollectionInputFilterTest.php index d03d5eab..758ed388 100644 --- a/test/CollectionInputFilterTest.php +++ b/test/CollectionInputFilterTest.php @@ -90,9 +90,6 @@ public function testSetCount(?int $count, ?array $data, int $expectedCount): voi $this->assertEquals($expectedCount, $this->inputFilter->getCount(), 'getCount() value not match'); } - /** - * @group 6160 - */ public function testGetCountReturnsRightCountOnConsecutiveCallsWithDifferentData(): void { $collectionData1 = [ diff --git a/test/InputFilterAbstractServiceFactoryTest.php b/test/InputFilterAbstractServiceFactoryTest.php index dab94502..fd4ea9c9 100644 --- a/test/InputFilterAbstractServiceFactoryTest.php +++ b/test/InputFilterAbstractServiceFactoryTest.php @@ -205,9 +205,6 @@ public function testInjectsInputFilterManagerFromServiceManager(): void $this->assertInstanceOf(Foo::class, $inputFilterManager->get('foo')); } - /** - * @group zendframework/zend-servicemanager#123 - */ public function testAllowsPassingNonPluginManagerContainerToFactoryWithServiceManagerV2(): void { $this->services->setService('config', [ diff --git a/test/InputTest.php b/test/InputTest.php index 1bcb8d8d..ea834fbb 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -245,10 +245,6 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomEr $this->assertSame(['FAILED TO VALIDATE'], $input->getMessages()); } - /** - * @group 28 - * @group 60 - */ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage(): void { $input = $this->input; @@ -262,10 +258,6 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat $this->assertRequiredValidationErrorMessage($input); } - /** - * @group 28 - * @group 69 - */ public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage(): void // phpcs:ignore { $input = new Input(); @@ -295,10 +287,6 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmpt $this->assertEquals($customMessage, $input->getMessages()); } - /** - * @group 28 - * @group 60 - */ public function testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMessageWhenSet(): void { $input = $this->input; From dfd586d08972f86700dd10a88677a38451ccdf74 Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 22:40:10 +0100 Subject: [PATCH 08/20] Update all locked dependencies Signed-off-by: George Steel --- composer.lock | 283 +++++++++++++++++++++++--------------------------- 1 file changed, 131 insertions(+), 152 deletions(-) diff --git a/composer.lock b/composer.lock index c8fc8cc8..b9cd6de9 100644 --- a/composer.lock +++ b/composer.lock @@ -6,54 +6,18 @@ ], "content-hash": "53f38233dacf2b64b07daad58d574517", "packages": [ - { - "name": "container-interop/container-interop", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/container-interop/container-interop.git", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "shasum": "" - }, - "require": { - "psr/container": "^1.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Interop\\Container\\": "src/Interop/Container/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", - "homepage": "https://github.com/container-interop/container-interop", - "support": { - "issues": "https://github.com/container-interop/container-interop/issues", - "source": "https://github.com/container-interop/container-interop/tree/master" - }, - "abandoned": "psr/container", - "time": "2017-02-14T19:40:03+00:00" - }, { "name": "laminas/laminas-filter", - "version": "2.13.0", + "version": "2.14.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-filter.git", - "reference": "67d88c471cb7016f495aeb1d3fd03edaa9bd9e70" + "reference": "98a126b8cd069a446054680c9be5f37a61f6dc17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-filter/zipball/67d88c471cb7016f495aeb1d3fd03edaa9bd9e70", - "reference": "67d88c471cb7016f495aeb1d3fd03edaa9bd9e70", + "url": "https://api.github.com/repos/laminas/laminas-filter/zipball/98a126b8cd069a446054680c9be5f37a61f6dc17", + "reference": "98a126b8cd069a446054680c9be5f37a61f6dc17", "shasum": "" }, "require": { @@ -119,41 +83,43 @@ "type": "community_bridge" } ], - "time": "2021-12-02T14:12:59+00:00" + "time": "2022-02-22T23:09:15+00:00" }, { "name": "laminas/laminas-servicemanager", - "version": "3.10.0", + "version": "3.11.2", "source": { "type": "git", "url": "https://github.com/laminas/laminas-servicemanager.git", - "reference": "e52b985909e0940bf22d34f322eb3f48bbef6bd1" + "reference": "8a1f4d53ec93b2e18174f6f186922ef44d11a75a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/e52b985909e0940bf22d34f322eb3f48bbef6bd1", - "reference": "e52b985909e0940bf22d34f322eb3f48bbef6bd1", + "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/8a1f4d53ec93b2e18174f6f186922ef44d11a75a", + "reference": "8a1f4d53ec93b2e18174f6f186922ef44d11a75a", "shasum": "" }, "require": { - "container-interop/container-interop": "^1.2", "laminas/laminas-stdlib": "^3.2.1", "php": "~7.4.0 || ~8.0.0 || ~8.1.0", "psr/container": "^1.0" }, "conflict": { + "ext-psr": "*", "laminas/laminas-code": "<3.3.1", "zendframework/zend-code": "<3.3.1", "zendframework/zend-servicemanager": "*" }, "provide": { - "container-interop/container-interop-implementation": "^1.2", "psr/container-implementation": "^1.0" }, + "replace": { + "container-interop/container-interop": "^1.2.0" + }, "require-dev": { "composer/package-versions-deprecated": "^1.0", - "laminas/laminas-coding-standard": "~2.2.1", - "laminas/laminas-container-config-test": "^0.3", + "laminas/laminas-coding-standard": "~2.3.0", + "laminas/laminas-container-config-test": "^0.6", "laminas/laminas-dependency-plugin": "^2.1.2", "mikey179/vfsstream": "^1.6.10@alpha", "ocramius/proxy-manager": "^2.11", @@ -172,6 +138,9 @@ ], "type": "library", "autoload": { + "files": [ + "src/autoload.php" + ], "psr-4": { "Laminas\\ServiceManager\\": "src/" } @@ -205,7 +174,7 @@ "type": "community_bridge" } ], - "time": "2021-09-18T20:19:36+00:00" + "time": "2022-04-07T17:21:25+00:00" }, { "name": "laminas/laminas-stdlib", @@ -268,16 +237,16 @@ }, { "name": "laminas/laminas-validator", - "version": "2.18.0", + "version": "2.19.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-validator.git", - "reference": "dd9d10602048c561730d8bdb0ae589cd8ba11a82" + "reference": "4875d4e58b6f728981bb767a60530540f82ee1df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/dd9d10602048c561730d8bdb0ae589cd8ba11a82", - "reference": "dd9d10602048c561730d8bdb0ae589cd8ba11a82", + "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/4875d4e58b6f728981bb767a60530540f82ee1df", + "reference": "4875d4e58b6f728981bb767a60530540f82ee1df", "shasum": "" }, "require": { @@ -354,7 +323,7 @@ "type": "community_bridge" } ], - "time": "2022-06-09T11:13:14+00:00" + "time": "2022-06-09T21:49:40+00:00" }, { "name": "psr/container", @@ -865,27 +834,27 @@ }, { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.7.1", + "version": "v0.7.2", "source": { "type": "git", "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", - "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", "shasum": "" }, "require": { "composer-plugin-api": "^1.0 || ^2.0", "php": ">=5.3", - "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" }, "require-dev": { "composer/composer": "*", - "phpcompatibility/php-compatibility": "^9.0", - "sensiolabs/security-checker": "^4.1.0" + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0" }, "type": "composer-plugin", "extra": { @@ -906,6 +875,10 @@ "email": "franck.nijhof@dealerdirect.com", "homepage": "http://www.frenck.nl", "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", @@ -917,6 +890,7 @@ "codesniffer", "composer", "installer", + "phpcbf", "phpcs", "plugin", "qa", @@ -931,7 +905,7 @@ "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" }, - "time": "2020-12-07T18:04:37+00:00" + "time": "2022-02-04T12:51:07+00:00" }, { "name": "dnoegel/php-xdg-base-dir", @@ -972,29 +946,30 @@ }, { "name": "doctrine/instantiator", - "version": "1.4.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b" + "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b", - "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", + "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^8.0", + "doctrine/coding-standard": "^9", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.13 || 1.0.0-alpha2", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpbench/phpbench": "^0.16 || ^1", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.22" }, "type": "library", "autoload": { @@ -1021,7 +996,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + "source": "https://github.com/doctrine/instantiator/tree/1.4.1" }, "funding": [ { @@ -1037,7 +1012,7 @@ "type": "tidelift" } ], - "time": "2020-11-10T18:47:58+00:00" + "time": "2022-03-03T08:28:38+00:00" }, { "name": "felixfbecker/advanced-json-rpc", @@ -1195,20 +1170,20 @@ }, { "name": "laminas/laminas-db", - "version": "2.13.4", + "version": "2.15.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-db.git", - "reference": "cdabb4bfa669c2c0edb0cb4e014c15b41afd3fb1" + "reference": "1125ef2e55108bdfcc1f0030d3a0f9b895e09606" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-db/zipball/cdabb4bfa669c2c0edb0cb4e014c15b41afd3fb1", - "reference": "cdabb4bfa669c2c0edb0cb4e014c15b41afd3fb1", + "url": "https://api.github.com/repos/laminas/laminas-db/zipball/1125ef2e55108bdfcc1f0030d3a0f9b895e09606", + "reference": "1125ef2e55108bdfcc1f0030d3a0f9b895e09606", "shasum": "" }, "require": { - "laminas/laminas-stdlib": "^3.6", + "laminas/laminas-stdlib": "^3.7.1", "php": "^7.3 || ~8.0.0 || ~8.1.0" }, "conflict": { @@ -1216,10 +1191,10 @@ }, "require-dev": { "laminas/laminas-coding-standard": "~2.2.1", - "laminas/laminas-eventmanager": "^3.4", + "laminas/laminas-eventmanager": "^3.4.0", "laminas/laminas-hydrator": "^3.2 || ^4.3", - "laminas/laminas-servicemanager": "^3.7", - "phpunit/phpunit": "^9.5.5" + "laminas/laminas-servicemanager": "^3.7.0", + "phpunit/phpunit": "^9.5.19" }, "suggest": { "laminas/laminas-eventmanager": "Laminas\\EventManager component", @@ -1262,29 +1237,33 @@ "type": "community_bridge" } ], - "time": "2021-09-21T18:59:44+00:00" + "time": "2022-04-11T13:26:20+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.10.2", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220" + "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220", - "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", + "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" + }, "require-dev": { - "doctrine/collections": "^1.0", - "doctrine/common": "^2.6", - "phpunit/phpunit": "^7.1" + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, "type": "library", "autoload": { @@ -1309,7 +1288,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0" }, "funding": [ { @@ -1317,7 +1296,7 @@ "type": "tidelift" } ], - "time": "2020-11-13T09:40:50+00:00" + "time": "2022-03-03T13:19:32+00:00" }, { "name": "netresearch/jsonmapper", @@ -1541,16 +1520,16 @@ }, { "name": "phar-io/version", - "version": "3.1.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "bae7c545bef187884426f042434e561ab1ddb182" + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182", - "reference": "bae7c545bef187884426f042434e561ab1ddb182", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", "shasum": "" }, "require": { @@ -1586,9 +1565,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/3.1.0" + "source": "https://github.com/phar-io/version/tree/3.2.1" }, - "time": "2021-02-23T14:00:09+00:00" + "time": "2022-02-21T01:04:05+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -1752,16 +1731,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.14.0", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e" + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e", - "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", "shasum": "" }, "require": { @@ -1813,9 +1792,9 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.14.0" + "source": "https://github.com/phpspec/prophecy/tree/v1.15.0" }, - "time": "2021-09-10T09:02:12+00:00" + "time": "2021-12-08T12:19:24+00:00" }, { "name": "phpspec/prophecy-phpunit", @@ -1924,16 +1903,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.9", + "version": "9.2.15", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f301eb1453c9e7a1bc912ee8b0ea9db22c60223b" + "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f301eb1453c9e7a1bc912ee8b0ea9db22c60223b", - "reference": "f301eb1453c9e7a1bc912ee8b0ea9db22c60223b", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2e9da11878c4202f97915c1cb4bb1ca318a63f5f", + "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f", "shasum": "" }, "require": { @@ -1989,7 +1968,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.9" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.15" }, "funding": [ { @@ -1997,7 +1976,7 @@ "type": "github" } ], - "time": "2021-11-19T15:21:02+00:00" + "time": "2022-03-07T09:28:20+00:00" }, { "name": "phpunit/php-file-iterator", @@ -2242,16 +2221,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.10", + "version": "9.5.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a" + "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c814a05837f2edb0d1471d6e3f4ab3501ca3899a", - "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba", + "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba", "shasum": "" }, "require": { @@ -2267,7 +2246,7 @@ "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2.7", + "phpunit/php-code-coverage": "^9.2.13", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -2281,7 +2260,7 @@ "sebastian/global-state": "^5.0.1", "sebastian/object-enumerator": "^4.0.3", "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^2.3.4", + "sebastian/type": "^3.0", "sebastian/version": "^3.0.2" }, "require-dev": { @@ -2329,11 +2308,11 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.10" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20" }, "funding": [ { - "url": "https://phpunit.de/donate.html", + "url": "https://phpunit.de/sponsors.html", "type": "custom" }, { @@ -2341,7 +2320,7 @@ "type": "github" } ], - "time": "2021-09-25T07:38:51+00:00" + "time": "2022-04-01T12:37:26+00:00" }, { "name": "psalm/plugin-phpunit", @@ -2872,16 +2851,16 @@ }, { "name": "sebastian/environment", - "version": "5.1.3", + "version": "5.1.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "388b6ced16caa751030f6a69e588299fa09200ac" + "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/388b6ced16caa751030f6a69e588299fa09200ac", - "reference": "388b6ced16caa751030f6a69e588299fa09200ac", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7", + "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7", "shasum": "" }, "require": { @@ -2923,7 +2902,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.3" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.4" }, "funding": [ { @@ -2931,7 +2910,7 @@ "type": "github" } ], - "time": "2020-09-28T05:52:38+00:00" + "time": "2022-04-03T09:37:03+00:00" }, { "name": "sebastian/exporter", @@ -3012,16 +2991,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.3", + "version": "5.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49" + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23bd5951f7ff26f12d4e3242864df3e08dec4e49", - "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", "shasum": "" }, "require": { @@ -3064,7 +3043,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.3" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" }, "funding": [ { @@ -3072,7 +3051,7 @@ "type": "github" } ], - "time": "2021-06-11T13:31:12+00:00" + "time": "2022-02-14T08:28:10+00:00" }, { "name": "sebastian/lines-of-code", @@ -3363,28 +3342,28 @@ }, { "name": "sebastian/type", - "version": "2.3.4", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914" + "reference": "b233b84bc4465aff7b57cf1c4bc75c86d00d6dad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8cd8a1c753c90bc1a0f5372170e3e489136f914", - "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b233b84bc4465aff7b57cf1c4bc75c86d00d6dad", + "reference": "b233b84bc4465aff7b57cf1c4bc75c86d00d6dad", "shasum": "" }, "require": { "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -3407,7 +3386,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/2.3.4" + "source": "https://github.com/sebastianbergmann/type/tree/3.0.0" }, "funding": [ { @@ -3415,7 +3394,7 @@ "type": "github" } ], - "time": "2021-06-15T12:49:02+00:00" + "time": "2022-03-15T09:54:48+00:00" }, { "name": "sebastian/version", @@ -3533,16 +3512,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.6.1", + "version": "3.6.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "f268ca40d54617c6e06757f83f699775c9b3ff2e" + "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/f268ca40d54617c6e06757f83f699775c9b3ff2e", - "reference": "f268ca40d54617c6e06757f83f699775c9b3ff2e", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", + "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a", "shasum": "" }, "require": { @@ -3585,7 +3564,7 @@ "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2021-10-11T04:00:11+00:00" + "time": "2021-12-12T21:44:58+00:00" }, { "name": "symfony/console", @@ -4573,24 +4552,24 @@ }, { "name": "webimpress/coding-standard", - "version": "1.2.3", + "version": "1.2.4", "source": { "type": "git", "url": "https://github.com/webimpress/coding-standard.git", - "reference": "7a71421c7fc85827488f10c4c510fe80f94d1a74" + "reference": "cd0c4b0b97440c337c1f7da17b524674ca2f9ca9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webimpress/coding-standard/zipball/7a71421c7fc85827488f10c4c510fe80f94d1a74", - "reference": "7a71421c7fc85827488f10c4c510fe80f94d1a74", + "url": "https://api.github.com/repos/webimpress/coding-standard/zipball/cd0c4b0b97440c337c1f7da17b524674ca2f9ca9", + "reference": "cd0c4b0b97440c337c1f7da17b524674ca2f9ca9", "shasum": "" }, "require": { "php": "^7.3 || ^8.0", - "squizlabs/php_codesniffer": "^3.6.1" + "squizlabs/php_codesniffer": "^3.6.2" }, "require-dev": { - "phpunit/phpunit": "^9.5.10" + "phpunit/phpunit": "^9.5.13" }, "type": "phpcodesniffer-standard", "extra": { @@ -4616,7 +4595,7 @@ ], "support": { "issues": "https://github.com/webimpress/coding-standard/issues", - "source": "https://github.com/webimpress/coding-standard/tree/1.2.3" + "source": "https://github.com/webimpress/coding-standard/tree/1.2.4" }, "funding": [ { @@ -4624,7 +4603,7 @@ "type": "github" } ], - "time": "2021-10-28T21:18:17+00:00" + "time": "2022-02-15T19:52:12+00:00" }, { "name": "webmozart/assert", From 2549b15b4203f674332fa41cff6b243bd420fb4b Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 22:57:56 +0100 Subject: [PATCH 09/20] CS Fix Signed-off-by: George Steel --- psalm-baseline.xml | 5 ----- test/InputTest.php | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 566b7270..57ed1550 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -695,11 +695,6 @@ $value $value - - function ($value, $context = null) use ($validatorMsg) { - function ($value, $context = null) { - function ($value, $context = null) { - $value['filtered'] $value['raw'] diff --git a/test/InputTest.php b/test/InputTest.php index ea834fbb..a77d23c0 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -732,13 +732,13 @@ public function isRequiredVsAllowEmptyVsContinueIfEmptyVsIsValidProvider(): iter $validatorMsg = ['FooValidator' => 'Invalid Value']; $notEmptyMsg = ['isEmpty' => "Value is required and can't be empty"]; - $validatorNotCall = function ($value, $context = null) { + $validatorNotCall = function ($value, $context = null): ValidatorInterface { return $this->createValidatorMock(null, $value, $context); }; - $validatorInvalid = function ($value, $context = null) use ($validatorMsg) { + $validatorInvalid = function ($value, $context = null) use ($validatorMsg): ValidatorInterface { return $this->createValidatorMock(false, $value, $context, $validatorMsg); }; - $validatorValid = function ($value, $context = null) { + $validatorValid = function ($value, $context = null): ValidatorInterface { return $this->createValidatorMock(true, $value, $context); }; From 7503d5b71999c11afed1d1a74a73c1376dd893df Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 9 Jun 2022 23:01:25 +0100 Subject: [PATCH 10/20] Suppress invalid CS violations Signed-off-by: George Steel --- src/InputFilterAbstractServiceFactory.php | 2 +- src/InputFilterPluginManager.php | 2 +- src/InputFilterPluginManagerFactory.php | 2 +- test/FactoryTest.php | 6 ++---- test/InputFilterPluginManagerFactoryTest.php | 2 +- test/ModuleTest.php | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/InputFilterAbstractServiceFactory.php b/src/InputFilterAbstractServiceFactory.php index ba6408a6..ea110b1c 100644 --- a/src/InputFilterAbstractServiceFactory.php +++ b/src/InputFilterAbstractServiceFactory.php @@ -1,4 +1,4 @@ -assertSame($validatorPlugins, $inputValidatorChain->getPluginManager()); } - // @codingStandardsIgnoreStart - public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjectsWhenCreatingNewInputFilterObjects(): void + public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjectsWhenCreatingNewInputFilterObjects(): void // phpcs:ignore { - // @codingStandardsIgnoreEnd $smMock = $this->createMock(ContainerInterface::class); $factory = $this->createDefaultFactory(); $filterPlugins = new Filter\FilterPluginManager($smMock); diff --git a/test/InputFilterPluginManagerFactoryTest.php b/test/InputFilterPluginManagerFactoryTest.php index 70cf3590..0a85b91e 100644 --- a/test/InputFilterPluginManagerFactoryTest.php +++ b/test/InputFilterPluginManagerFactoryTest.php @@ -1,4 +1,4 @@ - Date: Thu, 9 Jun 2022 23:37:26 +0100 Subject: [PATCH 11/20] Reduce `@psalm-var` usage updating baseline Signed-off-by: George Steel --- psalm-baseline.xml | 103 ++++++++++++++++++++++------------ src/BaseInputFilter.php | 17 ++---- src/CollectionInputFilter.php | 6 +- src/Factory.php | 19 +------ src/InputFilter.php | 1 - 5 files changed, 77 insertions(+), 69 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 57ed1550..a4e3f62e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -36,6 +36,12 @@ + + ! is_string($name) + + + $this->inputs + $messages @@ -45,13 +51,27 @@ $input - + + $inputs + $value + + $inputContext $unknownInputs[$key] + $value + + $inputs + $input + + $this->inputs + + + (string) $name + isValid isValid @@ -68,10 +88,15 @@ $this->collectionMessages $this->collectionMessages - - - $name - + + array<array-key, array> + + + $data + + + $data + $name @@ -81,28 +106,55 @@ ! is_array($inputFilterSpecification) && ! $inputFilterSpecification instanceof Traversable ! is_array($inputSpecification) && ! $inputSpecification instanceof Traversable - + + $inputFilter + + + InputFilterInterface + + $breakChainOnFailure $inputFilterSpecification['count'] $inputFilterSpecification['input_filter'] $inputFilterSpecification['required'] $inputFilterSpecification['required_message'] $key + $key + $name $options $priority + $priority + $value $value['type'] - + + $filter['name'] + $filter['options'] + $filter['priority'] + + $breakChainOnFailure $key + $key + $key + $name $options $options $priority + $priority $value new $class() + + $value + $value + + + add + add + @@ -218,6 +270,11 @@ (string) $errorMessage + + + $input + + InputFilterAbstractServiceFactory @@ -316,9 +373,10 @@ - + $input $input + ['nested' => ['nested-input1', 'nested-input2']] new stdClass() new stdClass() @@ -705,29 +763,7 @@ method - method - method - method - method - method - method - method - willReturn - willReturn - willReturn - willReturn willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - with - with - with - with with @@ -736,13 +772,6 @@ expects - expects - expects - expects - expects - expects - expects - expects isArray diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index a64258c9..50bd0b94 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -43,7 +43,7 @@ class BaseInputFilter implements /** @var array|null */ protected $invalidInputs; - /** @var null|list Input names */ + /** @var null|array Input names */ protected $validationGroup; /** @var array|null */ @@ -107,8 +107,6 @@ public function add($input, $name = null) return $this; } - /** @psalm-var string $name */ - $this->inputs[$name] = $input; return $this; } @@ -238,7 +236,7 @@ public function isValid($context = null) /** * Validate a set of inputs against the current data * - * @param list $inputs Array of input names. + * @param array $inputs Array of input names. * @param array $data * @param mixed|null $context * @return bool @@ -306,7 +304,7 @@ protected function validateInputs(array $inputs, array $data = [], $context = nu * Implementations should allow passing a single array value, or multiple arguments, * each specifying a single input. * - * @param string|list|array> $name + * @param string|array $name * @throws Exception\InvalidArgumentException * @return InputFilterInterface */ @@ -342,8 +340,6 @@ public function setValidationGroup($name) $inputs = func_get_args(); } - /** @psalm-var list $inputs */ - if (! empty($inputs)) { $this->validateValidationGroup($inputs); $this->validationGroup = $inputs; @@ -418,7 +414,6 @@ public function getValues() foreach ($inputs as $name) { $input = $this->inputs[$name]; - /** @psalm-var mixed $value */ $value = $input instanceof InputFilterInterface ? $input->getValues() : $input->getValue(); @@ -496,10 +491,9 @@ public function getMessages() /** * Ensure all names of a validation group exist as input in the filter * - * @param array $inputs Input names + * @param array $inputs Input names * @return void * @throws Exception\InvalidArgumentException - * @psalm-assert list $inputs */ protected function validateValidationGroup(array $inputs) { @@ -545,7 +539,7 @@ protected function populate() continue; } - /** @psalm-var mixed $value */ + /** @psalm-suppress MixedAssignment */ $value = $this->data[$name]; if ($input instanceof InputFilterInterface) { @@ -553,7 +547,6 @@ protected function populate() if (! is_array($value) && ! $value instanceof Traversable) { $value = []; } - /** @psalm-var iterable $value */ $input->setData($value); continue; diff --git a/src/CollectionInputFilter.php b/src/CollectionInputFilter.php index 37f2537d..521eb9cb 100644 --- a/src/CollectionInputFilter.php +++ b/src/CollectionInputFilter.php @@ -168,7 +168,7 @@ public function setData($data) $this->setUnfilteredData($data); - /** @psalm-var mixed $item */ + /** @psalm-suppress MixedAssignment */ foreach ($data as $item) { /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ if (is_array($item) || $item instanceof Traversable) { @@ -246,8 +246,9 @@ public function isValid($context = null) return $valid; } - /** @psalm-var array $data */ + /** @psalm-suppress MixedAssignment */ foreach ($this->data as $key => $data) { + /** @psalm-suppress MixedArgument */ $inputFilter->setData($data); if (null !== $this->validationGroup) { @@ -342,7 +343,6 @@ public function getUnknown() $inputFilter = $this->getInputFilter(); $unknownInputs = []; - /** @psalm-var array $data */ foreach ($this->data as $key => $data) { $inputFilter->setData($data); diff --git a/src/Factory.php b/src/Factory.php index d0752acd..1d9cdb98 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -160,11 +160,9 @@ public function createInput($inputSpecification) $inputSpecification = ArrayUtils::iteratorToArray($inputSpecification); } - /** @psalm-var InputSpecification $inputSpecification */ - $class = Input::class; - if (isset($inputSpecification['type'])) { + if (isset($inputSpecification['type']) && is_string($inputSpecification['type'])) { $class = $inputSpecification['type']; } @@ -255,7 +253,6 @@ public function createInput($inputSpecification) is_object($value) ? get_class($value) : gettype($value) )); } - /** @psalm-var iterable $value */ $this->populateFilters($input->getFilterChain(), $value); break; case 'validators': @@ -271,7 +268,7 @@ public function createInput($inputSpecification) is_object($value) ? get_class($value) : gettype($value) )); } - /** @psalm-var iterable $value */ + $this->populateValidators($input->getValidatorChain(), $value); break; default: @@ -317,7 +314,6 @@ public function createInputFilter($inputFilterSpecification) unset($inputFilterSpecification['type']); } - /** @psalm-var InputFilterInterface $inputFilter */ $inputFilter = $this->getInputFilterManager()->get($type); if ($inputFilter instanceof CollectionInputFilter) { @@ -358,7 +354,6 @@ public function createInputFilter($inputFilterSpecification) && (isset($value['name']) && is_string($value['name'])) && $this->getInputFilterManager()->get($value['type']) instanceof InputFilter ) { - /** @psalm-var string $value['name'] */ // If $key is an integer, reset it to the specified name. if (is_int($key)) { $key = $value['name']; @@ -369,11 +364,6 @@ public function createInputFilter($inputFilterSpecification) unset($value['name']); } - /** - * @psalm-var InputSpecification $value - * @psalm-var string $key - */ - $inputFilter->add($this->createInput($value), $key); } @@ -394,10 +384,7 @@ protected function populateFilters(FilterChain $chain, $filters) continue; } - /** - * @psalm-var FilterSpecification $filter - * @psalm-suppress RedundantConditionGivenDocblockType - */ + /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ if (is_array($filter)) { if (! isset($filter['name'])) { throw new Exception\RuntimeException( diff --git a/src/InputFilter.php b/src/InputFilter.php index c9d10860..05ae403f 100644 --- a/src/InputFilter.php +++ b/src/InputFilter.php @@ -58,7 +58,6 @@ public function add($input, $name = null) $input = $factory->createInput($input); } - /** @psalm-var InputInterface|InputFilterInterface $input */ parent::add($input, $name); return $this; From 83d16c8d2f66e1c1ee0f61592c0231644329abca Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 10 Jun 2022 00:10:19 +0100 Subject: [PATCH 12/20] Removing the intersections on the psalm types improves inference Signed-off-by: George Steel --- psalm-baseline.xml | 8 ++------ src/Factory.php | 1 + src/InputFilterInterface.php | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a4e3f62e..4727f717 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -104,7 +104,6 @@ ! is_array($inputFilterSpecification) && ! $inputFilterSpecification instanceof Traversable - ! is_array($inputSpecification) && ! $inputSpecification instanceof Traversable $inputFilter @@ -112,8 +111,7 @@ InputFilterInterface - - $breakChainOnFailure + $inputFilterSpecification['count'] $inputFilterSpecification['input_filter'] $inputFilterSpecification['required'] @@ -121,7 +119,6 @@ $key $key $name - $options $priority $priority $value @@ -132,8 +129,7 @@ $filter['options'] $filter['priority'] - - $breakChainOnFailure + $key $key $key diff --git a/src/Factory.php b/src/Factory.php index 1d9cdb98..023f6f26 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -150,6 +150,7 @@ public function createInput($inputSpecification) } if (! is_array($inputSpecification) && ! $inputSpecification instanceof Traversable) { + /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ throw new Exception\InvalidArgumentException(sprintf( '%s expects an array or Traversable; received "%s"', __METHOD__, diff --git a/src/InputFilterInterface.php b/src/InputFilterInterface.php index efe7ee76..70385cbb 100644 --- a/src/InputFilterInterface.php +++ b/src/InputFilterInterface.php @@ -14,13 +14,13 @@ * name: string|class-string, * priority?: int, * options?: array, - * }&array + * } * @psalm-type ValidatorSpecification = array{ * name: string|class-string, * priority?: int, * break_chain_on_failure?: bool, * options?: array, - * }&array + * } * @psalm-type InputSpecification = array{ * type?: string|class-string, * name?: string, @@ -32,7 +32,7 @@ * break_on_failure?: bool, * filters?: FilterChain|iterable, * validators?: ValidatorChain|iterable, - * }&array + * } */ interface InputFilterInterface extends Countable { From 940a88f1103346f9a1f2e1c305cf4bb98ab81b1f Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 10 Jun 2022 11:03:46 +0100 Subject: [PATCH 13/20] Drop psalm assertions where they assert internal state mutation Signed-off-by: George Steel --- psalm-baseline.xml | 15 ++------------- src/BaseInputFilter.php | 1 - src/CollectionInputFilter.php | 6 ++---- src/Factory.php | 7 +------ src/Input.php | 6 ++---- src/InputFilter.php | 3 +-- src/OptionalInputFilter.php | 1 - 7 files changed, 8 insertions(+), 31 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4727f717..6c14ff62 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -102,7 +102,7 @@ - + ! is_array($inputFilterSpecification) && ! $inputFilterSpecification instanceof Traversable @@ -376,9 +376,8 @@ new stdClass() new stdClass() - + public function addMethodArgumentsProvider(): array - setData @@ -536,10 +535,6 @@ method method - - setInputFilter - setInputFilter - @@ -788,12 +783,6 @@ $config['service_manager']['factories'] - - - setData - setData - - CustomInput diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index 50bd0b94..e3825f3d 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -183,7 +183,6 @@ public function remove($name) * @param iterable|null $data null is cast to an empty array. * @throws Exception\InvalidArgumentException * @return InputFilterInterface - * @psalm-assert array $this->data */ public function setData($data) { diff --git a/src/CollectionInputFilter.php b/src/CollectionInputFilter.php index 521eb9cb..20cea1e7 100644 --- a/src/CollectionInputFilter.php +++ b/src/CollectionInputFilter.php @@ -60,7 +60,6 @@ class CollectionInputFilter extends InputFilter * @param BaseInputFilter|array|Traversable $inputFilter * @throws Exception\RuntimeException * @return CollectionInputFilter - * @psalm-assert BaseInputFilter $this->inputFilter */ public function setInputFilter($inputFilter) { @@ -91,7 +90,7 @@ public function setInputFilter($inputFilter) public function getInputFilter() { if (null === $this->inputFilter) { - $this->setInputFilter(new InputFilter()); + $this->inputFilter = new InputFilter(); } return $this->inputFilter; @@ -101,7 +100,7 @@ public function getInputFilter() * Set if the collection can be empty * * @param bool $isRequired - * @return CollectionInputFilter + * @return $this */ public function setIsRequired($isRequired) { @@ -150,7 +149,6 @@ public function getCount() /** * @param mixed $data * @psalm-suppress ImplementedParamTypeMismatch - * @psalm-assert array $this->data * @return $this */ public function setData($data) diff --git a/src/Factory.php b/src/Factory.php index 023f6f26..a34684c0 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -49,7 +49,6 @@ public function __construct(?InputFilterPluginManager $inputFilterManager = null /** * Set default filter chain to use * - * @psalm-assert FilterChain $this->defaultFilterChain * @return $this */ public function setDefaultFilterChain(FilterChain $filterChain) @@ -71,7 +70,6 @@ public function getDefaultFilterChain() /** * Clear the default filter chain (i.e., don't inject one into new inputs) * - * @psalm-assert null $this->defaultFilterChain * @return void */ public function clearDefaultFilterChain() @@ -82,7 +80,6 @@ public function clearDefaultFilterChain() /** * Set default validator chain to use * - * @psalm-assert ValidatorChain $this->defaultValidatorChain * @return $this */ public function setDefaultValidatorChain(ValidatorChain $validatorChain) @@ -104,7 +101,6 @@ public function getDefaultValidatorChain() /** * Clear the default validator chain (i.e., don't inject one into new inputs) * - * @psalm-assert null $this->defaultValidatorChain * @return void */ public function clearDefaultValidatorChain() @@ -113,8 +109,7 @@ public function clearDefaultValidatorChain() } /** - * @psalm-assert InputFilterPluginManager $this->inputFilterManager - * @return self + * @return $this */ public function setInputFilterManager(InputFilterPluginManager $inputFilterManager) { diff --git a/src/Input.php b/src/Input.php index 6b208cdc..5181ad1b 100644 --- a/src/Input.php +++ b/src/Input.php @@ -122,7 +122,6 @@ public function setErrorMessage($errorMessage) /** * @return $this - * @psalm-assert FilterChain $this->filterChain */ public function setFilterChain(FilterChain $filterChain) { @@ -154,7 +153,6 @@ public function setRequired($required) /** * @return $this - * @psalm-assert ValidatorChain $this->validatorChain */ public function setValidatorChain(ValidatorChain $validatorChain) { @@ -251,7 +249,7 @@ public function getErrorMessage() public function getFilterChain() { if (! $this->filterChain) { - $this->setFilterChain(new FilterChain()); + $this->filterChain = new FilterChain(); } return $this->filterChain; } @@ -286,7 +284,7 @@ public function isRequired() public function getValidatorChain() { if (! $this->validatorChain) { - $this->setValidatorChain(new ValidatorChain()); + $this->validatorChain = new ValidatorChain(); } return $this->validatorChain; } diff --git a/src/InputFilter.php b/src/InputFilter.php index 05ae403f..95560aee 100644 --- a/src/InputFilter.php +++ b/src/InputFilter.php @@ -17,7 +17,6 @@ class InputFilter extends BaseInputFilter /** * Set factory to use when adding inputs and filters by spec * - * @psalm-assert Factory $this->factory * @return InputFilter */ public function setFactory(Factory $factory) @@ -36,7 +35,7 @@ public function setFactory(Factory $factory) public function getFactory() { if (null === $this->factory) { - $this->setFactory(new Factory()); + $this->factory = new Factory(); } return $this->factory; } diff --git a/src/OptionalInputFilter.php b/src/OptionalInputFilter.php index 3ff29d29..895716f5 100644 --- a/src/OptionalInputFilter.php +++ b/src/OptionalInputFilter.php @@ -16,7 +16,6 @@ class OptionalInputFilter extends InputFilter * actual validation, else it is always valid * @return $this * @throws Exception\InvalidArgumentException - * @psalm-assert array $this->data */ public function setData($data) { From 0e1c695f131f30a89135aeae230568956a1d01ba Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 10 Jun 2022 11:09:36 +0100 Subject: [PATCH 14/20] Remove suppression of deprecated properties re-adding to baseline Signed-off-by: George Steel --- psalm-baseline.xml | 8 +++----- src/Input.php | 2 -- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 6c14ff62..8a27ded6 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -120,7 +120,6 @@ $key $name $priority - $priority $value $value['type'] @@ -130,13 +129,10 @@ $filter['priority'] - $key $key $key $name $options - $options - $priority $priority $value @@ -240,9 +236,11 @@ setAllowEmpty setContinueIfEmpty - + + $this->allowEmpty $this->allowEmpty $this->continueIfEmpty + $this->continueIfEmpty $this->notEmptyValidator $this->notEmptyValidator $this->notEmptyValidator diff --git a/src/Input.php b/src/Input.php index 5181ad1b..6378d30e 100644 --- a/src/Input.php +++ b/src/Input.php @@ -212,7 +212,6 @@ public function setFallbackValue($value) */ public function allowEmpty() { - /** @psalm-suppress DeprecatedProperty */ return $this->allowEmpty; } @@ -231,7 +230,6 @@ public function breakOnFailure() */ public function continueIfEmpty() { - /** @psalm-suppress DeprecatedProperty */ return $this->continueIfEmpty; } From 7cdfd42665fd1a169965fac4e2cfa1a2afe30017 Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 10 Jun 2022 11:21:21 +0100 Subject: [PATCH 15/20] Revert added call to `ArrayUtils::iteratorToArray()` on given payload Signed-off-by: George Steel --- psalm-baseline.xml | 3 +++ src/CollectionInputFilter.php | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8a27ded6..29d06296 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -97,6 +97,9 @@ $data + + $data + $name diff --git a/src/CollectionInputFilter.php b/src/CollectionInputFilter.php index 20cea1e7..c663860b 100644 --- a/src/CollectionInputFilter.php +++ b/src/CollectionInputFilter.php @@ -2,7 +2,6 @@ namespace Laminas\InputFilter; -use Laminas\Stdlib\ArrayUtils; use Laminas\Validator\NotEmpty; use Traversable; @@ -162,8 +161,6 @@ public function setData($data) )); } - $data = ArrayUtils::iteratorToArray($data); - $this->setUnfilteredData($data); /** @psalm-suppress MixedAssignment */ From 6521d0aa009f43d61e1eff90b115920274daa5c0 Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 10 Jun 2022 11:27:23 +0100 Subject: [PATCH 16/20] Remove file level CS suppression to offending lines Signed-off-by: George Steel --- src/InputFilterAbstractServiceFactory.php | 4 ++-- src/InputFilterInterface.php | 10 +++++----- src/InputFilterPluginManager.php | 4 ++-- src/InputFilterPluginManagerFactory.php | 4 ++-- test/FactoryTest.php | 4 ++-- test/InputFilterPluginManagerFactoryTest.php | 4 ++-- test/ModuleTest.php | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/InputFilterAbstractServiceFactory.php b/src/InputFilterAbstractServiceFactory.php index ea110b1c..b5aed472 100644 --- a/src/InputFilterAbstractServiceFactory.php +++ b/src/InputFilterAbstractServiceFactory.php @@ -1,8 +1,8 @@ - Date: Fri, 10 Jun 2022 11:48:36 +0100 Subject: [PATCH 17/20] Simplify `$data` argument type in `setData()` to `iterable|null` and make it consistent for all implementations Signed-off-by: George Steel --- psalm-baseline.xml | 15 +++++++-------- src/BaseInputFilter.php | 2 +- src/CollectionInputFilter.php | 3 +-- src/InputFilterInterface.php | 2 +- src/OptionalInputFilter.php | 4 ++-- test/CollectionInputFilterTest.php | 1 + 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 29d06296..a01c5b0e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -51,9 +51,8 @@ $input - + $inputs - $value $inputContext @@ -84,6 +83,9 @@ array<array-key, array<string, array<array-key, string>>> + + $data + $this->collectionMessages $this->collectionMessages @@ -91,15 +93,13 @@ array<array-key, array> - + + $data $data $data - - $data - $name @@ -403,8 +403,7 @@ $set[5] $set[6] - - $data + $inputName $inputName $inputName diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index e3825f3d..7a0edf0c 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -180,7 +180,7 @@ public function remove($name) /** * Set data to use when validating and filtering * - * @param iterable|null $data null is cast to an empty array. + * @param iterable|null $data null is cast to an empty array. * @throws Exception\InvalidArgumentException * @return InputFilterInterface */ diff --git a/src/CollectionInputFilter.php b/src/CollectionInputFilter.php index c663860b..73eccbc5 100644 --- a/src/CollectionInputFilter.php +++ b/src/CollectionInputFilter.php @@ -146,8 +146,7 @@ public function getCount() } /** - * @param mixed $data - * @psalm-suppress ImplementedParamTypeMismatch + * @param iterable|null $data * @return $this */ public function setData($data) diff --git a/src/InputFilterInterface.php b/src/InputFilterInterface.php index d5651cec..5668129e 100644 --- a/src/InputFilterInterface.php +++ b/src/InputFilterInterface.php @@ -77,7 +77,7 @@ public function remove($name); /** * Set data to use when validating and filtering * - * @param iterable|null $data + * @param iterable|null $data * @return InputFilterInterface */ public function setData($data); diff --git a/src/OptionalInputFilter.php b/src/OptionalInputFilter.php index 895716f5..6a46adac 100644 --- a/src/OptionalInputFilter.php +++ b/src/OptionalInputFilter.php @@ -12,8 +12,8 @@ class OptionalInputFilter extends InputFilter /** * Set data to use when validating and filtering * - * @param iterable|null $data must be a non-empty iterable in order trigger - * actual validation, else it is always valid + * @param iterable|null $data must be a non-empty iterable in order trigger + * actual validation, else it is always valid * @return $this * @throws Exception\InvalidArgumentException */ diff --git a/test/CollectionInputFilterTest.php b/test/CollectionInputFilterTest.php index 758ed388..468678cf 100644 --- a/test/CollectionInputFilterTest.php +++ b/test/CollectionInputFilterTest.php @@ -527,6 +527,7 @@ public function testSettingDataWithNonArrayNonTraversableRaisesException($data): $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('invalid collection'); + /** @psalm-suppress MixedArgument */ $collectionInputFilter->setData($data); } From b6a05873e66a35ecd0fa80d8c7d763f9c8198343 Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 10 Jun 2022 11:53:37 +0100 Subject: [PATCH 18/20] Tidy up test helper method Signed-off-by: George Steel --- test/FactoryTest.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 363583a1..a1111146 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -1112,17 +1112,13 @@ protected function createDefaultFactory(): Factory } /** - * @param string $pluginName * @param mixed $pluginValue - * @return MockObject&InputFilterPluginManager */ - protected function createInputFilterPluginManagerMockForPlugin($pluginName, $pluginValue) - { - /** @var InputFilterPluginManager&MockObject $pluginManager */ - $pluginManager = $this->getMockBuilder(InputFilterPluginManager::class) - ->disableOriginalConstructor() - ->getMock(); - + protected function createInputFilterPluginManagerMockForPlugin( + string $pluginName, + $pluginValue + ): InputFilterPluginManager { + $pluginManager = $this->createMock(InputFilterPluginManager::class); $pluginManager->expects($this->atLeastOnce()) ->method('has') ->with($pluginName) From 52a6dbda6e8f77161d5afa7e326a982ffdefc657 Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 10 Jun 2022 12:31:44 +0100 Subject: [PATCH 19/20] Add palm type for input filters and collection specs Signed-off-by: George Steel --- psalm-baseline.xml | 21 +++++++++---------- src/CollectionInputFilter.php | 5 ++++- src/Factory.php | 30 +++++++++++++++++----------- src/InputFilterInterface.php | 10 ++++++++++ src/InputFilterProviderInterface.php | 6 +++++- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a01c5b0e..f1e3abc7 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -105,34 +105,33 @@ - - ! is_array($inputFilterSpecification) && ! $inputFilterSpecification instanceof Traversable - $inputFilter InputFilterInterface - + $inputFilterSpecification['count'] $inputFilterSpecification['input_filter'] $inputFilterSpecification['required'] $inputFilterSpecification['required_message'] $key - $key $name $priority $value $value['type'] + + $inputSpecification + $key + $filter['name'] $filter['options'] $filter['priority'] - - $key + $key $name $options @@ -473,9 +472,8 @@ - + $expectedType - $inputFilter new stdClass() @@ -493,6 +491,9 @@ function () use ($dataRaw, $dataFiltered) { function () use ($dataRaw, $dataFiltered, $errorMessage) { + + $inputFilter + $set[3] @@ -546,7 +547,7 @@ setMethods setMethods - + 'invalid_value' 'invalid_value' diff --git a/src/CollectionInputFilter.php b/src/CollectionInputFilter.php index 73eccbc5..e691d6ca 100644 --- a/src/CollectionInputFilter.php +++ b/src/CollectionInputFilter.php @@ -12,6 +12,9 @@ use function is_object; use function sprintf; +/** + * @psalm-import-type InputFilterSpecification from InputFilterInterface + */ class CollectionInputFilter extends InputFilter { /** @var bool */ @@ -56,7 +59,7 @@ class CollectionInputFilter extends InputFilter /** * Set the input filter to use when looping the data * - * @param BaseInputFilter|array|Traversable $inputFilter + * @param BaseInputFilter|InputFilterSpecification|Traversable $inputFilter * @throws Exception\RuntimeException * @return CollectionInputFilter */ diff --git a/src/Factory.php b/src/Factory.php index a34684c0..ff960202 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -24,6 +24,8 @@ * @psalm-import-type InputSpecification from InputFilterInterface * @psalm-import-type FilterSpecification from InputFilterInterface * @psalm-import-type ValidatorSpecification from InputFilterInterface + * @psalm-import-type InputFilterSpecification from InputFilterInterface + * @psalm-import-type CollectionSpecification from InputFilterInterface */ class Factory { @@ -144,17 +146,18 @@ public function createInput($inputSpecification) $inputSpecification = $inputSpecification->getInputSpecification(); } - if (! is_array($inputSpecification) && ! $inputSpecification instanceof Traversable) { - /** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ + if ($inputSpecification instanceof Traversable) { + $inputSpecification = ArrayUtils::iteratorToArray($inputSpecification); + } + + /** @psalm-suppress DocblockTypeContradiction */ + if (! is_array($inputSpecification)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects an array or Traversable; received "%s"', __METHOD__, is_object($inputSpecification) ? get_class($inputSpecification) : gettype($inputSpecification) )); } - if ($inputSpecification instanceof Traversable) { - $inputSpecification = ArrayUtils::iteratorToArray($inputSpecification); - } $class = Input::class; @@ -279,10 +282,11 @@ public function createInput($inputSpecification) /** * Factory for input filters * - * @param array|Traversable|InputFilterProviderInterface $inputFilterSpecification - * @throws Exception\InvalidArgumentException - * @throws Exception\RuntimeException + * phpcs:ignore Generic.Files.LineLength.TooLong + * @param InputFilterSpecification|CollectionSpecification|Traversable|InputFilterProviderInterface $inputFilterSpecification * @return InputFilterInterface + * @throws Exception\RuntimeException + * @throws Exception\InvalidArgumentException */ public function createInputFilter($inputFilterSpecification) { @@ -290,7 +294,12 @@ public function createInputFilter($inputFilterSpecification) $inputFilterSpecification = $inputFilterSpecification->getInputFilterSpecification(); } - if (! is_array($inputFilterSpecification) && ! $inputFilterSpecification instanceof Traversable) { + if ($inputFilterSpecification instanceof Traversable) { + $inputFilterSpecification = ArrayUtils::iteratorToArray($inputFilterSpecification); + } + + /** @psalm-suppress DocblockTypeContradiction */ + if (! is_array($inputFilterSpecification)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects an array or Traversable; received "%s"', __METHOD__, @@ -299,9 +308,6 @@ public function createInputFilter($inputFilterSpecification) : gettype($inputFilterSpecification) )); } - if ($inputFilterSpecification instanceof Traversable) { - $inputFilterSpecification = ArrayUtils::iteratorToArray($inputFilterSpecification); - } $type = InputFilter::class; diff --git a/src/InputFilterInterface.php b/src/InputFilterInterface.php index 5668129e..05238eb5 100644 --- a/src/InputFilterInterface.php +++ b/src/InputFilterInterface.php @@ -33,6 +33,16 @@ * filters?: FilterChain|iterable, * validators?: ValidatorChain|iterable, * } + * @psalm-type InputFilterSpecification = array{ + * type?: class-string|string, + * }&array + * @psalm-type CollectionSpecification = array{ + * type?: class-string|string, + * input_filter?: InputFilterSpecification|InputFilterInterface, + * count?: int, + * required?: bool, + * required_message?: string, + * }&array */ interface InputFilterInterface extends Countable { diff --git a/src/InputFilterProviderInterface.php b/src/InputFilterProviderInterface.php index b87ee52e..ef68822d 100644 --- a/src/InputFilterProviderInterface.php +++ b/src/InputFilterProviderInterface.php @@ -2,13 +2,17 @@ namespace Laminas\InputFilter; +/** + * @psalm-import-type InputFilterSpecification from InputFilterInterface + * @psalm-import-type CollectionSpecification from InputFilterInterface + */ interface InputFilterProviderInterface { /** * Should return an array specification compatible with * {@link Factory::createInputFilter()}. * - * @return array + * @return InputFilterSpecification|CollectionSpecification */ public function getInputFilterSpecification(); } From 853a0ac03b935fb29910e1d596e1f0e06393034b Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 10 Jun 2022 13:12:07 +0100 Subject: [PATCH 20/20] Revert addition of protected properties on Collection and re-add to baseline Signed-off-by: George Steel --- psalm-baseline.xml | 8 ++++---- src/CollectionInputFilter.php | 18 ------------------ 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f1e3abc7..a3a34b12 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -86,9 +86,12 @@ $data - + + $name $this->collectionMessages $this->collectionMessages + $this->invalidInputs + $this->validInputs array<array-key, array> @@ -100,9 +103,6 @@ $data - - $name - diff --git a/src/CollectionInputFilter.php b/src/CollectionInputFilter.php index e691d6ca..1fbf0929 100644 --- a/src/CollectionInputFilter.php +++ b/src/CollectionInputFilter.php @@ -38,24 +38,6 @@ class CollectionInputFilter extends InputFilter /** @var NotEmpty|null */ protected $notEmptyValidator; - /** - * @var array>|null - * @psalm-suppress NonInvariantDocblockPropertyType - */ - protected $validInputs; - - /** - * @var array>|null - * @psalm-suppress NonInvariantDocblockPropertyType - */ - protected $invalidInputs; - - /** - * @var array>|null - * @psalm-suppress NonInvariantDocblockPropertyType - */ - protected $validationGroup; - /** * Set the input filter to use when looping the data *