diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index 26c58025..baac9881 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -6,6 +6,26 @@ on:
branches:
tags:
+
+env:
+ default_php: 8.1
+
jobs:
ci:
uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x
+
+ rector:
+ runs-on: ubuntu-latest
+ name: Run Rector on PHP
+ steps:
+ - uses: actions/checkout@v4.2.2
+ - uses: shivammathur/setup-php@2.32.0
+ with:
+ php-version: ${{ env.default_php }}
+ tools: composer
+
+ - name: Install dependencies
+ run: composer install --no-progress --prefer-dist
+
+ - name: Run Rector
+ run: composer rector
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 6dc30726..46da2316 100644
--- a/composer.json
+++ b/composer.json
@@ -44,6 +44,7 @@
"phpbench/phpbench": "^1.3.1",
"phpunit/phpunit": "^10.5.38",
"psalm/plugin-phpunit": "^0.19.0",
+ "rector/rector": "^2.1.0",
"vimeo/psalm": "^5.26.1"
},
"suggest": {
@@ -69,7 +70,11 @@
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
+ "rector": "rector -n -vv",
+ "rector:fix": "rector -vv",
"static-analysis": "psalm --shepherd --stats",
+ "static-analysis:b": "psalm --update-baseline",
+ "static-analysis:clear": "psalm --clear-cache",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
},
diff --git a/composer.lock b/composer.lock
index 9d896e41..53e427ca 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "0e03eca46a3c8e847190e5aee34912c7",
+ "content-hash": "fdad460db3968a663ffc353cf12cf8e5",
"packages": [
{
"name": "brick/varexporter",
@@ -2293,6 +2293,64 @@
},
"time": "2025-02-19T13:28:12+00:00"
},
+ {
+ "name": "phpstan/phpstan",
+ "version": "2.1.18",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpstan/phpstan.git",
+ "reference": "ee1f390b7a70cdf74a2b737e554f68afea885db7"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ee1f390b7a70cdf74a2b737e554f68afea885db7",
+ "reference": "ee1f390b7a70cdf74a2b737e554f68afea885db7",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.4|^8.0"
+ },
+ "conflict": {
+ "phpstan/phpstan-shim": "*"
+ },
+ "bin": [
+ "phpstan",
+ "phpstan.phar"
+ ],
+ "type": "library",
+ "autoload": {
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "PHPStan - PHP Static Analysis Tool",
+ "keywords": [
+ "dev",
+ "static analysis"
+ ],
+ "support": {
+ "docs": "https://phpstan.org/user-guide/getting-started",
+ "forum": "https://github.com/phpstan/phpstan/discussions",
+ "issues": "https://github.com/phpstan/phpstan/issues",
+ "security": "https://github.com/phpstan/phpstan/security/policy",
+ "source": "https://github.com/phpstan/phpstan-src"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/ondrejmirtes",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/phpstan",
+ "type": "github"
+ }
+ ],
+ "time": "2025-07-17T17:22:31+00:00"
+ },
{
"name": "phpunit/php-code-coverage",
"version": "10.1.16",
@@ -2882,6 +2940,66 @@
},
"time": "2024-09-11T13:17:53+00:00"
},
+ {
+ "name": "rector/rector",
+ "version": "2.1.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/rectorphp/rector.git",
+ "reference": "40a71441dd73fa150a66102f5ca1364c44fc8fff"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/rectorphp/rector/zipball/40a71441dd73fa150a66102f5ca1364c44fc8fff",
+ "reference": "40a71441dd73fa150a66102f5ca1364c44fc8fff",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.4|^8.0",
+ "phpstan/phpstan": "^2.1.18"
+ },
+ "conflict": {
+ "rector/rector-doctrine": "*",
+ "rector/rector-downgrade-php": "*",
+ "rector/rector-phpunit": "*",
+ "rector/rector-symfony": "*"
+ },
+ "suggest": {
+ "ext-dom": "To manipulate phpunit.xml via the custom-rule command"
+ },
+ "bin": [
+ "bin/rector"
+ ],
+ "type": "library",
+ "autoload": {
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "Instant Upgrade and Automated Refactoring of any PHP code",
+ "homepage": "https://getrector.com/",
+ "keywords": [
+ "automation",
+ "dev",
+ "migration",
+ "refactoring"
+ ],
+ "support": {
+ "issues": "https://github.com/rectorphp/rector/issues",
+ "source": "https://github.com/rectorphp/rector/tree/2.1.2"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/tomasvotruba",
+ "type": "github"
+ }
+ ],
+ "time": "2025-07-17T19:30:06+00:00"
+ },
{
"name": "sebastian/cli-parser",
"version": "2.0.1",
diff --git a/phpcs.xml b/phpcs.xml
index 7f391d80..a85c462b 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -15,6 +15,7 @@
src
test
+ rector.php
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 8d0a93e8..bc647ed2 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -1,13 +1,5 @@
-
-
- eventManager]]>
-
-
-
-
-
@@ -158,22 +150,6 @@
-
-
-
-
-
-
-
- mbStringSupport === null]]>
- pcreUnicodeSupport === null]]>
-
-
-
-
-
-
-
@@ -182,13 +158,6 @@
-
-
-
-
-
-
-
replacement]]>
@@ -237,33 +206,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -272,31 +221,17 @@
-
- objectClassName]]>
-
-
-
-
-
-
-
-
-
-
-
-
@@ -309,41 +244,15 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
objectClassName]]>
-
-
-
@@ -353,9 +262,6 @@
-
-
-
@@ -492,11 +398,6 @@
field3]]>
-
-
-
-
-
@@ -529,15 +430,6 @@
-
-
-
-
-
-
-
-
-
@@ -628,8 +520,6 @@
-
-
@@ -647,7 +537,6 @@
-
@@ -688,9 +577,6 @@
-
-
-
@@ -711,7 +597,6 @@
-
diff --git a/rector.php b/rector.php
new file mode 100644
index 00000000..4856bfd3
--- /dev/null
+++ b/rector.php
@@ -0,0 +1,16 @@
+withPhpSets(php81: true)
+ ->withPaths([
+ __DIR__ . '/src',
+ __DIR__ . '/test',
+ ])
+ ->withPreparedSets(
+ typeDeclarations: true,
+ privatization: true,
+ );
diff --git a/src/AbstractHydrator.php b/src/AbstractHydrator.php
index 46f0fb27..77f57bab 100644
--- a/src/AbstractHydrator.php
+++ b/src/AbstractHydrator.php
@@ -4,6 +4,8 @@
namespace Laminas\Hydrator;
+use Laminas\Hydrator\Filter\FilterInterface;
+
use function sprintf;
abstract class AbstractHydrator implements
@@ -17,21 +19,17 @@ abstract class AbstractHydrator implements
*
* @var Strategy\StrategyInterface[]
*/
- protected $strategies = [];
+ protected array $strategies = [];
/**
* An instance of NamingStrategy\NamingStrategyInterface
- *
- * @var null|NamingStrategy\NamingStrategyInterface
*/
- protected $namingStrategy;
+ protected ?NamingStrategy\NamingStrategyInterface $namingStrategy = null;
/**
* Composite to filter the methods, that need to be hydrated
- *
- * @var null|Filter\FilterComposite
*/
- protected $filterComposite;
+ protected ?Filter\FilterComposite $filterComposite = null;
/**
* Gets the strategy with the given name.
@@ -112,9 +110,8 @@ public function removeStrategy(string $name): void
* @param string $name The name of the strategy to use.
* @param mixed $value The value that should be converted.
* @param null|object $object The object is optionally provided as context.
- * @return mixed
*/
- public function extractValue(string $name, mixed $value, ?object $object = null)
+ public function extractValue(string $name, mixed $value, ?object $object = null): mixed
{
return $this->hasStrategy($name)
? $this->getStrategy($name)->extract($value, $object)
@@ -127,9 +124,8 @@ public function extractValue(string $name, mixed $value, ?object $object = null)
* @param string $name The name of the strategy to use.
* @param mixed $value The value that should be converted.
* @param null|array $data The whole data is optionally provided as context.
- * @return mixed
*/
- public function hydrateValue(string $name, mixed $value, ?array $data = null)
+ public function hydrateValue(string $name, mixed $value, ?array $data = null): mixed
{
return $this->hasStrategy($name)
? $this->getStrategy($name)->hydrate($value, $data)
@@ -141,9 +137,8 @@ public function hydrateValue(string $name, mixed $value, ?array $data = null)
*
* @param string $name The name to convert.
* @param null|object $object The object is optionally provided as context.
- * @return string
*/
- public function extractName(string $name, ?object $object = null)
+ public function extractName(string $name, ?object $object = null): string
{
return $this->hasNamingStrategy()
? $this->getNamingStrategy()->extract($name, $object)
@@ -166,7 +161,7 @@ public function hydrateName(string $name, ?array $data = null): string
/**
* Get the filter instance
*/
- public function getFilter(): Filter\FilterInterface
+ public function getFilter(): FilterInterface
{
return $this->getCompositeFilter();
}
@@ -188,10 +183,13 @@ public function getFilter(): Filter\FilterInterface
*
*
* @param string $name Index in the composite
- * @param callable|Filter\FilterInterface $filter
+ * @param (callable(string, ?object):bool)|FilterInterface $filter
*/
- public function addFilter(string $name, $filter, int $condition = Filter\FilterComposite::CONDITION_OR): void
- {
+ public function addFilter(
+ string $name,
+ callable|FilterInterface $filter,
+ int $condition = Filter\FilterComposite::CONDITION_OR
+ ): void {
$this->getCompositeFilter()->addFilter($name, $filter, $condition);
}
diff --git a/src/Aggregate/AggregateHydrator.php b/src/Aggregate/AggregateHydrator.php
index 214e05fc..fd315151 100644
--- a/src/Aggregate/AggregateHydrator.php
+++ b/src/Aggregate/AggregateHydrator.php
@@ -9,6 +9,8 @@
use Laminas\EventManager\EventManagerInterface;
use Laminas\Hydrator\HydratorInterface;
+use function assert;
+
/**
* Aggregate hydrator that composes multiple hydrators via events
*/
@@ -16,8 +18,7 @@ final class AggregateHydrator implements HydratorInterface, EventManagerAwareInt
{
public const DEFAULT_PRIORITY = 1;
- /** @var EventManagerInterface */
- protected $eventManager;
+ private ?EventManagerInterface $eventManager = null;
/**
* Attaches the provided hydrator to the list of hydrators to be used while hydrating/extracting data
@@ -41,7 +42,7 @@ public function extract(object $object): array
/**
* {@inheritDoc}
*/
- public function hydrate(array $data, object $object)
+ public function hydrate(array $data, object $object): object
{
$event = new HydrateEvent($this, $object, $data);
$this->getEventManager()->triggerEvent($event);
@@ -53,7 +54,7 @@ public function hydrate(array $data, object $object)
*/
public function setEventManager(EventManagerInterface $eventManager): void
{
- $eventManager->setIdentifiers([self::class, static::class]);
+ $eventManager->setIdentifiers([self::class, self::class]);
$this->eventManager = $eventManager;
}
@@ -64,6 +65,7 @@ public function getEventManager(): EventManagerInterface
{
if (null === $this->eventManager) {
$this->setEventManager(new EventManager());
+ assert($this->eventManager instanceof EventManagerInterface);
}
return $this->eventManager;
diff --git a/src/Aggregate/ExtractEvent.php b/src/Aggregate/ExtractEvent.php
index a789d22e..05e64040 100644
--- a/src/Aggregate/ExtractEvent.php
+++ b/src/Aggregate/ExtractEvent.php
@@ -25,10 +25,10 @@ final class ExtractEvent extends Event
protected $name = self::EVENT_EXTRACT;
/** @var mixed[] Data being extracted from the $extractionObject */
- protected $extractedData = [];
+ private array $extractedData = [];
/** @psalm-param TTarget $target */
- public function __construct(object $target, protected object $extractionObject)
+ public function __construct(object $target, private object $extractionObject)
{
parent::__construct(self::EVENT_EXTRACT, $target, []);
}
diff --git a/src/Aggregate/HydrateEvent.php b/src/Aggregate/HydrateEvent.php
index ba9074ac..75516b2e 100644
--- a/src/Aggregate/HydrateEvent.php
+++ b/src/Aggregate/HydrateEvent.php
@@ -28,7 +28,7 @@ final class HydrateEvent extends Event
* @psalm-param TTarget $target
* @psalm-param T $hydratedObject
*/
- public function __construct(object $target, protected object $hydratedObject, protected array $hydrationData)
+ public function __construct(object $target, private object $hydratedObject, private array $hydrationData)
{
parent::__construct(self::EVENT_HYDRATE, $target, []);
}
diff --git a/src/Aggregate/HydratorListener.php b/src/Aggregate/HydratorListener.php
index 7a000fd9..daffff20 100644
--- a/src/Aggregate/HydratorListener.php
+++ b/src/Aggregate/HydratorListener.php
@@ -24,8 +24,8 @@ public function __construct(protected HydratorInterface $hydrator)
*/
public function attach(EventManagerInterface $events, $priority = 1): void
{
- $this->listeners[] = $events->attach(HydrateEvent::EVENT_HYDRATE, [$this, 'onHydrate'], $priority);
- $this->listeners[] = $events->attach(ExtractEvent::EVENT_EXTRACT, [$this, 'onExtract'], $priority);
+ $this->listeners[] = $events->attach(HydrateEvent::EVENT_HYDRATE, $this->onHydrate(...), $priority);
+ $this->listeners[] = $events->attach(ExtractEvent::EVENT_EXTRACT, $this->onExtract(...), $priority);
}
/**
diff --git a/src/ArraySerializableHydrator.php b/src/ArraySerializableHydrator.php
index 859f0831..9bb5410f 100644
--- a/src/ArraySerializableHydrator.php
+++ b/src/ArraySerializableHydrator.php
@@ -75,7 +75,7 @@ public function extract(object $object): array
* @throws Exception\BadMethodCallException For an $object not implementing exchangeArray() or populate().
* @throws Exception\RuntimeException If a part of $data could not be hydrated.
*/
- public function hydrate(array $data, object $object)
+ public function hydrate(array $data, object $object): object
{
$replacement = [];
foreach ($data as $key => $value) {
diff --git a/src/ClassMethodsHydrator.php b/src/ClassMethodsHydrator.php
index 34a3ae08..c6e3d05c 100644
--- a/src/ClassMethodsHydrator.php
+++ b/src/ClassMethodsHydrator.php
@@ -25,18 +25,14 @@ class ClassMethodsHydrator extends AbstractHydrator implements HydratorOptionsIn
{
/**
* Flag defining whether array keys are underscore-separated (true) or camel case (false)
- *
- * @var bool
*/
- protected $underscoreSeparatedKeys = true;
+ protected bool $underscoreSeparatedKeys = true;
/**
* Flag defining whether to check the setter method with method_exists to prevent the
* hydrator from calling __call during hydration
- *
- * @var bool
*/
- protected $methodExistsCheck = false;
+ protected bool $methodExistsCheck = false;
/**
* Holds the names of the methods used for hydration, indexed by class::property name,
@@ -44,7 +40,7 @@ class ClassMethodsHydrator extends AbstractHydrator implements HydratorOptionsIn
*
* @var string[]|bool[]
*/
- private $hydrationMethodsCache = [];
+ private array $hydrationMethodsCache = [];
/**
* A map of extraction methods to property name to be used during extraction, indexed
@@ -52,9 +48,9 @@ class ClassMethodsHydrator extends AbstractHydrator implements HydratorOptionsIn
*
* @var null[]|string[][]
*/
- private $extractionMethodsCache = [];
+ private array $extractionMethodsCache = [];
- private FilterInterface $optionalParametersFilter;
+ private readonly FilterInterface $optionalParametersFilter;
/**
* Define if extract values will use camel case or name with underscore
@@ -221,7 +217,7 @@ private function identifyAttributeName(object $object, string $method): string
*
* {@inheritDoc}
*/
- public function hydrate(array $data, object $object)
+ public function hydrate(array $data, object $object): object
{
$objectClass = $object::class;
@@ -248,8 +244,11 @@ public function hydrate(array $data, object $object)
/**
* {@inheritDoc}
*/
- public function addFilter(string $name, $filter, int $condition = Filter\FilterComposite::CONDITION_OR): void
- {
+ public function addFilter(
+ string $name,
+ callable|FilterInterface $filter,
+ int $condition = Filter\FilterComposite::CONDITION_OR
+ ): void {
$this->resetCaches();
parent::addFilter($name, $filter, $condition);
}
diff --git a/src/DelegatingHydrator.php b/src/DelegatingHydrator.php
index ce6d7c22..7ff8b87c 100644
--- a/src/DelegatingHydrator.php
+++ b/src/DelegatingHydrator.php
@@ -15,7 +15,7 @@ public function __construct(protected ContainerInterface $hydrators)
/**
* {@inheritdoc}
*/
- public function hydrate(array $data, object $object)
+ public function hydrate(array $data, object $object): object
{
return $this->getHydrator($object)->hydrate($data, $object);
}
diff --git a/src/Filter/FilterEnabledInterface.php b/src/Filter/FilterEnabledInterface.php
index cd7bc203..ada69518 100644
--- a/src/Filter/FilterEnabledInterface.php
+++ b/src/Filter/FilterEnabledInterface.php
@@ -25,9 +25,13 @@ interface FilterEnabledInterface extends FilterProviderInterface
*
*
* @param string $name Index in the composite
- * @param callable|FilterInterface $filter
+ * @param (callable(string, ?object):bool)|FilterInterface $filter
*/
- public function addFilter(string $name, $filter, int $condition = FilterComposite::CONDITION_OR): void;
+ public function addFilter(
+ string $name,
+ callable|FilterInterface $filter,
+ int $condition = FilterComposite::CONDITION_OR,
+ ): void;
/**
* Check whether a specific filter exists at key $name or not
diff --git a/src/Filter/MethodMatchFilter.php b/src/Filter/MethodMatchFilter.php
index e59ce514..4e94f3bc 100644
--- a/src/Filter/MethodMatchFilter.php
+++ b/src/Filter/MethodMatchFilter.php
@@ -17,11 +17,11 @@ public function __construct(
/**
* The method to exclude
*/
- private string $method,
+ private readonly string $method,
/**
* Either an exclude or an include
*/
- private bool $exclude = true
+ private readonly bool $exclude = true
) {
}
diff --git a/src/Filter/NumberOfParameterFilter.php b/src/Filter/NumberOfParameterFilter.php
index 1e2d3279..c741e789 100644
--- a/src/Filter/NumberOfParameterFilter.php
+++ b/src/Filter/NumberOfParameterFilter.php
@@ -20,7 +20,7 @@ public function __construct(
/**
* The number of parameters being accepted
*/
- private int $numberOfParameters = 0
+ private readonly int $numberOfParameters = 0
) {
}
diff --git a/src/HydrationInterface.php b/src/HydrationInterface.php
index bb91316d..c1d5f320 100644
--- a/src/HydrationInterface.php
+++ b/src/HydrationInterface.php
@@ -17,5 +17,5 @@ interface HydrationInterface
* @psalm-return T
* @template T of object
*/
- public function hydrate(array $data, object $object);
+ public function hydrate(array $data, object $object): object;
}
diff --git a/src/HydratorAwareTrait.php b/src/HydratorAwareTrait.php
index aed2fbb3..be526df3 100644
--- a/src/HydratorAwareTrait.php
+++ b/src/HydratorAwareTrait.php
@@ -8,10 +8,8 @@ trait HydratorAwareTrait
{
/**
* Hydrator instance
- *
- * @var null|HydratorInterface
*/
- protected $hydrator;
+ protected ?HydratorInterface $hydrator = null;
/**
* Set hydrator
diff --git a/src/HydratorPluginManager.php b/src/HydratorPluginManager.php
index 273aff68..dbaaed50 100644
--- a/src/HydratorPluginManager.php
+++ b/src/HydratorPluginManager.php
@@ -11,8 +11,7 @@
use Psr\Container\ContainerInterface;
use function array_replace_recursive;
-use function gettype;
-use function is_object;
+use function get_debug_type;
use function sprintf;
/**
@@ -102,7 +101,7 @@ public function validate(mixed $instance): void
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s',
- is_object($instance) ? $instance::class : gettype($instance),
+ get_debug_type($instance),
HydratorInterface::class
));
}
diff --git a/src/Iterator/HydratingIteratorInterface.php b/src/Iterator/HydratingIteratorInterface.php
index f0745056..43c1698a 100644
--- a/src/Iterator/HydratingIteratorInterface.php
+++ b/src/Iterator/HydratingIteratorInterface.php
@@ -22,7 +22,7 @@ interface HydratingIteratorInterface extends Iterator
*
* @param class-string|TPrototype $prototype
*/
- public function setPrototype($prototype): void;
+ public function setPrototype(string|object $prototype): void;
/**
* Sets the hydrator to use during iteration.
diff --git a/src/Iterator/HydratingIteratorIterator.php b/src/Iterator/HydratingIteratorIterator.php
index 30e7e051..edf255e7 100644
--- a/src/Iterator/HydratingIteratorIterator.php
+++ b/src/Iterator/HydratingIteratorIterator.php
@@ -24,8 +24,7 @@
*/
class HydratingIteratorIterator extends IteratorIterator implements HydratingIteratorInterface
{
- /** @var HydratorInterface */
- protected $hydrator;
+ protected HydratorInterface $hydrator;
/** @var TPrototype */
protected $prototype;
@@ -46,7 +45,7 @@ public function __construct(HydratorInterface $hydrator, Iterator $data, $protot
* @throws InvalidArgumentException If $prototype is a string, but refers to
* a non-existent class.
*/
- public function setPrototype($prototype): void
+ public function setPrototype(string|object $prototype): void
{
if (is_object($prototype)) {
$this->prototype = $prototype;
diff --git a/src/NamingStrategy/CompositeNamingStrategy.php b/src/NamingStrategy/CompositeNamingStrategy.php
index f1fec75f..02d6ca50 100644
--- a/src/NamingStrategy/CompositeNamingStrategy.php
+++ b/src/NamingStrategy/CompositeNamingStrategy.php
@@ -13,7 +13,7 @@ final class CompositeNamingStrategy implements NamingStrategyInterface
/** @var NamingStrategyInterface[] */
private array $namingStrategies = [];
- private NamingStrategyInterface $defaultNamingStrategy;
+ private readonly NamingStrategyInterface $defaultNamingStrategy;
/**
* @param NamingStrategyInterface[] $strategies indexed by the name they translate
diff --git a/src/NamingStrategy/UnderscoreNamingStrategy/CamelCaseToUnderscoreFilter.php b/src/NamingStrategy/UnderscoreNamingStrategy/CamelCaseToUnderscoreFilter.php
index edda7d2f..c000eacb 100644
--- a/src/NamingStrategy/UnderscoreNamingStrategy/CamelCaseToUnderscoreFilter.php
+++ b/src/NamingStrategy/UnderscoreNamingStrategy/CamelCaseToUnderscoreFilter.php
@@ -73,8 +73,12 @@ private function getLowerFunction(): callable
return $this->hasMbStringSupport()
? static fn($value): string =>
// ignore unicode characters w/ strtolower
- mb_strtolower($value, 'UTF-8')
- : static fn($value) =>
- preg_replace_callback('#([A-Z])#', static fn($matches): string => strtolower($matches[1]), $value);
+ mb_strtolower((string) $value, 'UTF-8')
+ : static fn($value): ?string =>
+ preg_replace_callback(
+ '#([A-Z])#',
+ static fn($matches): string => strtolower($matches[1]),
+ (string) $value
+ );
}
}
diff --git a/src/NamingStrategy/UnderscoreNamingStrategy/PcreReplacement.php b/src/NamingStrategy/UnderscoreNamingStrategy/PcreReplacement.php
index f5db80d9..0ac60b3e 100644
--- a/src/NamingStrategy/UnderscoreNamingStrategy/PcreReplacement.php
+++ b/src/NamingStrategy/UnderscoreNamingStrategy/PcreReplacement.php
@@ -13,15 +13,12 @@ class PcreReplacement
{
/** @var callable */
public $replacement;
- /** @var non-empty-string */
- public string $pattern;
/**
* @param non-empty-string $pattern
*/
- public function __construct(string $pattern, callable $replacement)
+ public function __construct(public string $pattern, callable $replacement)
{
$this->replacement = $replacement;
- $this->pattern = $pattern;
}
}
diff --git a/src/NamingStrategy/UnderscoreNamingStrategy/StringSupportTrait.php b/src/NamingStrategy/UnderscoreNamingStrategy/StringSupportTrait.php
index 067e4ed4..b607edbc 100644
--- a/src/NamingStrategy/UnderscoreNamingStrategy/StringSupportTrait.php
+++ b/src/NamingStrategy/UnderscoreNamingStrategy/StringSupportTrait.php
@@ -13,11 +13,9 @@
*/
trait StringSupportTrait
{
- /** @var bool */
- private $pcreUnicodeSupport;
+ private ?bool $pcreUnicodeSupport = null;
- /** @var bool */
- private $mbStringSupport;
+ private ?bool $mbStringSupport = null;
private function hasPcreUnicodeSupport(): bool
{
diff --git a/src/NamingStrategy/UnderscoreNamingStrategy/UnderscoreToCamelCaseFilter.php b/src/NamingStrategy/UnderscoreNamingStrategy/UnderscoreToCamelCaseFilter.php
index 348df50c..a15e1e62 100644
--- a/src/NamingStrategy/UnderscoreNamingStrategy/UnderscoreToCamelCaseFilter.php
+++ b/src/NamingStrategy/UnderscoreNamingStrategy/UnderscoreToCamelCaseFilter.php
@@ -54,7 +54,7 @@ private function getPatternAndReplacement(string $pregQuotedSeparator): PcreRepl
? $this->getUnicodePatternAndReplacement($pregQuotedSeparator)
: new PcreReplacement(
'#(' . $pregQuotedSeparator . ')([\S]{1})#',
- static fn($matches): string => strtoupper($matches[2])
+ static fn($matches): string => strtoupper((string) $matches[2])
);
}
@@ -63,19 +63,19 @@ private function getUnicodePatternAndReplacement(string $pregQuotedSeparator): P
return $this->hasMbStringSupport()
? new PcreReplacement(
'#(' . $pregQuotedSeparator . ')(\P{Z}{1})#u',
- static fn($matches): string => mb_strtoupper($matches[2], 'UTF-8')
+ static fn($matches): string => mb_strtoupper((string) $matches[2], 'UTF-8')
)
: new PcreReplacement(
'#(' . $pregQuotedSeparator . ')'
. '([^\p{Z}\p{Ll}]{1}|[a-zA-Z]{1})#u',
- static fn($matches): string => strtoupper($matches[2])
+ static fn($matches): string => strtoupper((string) $matches[2])
);
}
private function getLcFirstFunction(): callable
{
return $this->hasMbStringSupport()
- ? static fn($value): string => mb_strtolower($value[0], 'UTF-8') . substr($value, 1)
+ ? static fn($value): string => mb_strtolower((string) $value[0], 'UTF-8') . substr((string) $value, 1)
: 'lcfirst';
}
}
diff --git a/src/ObjectPropertyHydrator.php b/src/ObjectPropertyHydrator.php
index 7dba9328..81188e9f 100644
--- a/src/ObjectPropertyHydrator.php
+++ b/src/ObjectPropertyHydrator.php
@@ -54,7 +54,7 @@ public function extract(object $object): array
*
* {@inheritDoc}
*/
- public function hydrate(array $data, object $object)
+ public function hydrate(array $data, object $object): object
{
$properties = &self::$skippedPropertiesCache[$object::class] ?? null;
diff --git a/src/ReflectionHydrator.php b/src/ReflectionHydrator.php
index 97187434..30254051 100644
--- a/src/ReflectionHydrator.php
+++ b/src/ReflectionHydrator.php
@@ -42,7 +42,7 @@ public function extract(object $object): array
*
* {@inheritDoc}
*/
- public function hydrate(array $data, object $object)
+ public function hydrate(array $data, object $object): object
{
$reflProperties = self::getReflProperties($object);
foreach ($data as $key => $value) {
diff --git a/src/StandaloneHydratorPluginManager.php b/src/StandaloneHydratorPluginManager.php
index 59924839..5a62a36b 100644
--- a/src/StandaloneHydratorPluginManager.php
+++ b/src/StandaloneHydratorPluginManager.php
@@ -37,7 +37,7 @@ final class StandaloneHydratorPluginManager implements HydratorPluginManagerInte
* did not have the Hydrator suffix, it also maps the class name without
* the suffix.
*
- * @var array
+ * @var array
*/
private array $aliases = [
'arrayserializable' => ArraySerializableHydrator::class,
@@ -83,7 +83,7 @@ public function get($id)
/**
* {@inheritDoc}
*/
- public function has($id)
+ public function has($id): bool
{
return null !== $this->resolveName($id);
}
@@ -97,10 +97,6 @@ private function resolveName(string $name): ?string
return $name;
}
- if (isset($this->aliases[$name])) {
- return $this->aliases[$name];
- }
-
- return $this->aliases[strtolower($name)] ?? null;
+ return $this->aliases[$name] ?? $this->aliases[strtolower($name)] ?? null;
}
}
diff --git a/src/Strategy/BackedEnumStrategy.php b/src/Strategy/BackedEnumStrategy.php
index 12059da9..8797a7b3 100644
--- a/src/Strategy/BackedEnumStrategy.php
+++ b/src/Strategy/BackedEnumStrategy.php
@@ -18,21 +18,17 @@
*/
final class BackedEnumStrategy implements StrategyInterface
{
- /** @var class-string */
- private string $enumClass;
-
/**
* @param class-string $enumClass
*/
- public function __construct(string $enumClass)
+ public function __construct(private readonly string $enumClass)
{
- $this->enumClass = $enumClass;
}
/**
* @inheritDoc
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): int|string
{
if (! $value instanceof $this->enumClass) {
throw new InvalidArgumentException(sprintf(
@@ -46,10 +42,9 @@ public function extract($value, ?object $object = null)
}
/**
- * @param mixed $value
* @return T
*/
- public function hydrate($value, ?array $data)
+ public function hydrate(mixed $value, ?array $data = null): BackedEnum
{
if ($value instanceof $this->enumClass) {
return $value;
diff --git a/src/Strategy/BooleanStrategy.php b/src/Strategy/BooleanStrategy.php
index e6f1a5b0..c748a476 100644
--- a/src/Strategy/BooleanStrategy.php
+++ b/src/Strategy/BooleanStrategy.php
@@ -6,10 +6,9 @@
use Laminas\Hydrator\Exception\InvalidArgumentException;
-use function gettype;
+use function get_debug_type;
use function is_bool;
use function is_int;
-use function is_object;
use function is_string;
use function sprintf;
@@ -18,48 +17,23 @@
*/
final class BooleanStrategy implements StrategyInterface
{
- private int|string $trueValue;
-
- private int|string $falseValue;
-
- /**
- * @param int|string $trueValue
- * @param int|string $falseValue
- * @throws InvalidArgumentException
- */
- public function __construct($trueValue, $falseValue)
+ public function __construct(private readonly int|string $trueValue, private readonly int|string $falseValue)
{
- if (! is_int($trueValue) && ! is_string($trueValue)) {
- throw new InvalidArgumentException(sprintf(
- 'Unable to instantiate BooleanStrategy. Expected int or string as $trueValue. %s was given',
- is_object($trueValue) ? $trueValue::class : gettype($trueValue)
- ));
- }
-
- if (! is_int($falseValue) && ! is_string($falseValue)) {
- throw new InvalidArgumentException(sprintf(
- 'Unable to instantiate BooleanStrategy. Expected int or string as $falseValue. %s was given',
- is_object($falseValue) ? $falseValue::class : gettype($falseValue)
- ));
- }
-
- $this->trueValue = $trueValue;
- $this->falseValue = $falseValue;
}
/**
* Converts the given value so that it can be extracted by the hydrator.
*
- * @param bool $value The original value.
+ * @param bool $value The original value.
* @throws InvalidArgumentException
* @return int|string Returns the value that should be extracted.
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): int|string
{
if (! is_bool($value)) {
throw new InvalidArgumentException(sprintf(
'Unable to extract. Expected bool. %s was given.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
}
@@ -73,7 +47,7 @@ public function extract($value, ?object $object = null)
* @throws InvalidArgumentException
* @return bool Returns the value that should be hydrated.
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): bool
{
if (is_bool($value)) {
return $value;
@@ -82,7 +56,7 @@ public function hydrate($value, ?array $data = null)
if (! is_string($value) && ! is_int($value)) {
throw new InvalidArgumentException(sprintf(
'Unable to hydrate. Expected bool, string or int. %s was given.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
}
diff --git a/src/Strategy/ClosureStrategy.php b/src/Strategy/ClosureStrategy.php
index 602e64ac..5860426a 100644
--- a/src/Strategy/ClosureStrategy.php
+++ b/src/Strategy/ClosureStrategy.php
@@ -17,7 +17,7 @@ final class ClosureStrategy implements StrategyInterface
*
* @var null|callable
*/
- protected $extractFunc;
+ private $extractFunc;
/**
* Function, used in hydrate method, default:
@@ -30,7 +30,7 @@ final class ClosureStrategy implements StrategyInterface
*
* @var null|callable
*/
- protected $hydrateFunc;
+ private $hydrateFunc;
/**
* You can describe how your values will extract and hydrate, like this:
@@ -60,7 +60,7 @@ public function __construct(?callable $extractFunc = null, ?callable $hydrateFun
*
* {@inheritDoc}
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): mixed
{
$func = $this->extractFunc;
return $func
@@ -73,7 +73,7 @@ public function extract($value, ?object $object = null)
*
* {@inheritDoc}
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
$func = $this->hydrateFunc;
return $func
diff --git a/src/Strategy/CollectionStrategy.php b/src/Strategy/CollectionStrategy.php
index ff46646c..1e4d8e9f 100644
--- a/src/Strategy/CollectionStrategy.php
+++ b/src/Strategy/CollectionStrategy.php
@@ -10,42 +10,44 @@
use function array_map;
use function class_exists;
-use function gettype;
+use function get_debug_type;
use function is_array;
-use function is_object;
use function sprintf;
+/**
+ * @template T of object
+ */
final class CollectionStrategy implements StrategyInterface
{
- private string $objectClassName;
-
/**
+ * @param class-string $objectClassName
* @throws Exception\InvalidArgumentException
*/
- public function __construct(private HydratorInterface $objectHydrator, string $objectClassName)
- {
- if (! class_exists($objectClassName)) {
+ public function __construct(
+ private readonly HydratorInterface $objectHydrator,
+ private readonly string $objectClassName
+ ) {
+ if (! class_exists($this->objectClassName)) {
throw new Exception\InvalidArgumentException(sprintf(
'Object class name needs to be the name of an existing class, got "%s" instead.',
- $objectClassName
+ $this->objectClassName
));
}
- $this->objectClassName = $objectClassName;
}
/**
* Converts the given value so that it can be extracted by the hydrator.
*
- * @param mixed[] $value The original value.
+ * @param array $value The original value.
* @throws Exception\InvalidArgumentException
* @return mixed Returns the value that should be extracted.
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): array
{
if (! is_array($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Value needs to be an array, got "%s" instead.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
}
@@ -54,7 +56,7 @@ public function extract($value, ?object $object = null)
throw new Exception\InvalidArgumentException(sprintf(
'Value needs to be an instance of "%s", got "%s" instead.',
$this->objectClassName,
- is_object($object) ? $object::class : gettype($object)
+ get_debug_type($object)
));
}
@@ -65,16 +67,16 @@ public function extract($value, ?object $object = null)
/**
* Converts the given value so that it can be hydrated by the hydrator.
*
- * @param mixed[] $value The original value.
+ * @param mixed[] $value The original value.
* @throws Exception\InvalidArgumentException
- * @return object[] Returns the value that should be hydrated.
+ * @return array Returns the value that should be hydrated.
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate($value, ?array $data = null): array
{
if (! is_array($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Value needs to be an array, got "%s" instead.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
}
diff --git a/src/Strategy/DateTimeFormatterStrategy.php b/src/Strategy/DateTimeFormatterStrategy.php
index 13550bee..7918462d 100644
--- a/src/Strategy/DateTimeFormatterStrategy.php
+++ b/src/Strategy/DateTimeFormatterStrategy.php
@@ -8,8 +8,7 @@
use DateTimeInterface;
use DateTimeZone;
-use function gettype;
-use function is_object;
+use function get_debug_type;
use function is_string;
use function preg_replace;
use function sprintf;
@@ -24,7 +23,7 @@ final class DateTimeFormatterStrategy implements StrategyInterface
* during hydration). These include `!` at the beginning of the string and
* `|` at the end.
*/
- private string $extractionFormat;
+ private readonly string $extractionFormat;
/**
* @param bool $dateTimeFallback try to parse with DateTime when createFromFormat fails
@@ -34,12 +33,12 @@ public function __construct(
/**
* Format to use during hydration.
*/
- private string $format = DateTime::RFC3339,
- private ?DateTimeZone $timezone = null,
+ private readonly string $format = DateTime::RFC3339,
+ private readonly ?DateTimeZone $timezone = null,
/**
* Whether or not to allow hydration of values that do not follow the format exactly.
*/
- private bool $dateTimeFallback = false
+ private readonly bool $dateTimeFallback = false
) {
$extractionFormat = preg_replace('/(?format);
if (null === $extractionFormat) {
@@ -62,7 +61,7 @@ public function __construct(
* will be returned unmodified; otherwise, it will be extracted to a
* string.
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): mixed
{
if ($value instanceof DateTimeInterface) {
return $value->format($this->extractionFormat);
@@ -81,7 +80,7 @@ public function extract($value, ?object $object = null)
* @throws Exception\InvalidArgumentException If $value is not null, not a
* string, nor a DateTimeInterface.
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
if ($value === '' || $value === null || $value instanceof DateTimeInterface) {
return $value;
@@ -90,7 +89,7 @@ public function hydrate($value, ?array $data = null)
if (! is_string($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Unable to hydrate. Expected null, string, or DateTimeInterface; %s was given.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
}
diff --git a/src/Strategy/DateTimeImmutableFormatterStrategy.php b/src/Strategy/DateTimeImmutableFormatterStrategy.php
index 2503fb87..c91f59b6 100644
--- a/src/Strategy/DateTimeImmutableFormatterStrategy.php
+++ b/src/Strategy/DateTimeImmutableFormatterStrategy.php
@@ -11,7 +11,7 @@
final class DateTimeImmutableFormatterStrategy implements StrategyInterface
{
- public function __construct(private DateTimeFormatterStrategy $dateTimeStrategy)
+ public function __construct(private readonly DateTimeFormatterStrategy $dateTimeStrategy)
{
}
@@ -25,7 +25,7 @@ public function __construct(private DateTimeFormatterStrategy $dateTimeStrategy)
* will be returned unmodified; otherwise, it will be extracted to a
* string.
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): mixed
{
return $this->dateTimeStrategy->extract($value, $object);
}
@@ -40,7 +40,7 @@ public function extract($value, ?object $object = null)
* @throws Exception\InvalidArgumentException If $value is not null, not a
* string, nor a DateTimeInterface.
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
if ($value instanceof DateTimeImmutable) {
return $value;
diff --git a/src/Strategy/DefaultStrategy.php b/src/Strategy/DefaultStrategy.php
index 2565f82c..d2ff30c5 100644
--- a/src/Strategy/DefaultStrategy.php
+++ b/src/Strategy/DefaultStrategy.php
@@ -7,23 +7,17 @@
class DefaultStrategy implements StrategyInterface
{
/**
- * Converts the given value so that it can be extracted by the hydrator.
- *
- * @param mixed $value The original value.
- * @return mixed Returns the value that should be extracted.
+ * @inheritDoc
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): mixed
{
return $value;
}
/**
- * Converts the given value so that it can be hydrated by the hydrator.
- *
- * @param mixed $value The original value.
- * @return mixed Returns the value that should be hydrated.
+ * @inheritDoc
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
return $value;
}
diff --git a/src/Strategy/ExplodeStrategy.php b/src/Strategy/ExplodeStrategy.php
index 37b5c67e..1cea5ccf 100644
--- a/src/Strategy/ExplodeStrategy.php
+++ b/src/Strategy/ExplodeStrategy.php
@@ -5,11 +5,10 @@
namespace Laminas\Hydrator\Strategy;
use function explode;
-use function gettype;
+use function get_debug_type;
use function implode;
use function is_array;
use function is_numeric;
-use function is_object;
use function is_string;
use function sprintf;
@@ -24,7 +23,7 @@ final class ExplodeStrategy implements StrategyInterface
* @param non-empty-string $delimiter String that the values will be split upon
* @param int|null $explodeLimit Explode limit
*/
- public function __construct(string $delimiter = ',', private ?int $explodeLimit = null)
+ public function __construct(string $delimiter = ',', private readonly ?int $explodeLimit = null)
{
$this->setValueDelimiter($delimiter);
}
@@ -46,11 +45,11 @@ private function setValueDelimiter(string $delimiter): void
*
* Split a string by delimiter
*
- * @param string|null $value
+ * @param mixed $value
* @return string[]
* @throws Exception\InvalidArgumentException
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
if (null === $value) {
return [];
@@ -60,7 +59,7 @@ public function hydrate($value, ?array $data = null)
throw new Exception\InvalidArgumentException(sprintf(
'%s expects argument 1 to be string, %s provided instead',
__METHOD__,
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
}
@@ -80,13 +79,13 @@ public function hydrate($value, ?array $data = null)
* @return string|null
* @throws Exception\InvalidArgumentException For non-array $value values.
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): ?string
{
if (! is_array($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects argument 1 to be array, %s provided instead',
__METHOD__,
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
}
diff --git a/src/Strategy/HydratorStrategy.php b/src/Strategy/HydratorStrategy.php
index 491f0a1d..b49230f5 100644
--- a/src/Strategy/HydratorStrategy.php
+++ b/src/Strategy/HydratorStrategy.php
@@ -9,20 +9,19 @@
use ReflectionException;
use function class_exists;
-use function gettype;
+use function get_debug_type;
use function is_array;
-use function is_object;
use function sprintf;
final class HydratorStrategy implements StrategyInterface
{
- private string $objectClassName;
+ private readonly string $objectClassName;
/**
* @throws Exception\InvalidArgumentException
*/
public function __construct(
- private HydratorInterface $objectHydrator,
+ private readonly HydratorInterface $objectHydrator,
string $objectClassName
) {
if (! class_exists($objectClassName)) {
@@ -42,14 +41,14 @@ public function __construct(
* @return mixed Returns the value that should be extracted.
* @throws Exception\InvalidArgumentException
*/
- public function extract($value, ?object $object = null)
+ public function extract($value, ?object $object = null): array
{
if (! $value instanceof $this->objectClassName) {
throw new Exception\InvalidArgumentException(
sprintf(
'Value needs to be an instance of "%s", got "%s" instead.',
$this->objectClassName,
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
)
);
}
@@ -60,11 +59,10 @@ public function extract($value, ?object $object = null)
/**
* @param mixed $value The original value.
* @param null|array $data (optional) The original data for context.
- * @return object|string|null
* @throws ReflectionException
* @throws Exception\InvalidArgumentException
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): object|string|null
{
if (
$value === ''
@@ -78,7 +76,7 @@ public function hydrate($value, ?array $data = null)
throw new Exception\InvalidArgumentException(
sprintf(
'Value needs to be an array, got "%s" instead.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
)
);
}
diff --git a/src/Strategy/NullableStrategy.php b/src/Strategy/NullableStrategy.php
index a3241ac4..aba51e6a 100644
--- a/src/Strategy/NullableStrategy.php
+++ b/src/Strategy/NullableStrategy.php
@@ -8,8 +8,10 @@
final class NullableStrategy implements StrategyInterface
{
- public function __construct(private StrategyInterface $strategy, private bool $treatEmptyAsNull = false)
- {
+ public function __construct(
+ private readonly StrategyInterface $strategy,
+ private readonly bool $treatEmptyAsNull = false
+ ) {
}
/**
@@ -17,7 +19,7 @@ public function __construct(private StrategyInterface $strategy, private bool $t
*
* {@inheritDoc}
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): mixed
{
if ($value === null) {
return null;
@@ -35,7 +37,7 @@ public function extract($value, ?object $object = null)
*
* {@inheritDoc}
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
if ($value === null) {
return null;
diff --git a/src/Strategy/ScalarTypeStrategy.php b/src/Strategy/ScalarTypeStrategy.php
index c5c1d356..25fd971a 100644
--- a/src/Strategy/ScalarTypeStrategy.php
+++ b/src/Strategy/ScalarTypeStrategy.php
@@ -36,25 +36,16 @@ public static function createToBoolean(): self
return new self(self::TYPE_BOOLEAN);
}
- private function __construct(private string $type)
+ private function __construct(private readonly string $type)
{
}
- /**
- * @param mixed $value
- * @return mixed
- */
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): mixed
{
return $value;
}
- /**
- * @param mixed $value
- * @param array|null $data
- * @psalm-return null|scalar
- */
- public function hydrate($value, ?array $data)
+ public function hydrate(mixed $value, ?array $data = null): null|int|float|string|bool
{
if ($value === null) {
return null;
diff --git a/src/Strategy/SerializableStrategy.php b/src/Strategy/SerializableStrategy.php
index ca461c0b..c1bb8ecf 100644
--- a/src/Strategy/SerializableStrategy.php
+++ b/src/Strategy/SerializableStrategy.php
@@ -17,7 +17,7 @@ public function __construct(private readonly SerializerAdapter $serializer)
*
* {@inheritDoc}
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): string
{
return $this->serializer->serialize($value);
}
@@ -27,7 +27,7 @@ public function extract($value, ?object $object = null)
*
* {@inheritDoc}
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
return $this->serializer->unserialize($value);
}
diff --git a/src/Strategy/StrategyChain.php b/src/Strategy/StrategyChain.php
index 5370cb1f..87141c3b 100644
--- a/src/Strategy/StrategyChain.php
+++ b/src/Strategy/StrategyChain.php
@@ -16,14 +16,14 @@ final class StrategyChain implements StrategyInterface
*
* @var StrategyInterface[]
*/
- private array $extractionStrategies;
+ private readonly array $extractionStrategies;
/**
* Strategy chain for hydration
*
* @var StrategyInterface[]
*/
- private array $hydrationStrategies;
+ private readonly array $hydrationStrategies;
/**
* @param StrategyInterface[] $extractionStrategies
@@ -43,7 +43,7 @@ public function __construct(iterable $extractionStrategies)
/**
* {@inheritDoc}
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): mixed
{
foreach ($this->extractionStrategies as $strategy) {
$value = $strategy->extract($value, $object);
@@ -55,7 +55,7 @@ public function extract($value, ?object $object = null)
/**
* {@inheritDoc}
*/
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
foreach ($this->hydrationStrategies as $strategy) {
$value = $strategy->hydrate($value, $data);
diff --git a/src/Strategy/StrategyInterface.php b/src/Strategy/StrategyInterface.php
index 73900e2a..968b8200 100644
--- a/src/Strategy/StrategyInterface.php
+++ b/src/Strategy/StrategyInterface.php
@@ -13,7 +13,7 @@ interface StrategyInterface
* @param null|object $object (optional) The original object for context.
* @return mixed Returns the value that should be extracted.
*/
- public function extract($value, ?object $object = null);
+ public function extract(mixed $value, ?object $object = null): mixed;
/**
* Converts the given value so that it can be hydrated by the hydrator.
@@ -22,5 +22,5 @@ public function extract($value, ?object $object = null);
* @param null|array $data The original data for context.
* @return mixed Returns the value that should be hydrated.
*/
- public function hydrate($value, ?array $data);
+ public function hydrate(mixed $value, ?array $data = null): mixed;
}
diff --git a/test/Aggregate/HydratorListenerTest.php b/test/Aggregate/HydratorListenerTest.php
index e78b4252..4d368eac 100644
--- a/test/Aggregate/HydratorListenerTest.php
+++ b/test/Aggregate/HydratorListenerTest.php
@@ -37,7 +37,7 @@ public function testAttach(): void
$this->logicalOr(HydrateEvent::EVENT_HYDRATE, ExtractEvent::EVENT_EXTRACT),
$this->logicalAnd(
$this->callback('is_callable'),
- $this->logicalOr([$this->listener, 'onHydrate'], [$this->listener, 'onExtract'])
+ $this->logicalOr($this->listener->onHydrate(...), $this->listener->onExtract(...))
)
);
diff --git a/test/ArraySerializableHydratorTest.php b/test/ArraySerializableHydratorTest.php
index 10e1cfe3..f6cdeb25 100644
--- a/test/ArraySerializableHydratorTest.php
+++ b/test/ArraySerializableHydratorTest.php
@@ -21,8 +21,7 @@ class ArraySerializableHydratorTest extends TestCase
{
use HydratorTestTrait;
- /** @var ArraySerializableHydrator */
- protected $hydrator;
+ protected ArraySerializableHydrator $hydrator;
/**
* {@inheritDoc}
diff --git a/test/ClassMethodsHydratorTest.php b/test/ClassMethodsHydratorTest.php
index 15e2c157..c4b48b9a 100644
--- a/test/ClassMethodsHydratorTest.php
+++ b/test/ClassMethodsHydratorTest.php
@@ -19,8 +19,7 @@ class ClassMethodsHydratorTest extends TestCase
{
use HydratorTestTrait;
- /** @var ClassMethodsHydrator */
- protected $hydrator;
+ protected ClassMethodsHydrator $hydrator;
/**
* {@inheritDoc}
diff --git a/test/DelegatingHydratorTest.php b/test/DelegatingHydratorTest.php
index 8e8a5678..ffe0a41a 100644
--- a/test/DelegatingHydratorTest.php
+++ b/test/DelegatingHydratorTest.php
@@ -15,17 +15,11 @@
#[CoversClass(DelegatingHydrator::class)]
class DelegatingHydratorTest extends TestCase
{
- /** @var DelegatingHydrator */
- protected $hydrator;
+ protected DelegatingHydrator $hydrator;
- /**
- * @var ContainerInterface|MockObject
- * @psalm-var ContainerInterface&MockObject
- */
- protected $hydrators;
+ protected ContainerInterface&MockObject $hydrators;
- /** @var ArrayObject */
- protected $object;
+ protected ArrayObject $object;
/**
* {@inheritDoc}
diff --git a/test/Filter/OptionalParametersFilterTest.php b/test/Filter/OptionalParametersFilterTest.php
index e6ba7270..ba2fa8d4 100644
--- a/test/Filter/OptionalParametersFilterTest.php
+++ b/test/Filter/OptionalParametersFilterTest.php
@@ -13,8 +13,7 @@
#[CoversClass(OptionalParametersFilter::class)]
class OptionalParametersFilterTest extends TestCase
{
- /** @var OptionalParametersFilter */
- protected $filter;
+ protected OptionalParametersFilter $filter;
/**
* {@inheritDoc}
diff --git a/test/HydratorObjectPropertyTest.php b/test/HydratorObjectPropertyTest.php
index f7a343ea..93392172 100644
--- a/test/HydratorObjectPropertyTest.php
+++ b/test/HydratorObjectPropertyTest.php
@@ -21,20 +21,18 @@ protected function setUp(): void
public function testMultipleInvocationsWithDifferentFiltersFindsAllProperties(): void
{
$instance = new class {
- /** @var int */
- public $id;
+ public int $id;
/** @var int[] */
- public $array;
+ public array $array;
/** @var object{id:int} */
- public $object;
+ public object $object;
public function __construct()
{
$this->id = 4;
$this->array = [4, 3, 5, 6];
$this->object = new class {
- /** @var int */
- public $id = 4;
+ public int $id = 4;
};
}
};
diff --git a/test/HydratorPluginManagerFactoryTest.php b/test/HydratorPluginManagerFactoryTest.php
index fcfc7f41..104c7a50 100644
--- a/test/HydratorPluginManagerFactoryTest.php
+++ b/test/HydratorPluginManagerFactoryTest.php
@@ -10,6 +10,7 @@
use Laminas\Hydrator\ReflectionHydrator;
use LaminasTest\Hydrator\TestAsset\InMemoryContainer;
use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
#[CoversClass(HydratorPluginManagerFactory::class)]
@@ -32,8 +33,7 @@ public function testConfiguresHydratorServicesWhenFound(): void
'test' => ReflectionHydrator::class,
],
'factories' => [
- /** @psalm-return MockObject&HydratorInterface */
- 'test-too' => static fn(): HydratorInterface => $hydrator,
+ 'test-too' => static fn(): MockObject&HydratorInterface => $hydrator,
],
],
];
diff --git a/test/HydratorTest.php b/test/HydratorTest.php
index 409254da..71c9838f 100644
--- a/test/HydratorTest.php
+++ b/test/HydratorTest.php
@@ -33,23 +33,17 @@
class HydratorTest extends TestCase
{
- /** @var ClassMethodsCamelCase */
- protected $classMethodsCamelCase;
+ protected ClassMethodsCamelCase $classMethodsCamelCase;
- /** @var ClassMethodsTitleCase */
- protected $classMethodsTitleCase;
+ protected ClassMethodsTitleCase $classMethodsTitleCase;
- /** @var ClassMethodsCamelCaseMissing */
- protected $classMethodsCamelCaseMissing;
+ protected ClassMethodsCamelCaseMissing $classMethodsCamelCaseMissing;
- /** @var ClassMethodsUnderscore */
- protected $classMethodsUnderscore;
+ protected ClassMethodsUnderscore $classMethodsUnderscore;
- /** @var ClassMethodsInvalidParameter */
- protected $classMethodsInvalidParameter;
+ protected ClassMethodsInvalidParameter $classMethodsInvalidParameter;
- /** @var ReflectionAsset */
- protected $reflection;
+ protected ReflectionAsset $reflection;
protected function setUp(): void
{
diff --git a/test/NamingStrategy/IdentityNamingStrategyTest.php b/test/NamingStrategy/IdentityNamingStrategyTest.php
index 9a4bdfce..72ad5bc3 100644
--- a/test/NamingStrategy/IdentityNamingStrategyTest.php
+++ b/test/NamingStrategy/IdentityNamingStrategyTest.php
@@ -12,22 +12,16 @@
#[CoversClass(IdentityNamingStrategy::class)]
class IdentityNamingStrategyTest extends TestCase
{
- /**
- * @param string $name
- */
#[DataProvider('getTestedNames')]
- public function testHydrate($name): void
+ public function testHydrate(string $name): void
{
$namingStrategy = new IdentityNamingStrategy();
$this->assertSame($name, $namingStrategy->hydrate($name));
}
- /**
- * @param string $name
- */
#[DataProvider('getTestedNames')]
- public function testExtract($name): void
+ public function testExtract(string $name): void
{
$namingStrategy = new IdentityNamingStrategy();
@@ -39,7 +33,7 @@ public function testExtract($name): void
*
* @return string[][]
*/
- public static function getTestedNames()
+ public static function getTestedNames(): array
{
return [
'foo' => ['foo'],
diff --git a/test/NamingStrategy/UnderscoreNamingStrategy/CamelCaseToUnderscoreFilterTest.php b/test/NamingStrategy/UnderscoreNamingStrategy/CamelCaseToUnderscoreFilterTest.php
index 04d0ad57..d77e1d90 100644
--- a/test/NamingStrategy/UnderscoreNamingStrategy/CamelCaseToUnderscoreFilterTest.php
+++ b/test/NamingStrategy/UnderscoreNamingStrategy/CamelCaseToUnderscoreFilterTest.php
@@ -15,12 +15,8 @@
#[CoversClass(CamelCaseToUnderscoreFilter::class)]
class CamelCaseToUnderscoreFilterTest extends TestCase
{
- /**
- * @param string $string
- * @param string $expected
- */
#[DataProvider('nonUnicodeProvider')]
- public function testFilterUnderscoresNonUnicodeStrings($string, $expected): void
+ public function testFilterUnderscoresNonUnicodeStrings(string $string, string $expected): void
{
$filter = new CamelCaseToUnderscoreFilter();
@@ -34,12 +30,8 @@ public function testFilterUnderscoresNonUnicodeStrings($string, $expected): void
$this->assertEquals($expected, $filtered);
}
- /**
- * @param string $string
- * @param string $expected
- */
#[DataProvider('unicodeProvider')]
- public function testFilterUnderscoresUnicodeStrings($string, $expected): void
+ public function testFilterUnderscoresUnicodeStrings(string $string, string $expected): void
{
if (! extension_loaded('mbstring')) {
$this->markTestSkipped('Extension mbstring not available');
@@ -53,12 +45,8 @@ public function testFilterUnderscoresUnicodeStrings($string, $expected): void
$this->assertEquals($expected, $filtered);
}
- /**
- * @param string $string
- * @param string $expected
- */
#[DataProvider('unicodeProviderWithoutMbStrings')]
- public function testFilterUnderscoresUnicodeStringsWithoutMbStrings($string, $expected): void
+ public function testFilterUnderscoresUnicodeStringsWithoutMbStrings(string $string, string $expected): void
{
$filter = new CamelCaseToUnderscoreFilter();
diff --git a/test/NamingStrategy/UnderscoreNamingStrategy/UnderscoreToCamelCaseFilterTest.php b/test/NamingStrategy/UnderscoreNamingStrategy/UnderscoreToCamelCaseFilterTest.php
index 808a26cd..dbc5f1f1 100644
--- a/test/NamingStrategy/UnderscoreNamingStrategy/UnderscoreToCamelCaseFilterTest.php
+++ b/test/NamingStrategy/UnderscoreNamingStrategy/UnderscoreToCamelCaseFilterTest.php
@@ -15,12 +15,8 @@
#[CoversClass(UnderscoreToCamelCaseFilter::class)]
class UnderscoreToCamelCaseFilterTest extends TestCase
{
- /**
- * @param string $string
- * @param string $expected
- */
#[DataProvider('nonUnicodeProvider')]
- public function testFilterCamelCasesNonUnicodeStrings($string, $expected): void
+ public function testFilterCamelCasesNonUnicodeStrings(string $string, string $expected): void
{
$filter = new UnderscoreToCamelCaseFilter();
@@ -60,12 +56,8 @@ public static function nonUnicodeProvider(): array
];
}
- /**
- * @param string $string
- * @param string $expected
- */
#[DataProvider('unicodeProvider')]
- public function testFilterCamelCasesUnicodeStrings($string, $expected): void
+ public function testFilterCamelCasesUnicodeStrings(string $string, string $expected): void
{
if (! extension_loaded('mbstring')) {
$this->markTestSkipped('Extension mbstring not available');
@@ -112,14 +104,10 @@ public static function unicodeProvider(): array
];
}
- /**
- * @param string $string
- * @param string $expected
- */
#[DataProvider('unicodeWithoutMbStringsProvider')]
public function testFilterCamelCasesUnicodeStringsWithoutMbStrings(
- $string,
- $expected
+ string $string,
+ string $expected
): void {
$filter = new UnderscoreToCamelCaseFilter();
diff --git a/test/ObjectPropertyHydratorTest.php b/test/ObjectPropertyHydratorTest.php
index 0396cb21..4a9b86e0 100644
--- a/test/ObjectPropertyHydratorTest.php
+++ b/test/ObjectPropertyHydratorTest.php
@@ -17,8 +17,7 @@ class ObjectPropertyHydratorTest extends TestCase
{
use HydratorTestTrait;
- /** @var ObjectPropertyHydrator */
- private $hydrator;
+ private ObjectPropertyHydrator $hydrator;
/**
* {@inheritDoc}
diff --git a/test/ReflectionHydratorTest.php b/test/ReflectionHydratorTest.php
index 4b2fff8f..80120571 100644
--- a/test/ReflectionHydratorTest.php
+++ b/test/ReflectionHydratorTest.php
@@ -16,8 +16,7 @@ class ReflectionHydratorTest extends TestCase
{
use HydratorTestTrait;
- /** @var ReflectionHydrator */
- protected $hydrator;
+ protected ReflectionHydrator $hydrator;
/**
* {@inheritDoc}
diff --git a/test/StandaloneHydratorPluginManagerFactoryTest.php b/test/StandaloneHydratorPluginManagerFactoryTest.php
index c14e2c99..64f13ce8 100644
--- a/test/StandaloneHydratorPluginManagerFactoryTest.php
+++ b/test/StandaloneHydratorPluginManagerFactoryTest.php
@@ -25,8 +25,7 @@ class StandaloneHydratorPluginManagerFactoryTest extends TestCase
private const MESSAGE_DEFAULT_SERVICES = 'Missing the service %s';
private StandaloneHydratorPluginManagerFactory $factory;
- /** @var ContainerInterface&MockObject */
- private ContainerInterface|MockObject $container;
+ private ContainerInterface&MockObject $container;
protected function setUp(): void
{
diff --git a/test/Strategy/BooleanStrategyTest.php b/test/Strategy/BooleanStrategyTest.php
index 75b500e4..bc314826 100644
--- a/test/Strategy/BooleanStrategyTest.php
+++ b/test/Strategy/BooleanStrategyTest.php
@@ -23,22 +23,6 @@ public function testConstructorWithValidString(): void
$this->assertInstanceOf(BooleanStrategy::class, new BooleanStrategy('true', 'false'));
}
- public function testExceptionOnWrongTrueValueInConstructor(): void
- {
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessage('Expected int or string as $trueValue.');
-
- new BooleanStrategy(true, 0);
- }
-
- public function testExceptionOnWrongFalseValueInConstructor(): void
- {
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessage('Expected int or string as $falseValue.');
-
- new BooleanStrategy(1, false);
- }
-
public function testExtractString(): void
{
$hydrator = new BooleanStrategy('true', 'false');
diff --git a/test/Strategy/CollectionStrategyTest.php b/test/Strategy/CollectionStrategyTest.php
index 510d4527..b8536591 100644
--- a/test/Strategy/CollectionStrategyTest.php
+++ b/test/Strategy/CollectionStrategyTest.php
@@ -21,8 +21,7 @@
use function array_map;
use function count;
use function fopen;
-use function gettype;
-use function is_object;
+use function get_debug_type;
use function mt_getrandmax;
use function mt_rand;
use function spl_object_hash;
@@ -79,7 +78,7 @@ public function testExtractRejectsInvalidValue(mixed $value): void
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf(
'Value needs to be an array, got "%s" instead.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
/** @psalm-suppress MixedArgument */
@@ -107,47 +106,6 @@ public static function providerInvalidValueForExtraction(): Generator
}
}
- #[DataProvider('providerInvalidObjectForExtraction')]
- public function testExtractRejectsInvalidObject(mixed $object): void
- {
- $value = [$object];
-
- $strategy = new CollectionStrategy(
- $this->createHydratorMock(),
- TestAsset\User::class
- );
-
- $this->expectException(Exception\InvalidArgumentException::class);
- $this->expectExceptionMessage(sprintf(
- 'Value needs to be an instance of "%s", got "%s" instead.',
- TestAsset\User::class,
- is_object($object) ? $object::class : gettype($object)
- ));
-
- $strategy->extract($value);
- }
-
- /**
- * @return Generator>
- */
- public static function providerInvalidObjectForExtraction(): Generator
- {
- $values = [
- 'boolean-false' => false,
- 'boolean-true' => true,
- 'float' => mt_rand() / mt_getrandmax(),
- 'integer' => mt_rand(),
- 'null' => null,
- 'object-but-not-instance-of-object-class' => new stdClass(),
- 'resource' => fopen(__FILE__, 'r'),
- 'string-non-existent-class' => 'FooBarBaz9000',
- ];
-
- foreach ($values as $key => $value) {
- yield $key => [$value];
- }
- }
-
public function testExtractUsesHydratorToExtractValues(): void
{
$value = [
@@ -192,7 +150,7 @@ public function testHydrateRejectsInvalidValue(mixed $value): void
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf(
'Value needs to be an array, got "%s" instead.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
));
/** @psalm-suppress MixedArgument */
@@ -257,10 +215,7 @@ public function testHydrateUsesHydratorToHydrateValues(): void
self::assertEquals($expected, $strategy->hydrate($value));
}
- /**
- * @return HydratorInterface&MockObject
- */
- private function createHydratorMock()
+ private function createHydratorMock(): HydratorInterface&MockObject
{
return $this->createMock(HydratorInterface::class);
}
diff --git a/test/Strategy/DateTimeFormatterStrategyTest.php b/test/Strategy/DateTimeFormatterStrategyTest.php
index a7da9276..bf2df6cb 100644
--- a/test/Strategy/DateTimeFormatterStrategyTest.php
+++ b/test/Strategy/DateTimeFormatterStrategyTest.php
@@ -83,12 +83,8 @@ public function testCanExtractAnyDateTimeInterface(): void
$strategy->extract($dateImmutableMock);
}
- /**
- * @param string $format
- * @param string $expectedValue
- */
#[DataProvider('formatsWithSpecialCharactersProvider')]
- public function testAcceptsCreateFromFormatSpecialCharacters($format, $expectedValue): void
+ public function testAcceptsCreateFromFormatSpecialCharacters(string $format, string $expectedValue): void
{
$strategy = new DateTimeFormatterStrategy($format);
$hydrated = $strategy->hydrate($expectedValue);
diff --git a/test/Strategy/ExplodeStrategyTest.php b/test/Strategy/ExplodeStrategyTest.php
index 0d06fb1f..c0e3fd5a 100644
--- a/test/Strategy/ExplodeStrategyTest.php
+++ b/test/Strategy/ExplodeStrategyTest.php
@@ -76,7 +76,6 @@ public function testHydrateWithInvalidScalarType(): void
. ' array provided instead'
);
- /** @psalm-suppress InvalidArgument */
$strategy->hydrate([]);
}
@@ -90,7 +89,6 @@ public function testHydrateWithInvalidObjectType(): void
. ' stdClass provided instead'
);
- /** @psalm-suppress InvalidArgument */
$strategy->hydrate(new stdClass());
}
@@ -116,7 +114,6 @@ public function testHydration(mixed $value, string $delimiter, array $expected):
{
$strategy = new ExplodeStrategy($delimiter);
- /** @psalm-suppress MixedArgument */
self::assertSame($expected, $strategy->hydrate($value));
}
diff --git a/test/Strategy/HydratorStrategyTest.php b/test/Strategy/HydratorStrategyTest.php
index 95890591..ae631252 100644
--- a/test/Strategy/HydratorStrategyTest.php
+++ b/test/Strategy/HydratorStrategyTest.php
@@ -20,8 +20,7 @@
use function count;
use function fopen;
-use function gettype;
-use function is_object;
+use function get_debug_type;
use function mt_getrandmax;
use function mt_rand;
use function spl_object_hash;
@@ -81,7 +80,7 @@ public function testExtractRejectsInvalidValue(mixed $value): void
sprintf(
'Value needs to be an instance of "%s", got "%s" instead.',
TestAsset\User::class,
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
)
);
@@ -120,7 +119,7 @@ public function testExtractRejectsInvalidObject(mixed $object): void
sprintf(
'Value needs to be an instance of "%s", got "%s" instead.',
TestAsset\User::class,
- is_object($object) ? $object::class : gettype($object)
+ get_debug_type($object)
)
);
@@ -184,7 +183,7 @@ public function testHydrateRejectsInvalidValue(mixed $value): void
$this->expectExceptionMessage(
sprintf(
'Value needs to be an array, got "%s" instead.',
- is_object($value) ? $value::class : gettype($value)
+ get_debug_type($value)
)
);
@@ -238,7 +237,7 @@ public function testHydrateUsesHydratorToHydrateValues(): void
{
$value = ['name' => 'John Doe'];
- $hydration = static function ($data) {
+ $hydration = static function ($data): mixed {
static $hydrator;
if (null === $hydrator) {
@@ -265,10 +264,7 @@ public function testHydrateUsesHydratorToHydrateValues(): void
self::assertEquals($hydration($value), $strategy->hydrate($value));
}
- /**
- * @return MockObject&HydratorInterface
- */
- private function createHydratorMock(): HydratorInterface
+ private function createHydratorMock(): MockObject&HydratorInterface
{
return $this->createMock(HydratorInterface::class);
}
diff --git a/test/TestAsset/AggregateObject.php b/test/TestAsset/AggregateObject.php
index e211e1da..92036b18 100644
--- a/test/TestAsset/AggregateObject.php
+++ b/test/TestAsset/AggregateObject.php
@@ -10,32 +10,21 @@
*/
class AggregateObject
{
- /** @var array */
- public $arrayData = ['president' => 'Zaphod'];
+ public array $arrayData = ['president' => 'Zaphod'];
- /** @var string */
- public $maintainer = 'Marvin';
+ public string $maintainer = 'Marvin';
- /**
- * @return string
- */
- public function getMaintainer()
+ public function getMaintainer(): string
{
return $this->maintainer;
}
- /**
- * @param string $maintainer
- */
- public function setMaintainer($maintainer): void
+ public function setMaintainer(string $maintainer): void
{
$this->maintainer = $maintainer;
}
- /**
- * @return array
- */
- public function getArrayCopy()
+ public function getArrayCopy(): array
{
return $this->arrayData;
}
diff --git a/test/TestAsset/ArrayObjectObjectVars.php b/test/TestAsset/ArrayObjectObjectVars.php
deleted file mode 100644
index 3967295f..00000000
--- a/test/TestAsset/ArrayObjectObjectVars.php
+++ /dev/null
@@ -1,16 +0,0 @@
-data = $array;
}
diff --git a/test/TestAsset/ArraySerializableNoGetArrayCopy.php b/test/TestAsset/ArraySerializableNoGetArrayCopy.php
index 7e193cbc..0f93f094 100644
--- a/test/TestAsset/ArraySerializableNoGetArrayCopy.php
+++ b/test/TestAsset/ArraySerializableNoGetArrayCopy.php
@@ -6,8 +6,7 @@
class ArraySerializableNoGetArrayCopy
{
- /** @var array */
- protected $data = [];
+ protected array $data = [];
public function __construct()
{
diff --git a/test/TestAsset/ClassMethodsCamelCase.php b/test/TestAsset/ClassMethodsCamelCase.php
index 6743d38e..02996b70 100644
--- a/test/TestAsset/ClassMethodsCamelCase.php
+++ b/test/TestAsset/ClassMethodsCamelCase.php
@@ -6,97 +6,79 @@
class ClassMethodsCamelCase
{
- /** @var string */
- protected $fooBar = '1';
+ protected string $fooBar = '1';
- /** @var string */
- protected $fooBarBaz = '2';
+ protected string $fooBarBaz = '2';
- /** @var bool */
- protected $isFoo = true;
+ protected bool $isFoo = true;
- /** @var bool */
- protected $isBar = true;
+ protected bool $isBar = true;
- /** @var bool */
- protected $hasFoo = true;
+ protected bool $hasFoo = true;
- /** @var bool */
- protected $hasBar = true;
+ protected bool $hasBar = true;
- /** @return string */
- public function getFooBar()
+ public function getFooBar(): string
{
return $this->fooBar;
}
- /** @param string $value */
- public function setFooBar($value): self
+ public function setFooBar(string $value): self
{
$this->fooBar = $value;
return $this;
}
- /** @return string */
- public function getFooBarBaz()
+ public function getFooBarBaz(): string
{
return $this->fooBarBaz;
}
- /** @param string $value */
- public function setFooBarBaz($value): self
+ public function setFooBarBaz(string $value): self
{
$this->fooBarBaz = $value;
return $this;
}
- /** @return bool */
- public function getIsFoo()
+ public function getIsFoo(): bool
{
return $this->isFoo;
}
- /** @param bool $value */
- public function setIsFoo($value): self
+ public function setIsFoo(bool $value): self
{
$this->isFoo = $value;
return $this;
}
- /** @return bool */
- public function isBar()
+ public function isBar(): bool
{
return $this->isBar;
}
- /** @param bool $value */
- public function setIsBar($value): self
+ public function setIsBar(bool $value): self
{
$this->isBar = $value;
return $this;
}
- /** @return bool */
- public function getHasFoo()
+ public function getHasFoo(): bool
{
return $this->hasFoo;
}
- /** @param bool $value */
- public function setHasFoo($value): self
+ public function setHasFoo(bool $value): self
{
$this->hasFoo = $value;
return $this;
}
- /** @return bool */
- public function hasBar()
+ public function hasBar(): bool
{
return $this->hasBar;
}
- /** @param bool $value */
- public function setHasBar($value): self
+ public function setHasBar(bool $value): self
{
$this->hasBar = $value;
return $this;
diff --git a/test/TestAsset/ClassMethodsCamelCaseMissing.php b/test/TestAsset/ClassMethodsCamelCaseMissing.php
index d90a14cb..825aae04 100644
--- a/test/TestAsset/ClassMethodsCamelCaseMissing.php
+++ b/test/TestAsset/ClassMethodsCamelCaseMissing.php
@@ -6,27 +6,22 @@
class ClassMethodsCamelCaseMissing
{
- /** @var string */
- protected $fooBar = '1';
+ protected string $fooBar = '1';
- /** @var string */
- protected $fooBarBaz = '2';
+ protected string $fooBarBaz = '2';
- /** @return string */
- public function getFooBar()
+ public function getFooBar(): string
{
return $this->fooBar;
}
- /** @param string $value */
- public function setFooBar($value): self
+ public function setFooBar(string $value): self
{
$this->fooBar = $value;
return $this;
}
- /** @return string */
- public function getFooBarBaz()
+ public function getFooBarBaz(): string
{
return $this->fooBarBaz;
}
diff --git a/test/TestAsset/ClassMethodsMagicMethodSetter.php b/test/TestAsset/ClassMethodsMagicMethodSetter.php
index 68372499..4f3478d7 100644
--- a/test/TestAsset/ClassMethodsMagicMethodSetter.php
+++ b/test/TestAsset/ClassMethodsMagicMethodSetter.php
@@ -10,23 +10,17 @@
class ClassMethodsMagicMethodSetter
{
- /** @var mixed */
- protected $foo;
+ protected mixed $foo;
- /**
- * @param string $method
- * @param array $args
- */
- public function __call($method, $args)
+ public function __call(string $method, array $args)
{
if (strlen($method) > 3 && strtolower(substr($method, 3)) === 'foo') {
$this->foo = $args[0];
}
}
- /** @return mixed */
- public function getFoo()
+ public function getFoo(): mixed
{
- return $this->foo;
+ return $this->foo ?? null;
}
}
diff --git a/test/TestAsset/ClassMethodsOptionalParameters.php b/test/TestAsset/ClassMethodsOptionalParameters.php
index 46327924..79e63bc7 100644
--- a/test/TestAsset/ClassMethodsOptionalParameters.php
+++ b/test/TestAsset/ClassMethodsOptionalParameters.php
@@ -9,23 +9,14 @@
*/
class ClassMethodsOptionalParameters
{
- /** @var string */
- public $foo = 'bar';
+ public string $foo = 'bar';
- /**
- * @param mixed $optional
- * @return string
- */
- public function getFoo($optional = null)
+ public function getFoo(mixed $optional = null): string
{
return $this->foo;
}
- /**
- * @param string $foo
- * @param mixed $optional
- */
- public function setFoo($foo, $optional = null): void
+ public function setFoo(string $foo, mixed $optional = null): void
{
$this->foo = $foo;
}
diff --git a/test/TestAsset/ClassMethodsProtectedSetter.php b/test/TestAsset/ClassMethodsProtectedSetter.php
index 1ea99893..0ca58d36 100644
--- a/test/TestAsset/ClassMethodsProtectedSetter.php
+++ b/test/TestAsset/ClassMethodsProtectedSetter.php
@@ -6,26 +6,21 @@
class ClassMethodsProtectedSetter
{
- /** @var mixed */
- protected $foo;
+ protected mixed $foo;
- /** @var mixed */
- protected $bar;
+ protected mixed $bar;
- /** @param mixed $foo */
- protected function setFoo($foo): void
+ protected function setFoo(mixed $foo): void
{
$this->foo = $foo;
}
- /** @param mixed $bar */
- public function setBar($bar): void
+ public function setBar(mixed $bar): void
{
$this->bar = $bar;
}
- /** @return mixed */
- public function getBar()
+ public function getBar(): mixed
{
return $this->bar;
}
diff --git a/test/TestAsset/ClassMethodsTitleCase.php b/test/TestAsset/ClassMethodsTitleCase.php
index b4a77bb8..765fdea2 100644
--- a/test/TestAsset/ClassMethodsTitleCase.php
+++ b/test/TestAsset/ClassMethodsTitleCase.php
@@ -6,79 +6,79 @@
class ClassMethodsTitleCase
{
- protected $FooBar = '1';
+ protected string $FooBar = '1';
- protected $FooBarBaz = '2';
+ protected string $FooBarBaz = '2';
- protected $IsFoo = true;
+ protected bool $IsFoo = true;
- protected $IsBar = true;
+ protected bool $IsBar = true;
- protected $HasFoo = true;
+ protected bool $HasFoo = true;
- protected $HasBar = true;
+ protected bool $HasBar = true;
- public function getFooBar()
+ public function getFooBar(): string
{
return $this->FooBar;
}
- public function setFooBar($value): self
+ public function setFooBar(string $value): self
{
$this->FooBar = $value;
return $this;
}
- public function getFooBarBaz()
+ public function getFooBarBaz(): string
{
return $this->FooBarBaz;
}
- public function setFooBarBaz($value): self
+ public function setFooBarBaz(string $value): self
{
$this->FooBarBaz = $value;
return $this;
}
- public function getIsFoo()
+ public function getIsFoo(): bool
{
return $this->IsFoo;
}
- public function setIsFoo($IsFoo): self
+ public function setIsFoo(bool $IsFoo): self
{
$this->IsFoo = $IsFoo;
return $this;
}
- public function getIsBar()
+ public function getIsBar(): bool
{
return $this->IsBar;
}
- public function setIsBar($IsBar): self
+ public function setIsBar(bool $IsBar): self
{
$this->IsBar = $IsBar;
return $this;
}
- public function getHasFoo()
+ public function getHasFoo(): bool
{
return $this->HasFoo;
}
- public function getHasBar()
+ public function getHasBar(): bool
{
return $this->HasBar;
}
- public function setHasFoo($HasFoo): self
+ public function setHasFoo(bool $HasFoo): self
{
$this->HasFoo = $HasFoo;
return $this;
}
- public function setHasBar($HasBar): void
+ public function setHasBar(bool $HasBar): void
{
$this->HasBar = $HasBar;
}
diff --git a/test/TestAsset/ClassMethodsUnderscore.php b/test/TestAsset/ClassMethodsUnderscore.php
index 476720d2..57ce8219 100644
--- a/test/TestAsset/ClassMethodsUnderscore.php
+++ b/test/TestAsset/ClassMethodsUnderscore.php
@@ -7,97 +7,79 @@
class ClassMethodsUnderscore
{
- /** @var string */
- protected $foo_bar = '1';
+ protected string $foo_bar = '1';
- /** @var string */
- protected $foo_bar_baz = '2';
+ protected string $foo_bar_baz = '2';
- /** @var bool */
- protected $is_foo = true;
+ protected bool $is_foo = true;
- /** @var bool */
- protected $is_bar = true;
+ protected bool $is_bar = true;
- /** @var bool */
- protected $has_foo = true;
+ protected bool $has_foo = true;
- /** @var bool */
- protected $has_bar = true;
+ protected bool $has_bar = true;
- /** @return string */
- public function getFooBar()
+ public function getFooBar(): string
{
return $this->foo_bar;
}
- /** @param string $value */
- public function setFooBar($value): self
+ public function setFooBar(string $value): self
{
$this->foo_bar = $value;
return $this;
}
- /** @return string */
- public function getFooBarBaz()
+ public function getFooBarBaz(): string
{
return $this->foo_bar_baz;
}
- /** @param string $value */
- public function setFooBarBaz($value): self
+ public function setFooBarBaz(string $value): self
{
$this->foo_bar_baz = $value;
return $this;
}
- /** @return bool */
- public function getIsFoo()
+ public function getIsFoo(): bool
{
return $this->is_foo;
}
- /** @param bool $value */
- public function setIsFoo($value): self
+ public function setIsFoo(bool $value): self
{
$this->is_foo = $value;
return $this;
}
- /** @return bool */
- public function isBar()
+ public function isBar(): bool
{
return $this->is_bar;
}
- /** @param bool $value */
- public function setIsBar($value): self
+ public function setIsBar(bool $value): self
{
$this->is_bar = $value;
return $this;
}
- /** @return bool */
- public function getHasFoo()
+ public function getHasFoo(): bool
{
return $this->has_foo;
}
- /** @param bool $value */
- public function setHasFoo($value): self
+ public function setHasFoo(bool $value): self
{
$this->has_foo = $value;
return $this;
}
- /** @return bool */
- public function hasBar()
+ public function hasBar(): bool
{
return $this->has_bar;
}
- /** @param bool $value */
- public function setHasBar($value): self
+ public function setHasBar(bool $value): self
{
$this->has_bar = $value;
return $this;
diff --git a/test/TestAsset/HydratorClosureStrategyEntity.php b/test/TestAsset/HydratorClosureStrategyEntity.php
index 71e62285..be52115d 100644
--- a/test/TestAsset/HydratorClosureStrategyEntity.php
+++ b/test/TestAsset/HydratorClosureStrategyEntity.php
@@ -9,19 +9,7 @@
#[AllowDynamicProperties]
class HydratorClosureStrategyEntity
{
- /** @var mixed */
- public $field1;
-
- /** @var mixed */
- public $field2;
-
- /**
- * @param mixed $field1
- * @param mixed $field2
- */
- public function __construct($field1 = null, $field2 = null)
+ public function __construct(public mixed $field1 = null, public mixed $field2 = null)
{
- $this->field1 = $field1;
- $this->field2 = $field2;
}
}
diff --git a/test/TestAsset/HydratorStrategy.php b/test/TestAsset/HydratorStrategy.php
index 8388a8e5..e864740c 100644
--- a/test/TestAsset/HydratorStrategy.php
+++ b/test/TestAsset/HydratorStrategy.php
@@ -25,9 +25,9 @@ public function __construct()
/**
* @param array $value
- * @return mixed
+ * @return list
*/
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): array
{
$result = [];
foreach ($value as $instance) {
@@ -36,11 +36,7 @@ public function extract($value, ?object $object = null)
return $result;
}
- /**
- * @param mixed $value
- * @return mixed
- */
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
$result = $value;
if (is_array($value)) {
@@ -52,11 +48,7 @@ public function hydrate($value, ?array $data = null)
return $result;
}
- /**
- * @param mixed $field1
- * @return mixed
- */
- private function findEntity($field1)
+ private function findEntity(mixed $field1): mixed
{
$result = null;
foreach ($this->simulatedStorageDevice as $entity) {
diff --git a/test/TestAsset/HydratorStrategyContextAware.php b/test/TestAsset/HydratorStrategyContextAware.php
index 2aa0c079..45b2686f 100644
--- a/test/TestAsset/HydratorStrategyContextAware.php
+++ b/test/TestAsset/HydratorStrategyContextAware.php
@@ -8,27 +8,17 @@
class HydratorStrategyContextAware extends DefaultStrategy
{
- /** @var object */
- public $object;
+ public object $object;
- /** @var mixed */
- public $data;
+ public mixed $data;
- /**
- * @param array $value
- * @return mixed
- */
- public function extract($value, ?object $object = null)
+ public function extract(mixed $value, ?object $object = null): mixed
{
$this->object = $object;
return $value;
}
- /**
- * @param mixed $value
- * @return mixed
- */
- public function hydrate($value, ?array $data = null)
+ public function hydrate(mixed $value, ?array $data = null): mixed
{
$this->data = $data;
return $value;
diff --git a/test/TestAsset/HydratorStrategyEntityA.php b/test/TestAsset/HydratorStrategyEntityA.php
index a3d00f52..2e31fd12 100644
--- a/test/TestAsset/HydratorStrategyEntityA.php
+++ b/test/TestAsset/HydratorStrategyEntityA.php
@@ -9,7 +9,7 @@
class HydratorStrategyEntityA
{
/** @var HydratorStrategyEntityB[] */
- public $entities; // public to make testing easier!
+ public array $entities; // public to make testing easier!
public function __construct()
{
@@ -24,7 +24,7 @@ public function addEntity(HydratorStrategyEntityB $entity): void
/**
* @return HydratorStrategyEntityB[]
*/
- public function getEntities()
+ public function getEntities(): array
{
return $this->entities;
}
@@ -32,7 +32,7 @@ public function getEntities()
/**
* @param HydratorStrategyEntityB[] $entities
*/
- public function setEntities($entities): void
+ public function setEntities(array $entities): void
{
$this->entities = $entities;
}
@@ -50,10 +50,9 @@ public function getArrayCopy(): array
/**
* Add the populate method so we can test the ArraySerializable hydrator:
*
- * @param array $data
* @psalm-param array $data
*/
- public function populate($data): void
+ public function populate(array $data): void
{
foreach ($data as $name => $value) {
$this->$name = $value;
diff --git a/test/TestAsset/HydratorStrategyEntityB.php b/test/TestAsset/HydratorStrategyEntityB.php
index 1876a587..343c0c55 100644
--- a/test/TestAsset/HydratorStrategyEntityB.php
+++ b/test/TestAsset/HydratorStrategyEntityB.php
@@ -6,43 +6,27 @@
class HydratorStrategyEntityB
{
- /** @var mixed */
- private $field1;
-
- /** @var mixed */
- private $field2;
-
- /**
- * @param mixed $field1
- * @param mixed $field2
- */
- public function __construct($field1, $field2)
+ public function __construct(private mixed $field1, private mixed $field2)
{
- $this->field1 = $field1;
- $this->field2 = $field2;
}
- /** @return mixed */
- public function getField1()
+ public function getField1(): mixed
{
return $this->field1;
}
- /** @return mixed */
- public function getField2()
+ public function getField2(): mixed
{
return $this->field2;
}
- /** @param mixed $value */
- public function setField1($value): self
+ public function setField1(mixed $value): self
{
$this->field1 = $value;
return $this;
}
- /** @param mixed $value */
- public function setField2($value): self
+ public function setField2(mixed $value): self
{
$this->field2 = $value;
return $this;
diff --git a/test/TestAsset/ObjectProperty.php b/test/TestAsset/ObjectProperty.php
index 601d419f..93f5658c 100644
--- a/test/TestAsset/ObjectProperty.php
+++ b/test/TestAsset/ObjectProperty.php
@@ -9,20 +9,15 @@
#[AllowDynamicProperties]
class ObjectProperty
{
- /** @var string */
- public $foo;
+ public string $foo;
- /** @var string */
- public $bar;
+ public string $bar;
- /** @var string */
- public $blubb;
+ public string $blubb;
- /** @var string */
- public $quo;
+ public string $quo;
- /** @var string */
- protected $quin;
+ protected string $quin;
public function __construct()
{
diff --git a/test/TestAsset/Reflection.php b/test/TestAsset/Reflection.php
index df22b80c..2d30f145 100644
--- a/test/TestAsset/Reflection.php
+++ b/test/TestAsset/Reflection.php
@@ -6,11 +6,9 @@
class Reflection
{
- /** @var string */
- public $foo = '1';
+ public string $foo = '1';
- /** @var string */
- protected $fooBar = '2';
+ protected string $fooBar = '2';
private string $fooBarBaz = '3';
diff --git a/test/TestAsset/ReflectionFilter.php b/test/TestAsset/ReflectionFilter.php
index 67ff3136..c4e83ade 100644
--- a/test/TestAsset/ReflectionFilter.php
+++ b/test/TestAsset/ReflectionFilter.php
@@ -6,17 +6,13 @@
class ReflectionFilter
{
- /** @var string */
- protected $foo;
+ protected string $foo;
- /** @var string */
- protected $bar;
+ protected string $bar;
- /** @var string */
- protected $blubb;
+ protected string $blubb;
- /** @var string */
- protected $quo;
+ protected string $quo;
public function __construct()
{
diff --git a/test/TestAsset/SimpleEntity.php b/test/TestAsset/SimpleEntity.php
index 290bd148..32692c6d 100644
--- a/test/TestAsset/SimpleEntity.php
+++ b/test/TestAsset/SimpleEntity.php
@@ -8,32 +8,22 @@
class SimpleEntity
{
- /** @var mixed */
- public $value;
+ public mixed $value;
- /**
- * @param mixed $value
- * @return void
- */
- public function setValue($value)
+ public function setValue(mixed $value): void
{
$this->value = $value;
}
- /**
- * @return mixed
- */
- public function getValue()
+ public function getValue(): mixed
{
- return $this->value;
+ return $this->value ?? null;
}
/**
* Exchange internal values from provided array
- *
- * @return void
*/
- public function exchangeArray(array $array)
+ public function exchangeArray(array $array): void
{
if (array_key_exists('value', $array)) {
$this->setValue($array['value']);
@@ -42,10 +32,8 @@ public function exchangeArray(array $array)
/**
* Return an array representation of the object
- *
- * @return array
*/
- public function getArrayCopy()
+ public function getArrayCopy(): array
{
return ['value' => $this->getValue()];
}
diff --git a/test/TestAsset/User.php b/test/TestAsset/User.php
index 76f2df82..ae7e398f 100644
--- a/test/TestAsset/User.php
+++ b/test/TestAsset/User.php
@@ -8,10 +8,7 @@ final class User
{
private ?string $name = null;
- /**
- * @return string
- */
- public function name()
+ public function name(): ?string
{
return $this->name;
}