From 38e3a204ef726d3a6c9a47d3ba9c04a3134ffd7c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 May 2023 17:24:39 +0200 Subject: [PATCH 1/5] [7.0] Bump to PHP 8.2 minimum --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index ce7710c..95258ff 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ } ], "require": { - "php": ">=8.1", + "php": ">=8.2", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/property-info": "^5.4|^6.0|^7.0" + "symfony/property-info": "^6.4|^7.0" }, "require-dev": { - "symfony/cache": "^5.4|^6.0|^7.0" + "symfony/cache": "^6.4|^7.0" }, "autoload": { "psr-4": { "Symfony\\Component\\PropertyAccess\\": "" }, From 7045e689cfaff60d07a5622b59d4f5b90e49ccef Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 30 Jun 2023 18:53:02 +0200 Subject: [PATCH 2/5] Remove BC layers related to new methods and new parameters --- CHANGELOG.md | 5 +++++ PropertyPathInterface.php | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a48ed82..3d51596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.0 +--- + + * Add method `isNullSafe()` to `PropertyPathInterface` + 6.3 --- diff --git a/PropertyPathInterface.php b/PropertyPathInterface.php index 11f6ed4..9502b1a 100644 --- a/PropertyPathInterface.php +++ b/PropertyPathInterface.php @@ -16,8 +16,6 @@ * * @author Bernhard Schussek * - * @method bool isNullSafe(int $index) Returns whether the element at the given index is null safe. Not implementing it is deprecated since Symfony 6.2 - * * @extends \Traversable */ interface PropertyPathInterface extends \Traversable @@ -85,4 +83,9 @@ public function isProperty(int $index); * @throws Exception\OutOfBoundsException If the offset is invalid */ public function isIndex(int $index); + + /** + * Returns whether the element at the given index is null safe. + */ + public function isNullSafe(int $index): bool; } From cf8f78fdd5dcc2bc11667e43aee40b20a7036071 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 4 Jul 2023 14:50:59 +0200 Subject: [PATCH 3/5] [7.0] Remove remaining deprecated code paths --- CHANGELOG.md | 1 + PropertyAccessor.php | 9 +-------- PropertyAccessorBuilder.php | 5 +---- composer.json | 1 - 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d51596..0dacd60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Add method `isNullSafe()` to `PropertyPathInterface` + * Require explicit argument when calling `PropertyAccessorBuilder::setCacheItemPool()` 6.3 --- diff --git a/PropertyAccessor.php b/PropertyAccessor.php index 0bf5c0a..ac45dbe 100644 --- a/PropertyAccessor.php +++ b/PropertyAccessor.php @@ -290,14 +290,7 @@ private function readPropertiesUntil(array $zval, PropertyPathInterface $propert for ($i = 0; $i < $lastIndex; ++$i) { $property = $propertyPath->getElement($i); $isIndex = $propertyPath->isIndex($i); - - $isNullSafe = false; - if (method_exists($propertyPath, 'isNullSafe')) { - // To be removed in symfony 7 once we are sure isNullSafe is always implemented. - $isNullSafe = $propertyPath->isNullSafe($i); - } else { - trigger_deprecation('symfony/property-access', '6.2', 'The "%s()" method in class "%s" needs to be implemented in version 7.0, not defining it is deprecated.', 'isNullSafe', PropertyPathInterface::class); - } + $isNullSafe = $propertyPath->isNullSafe($i); if ($isIndex) { // Create missing nested arrays on demand diff --git a/PropertyAccessorBuilder.php b/PropertyAccessorBuilder.php index 51362af..3a62b44 100644 --- a/PropertyAccessorBuilder.php +++ b/PropertyAccessorBuilder.php @@ -239,11 +239,8 @@ public function isExceptionOnInvalidPropertyPath(): bool * * @return $this */ - public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool = null): static + public function setCacheItemPool(?CacheItemPoolInterface $cacheItemPool): static { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/property-access', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } $this->cacheItemPool = $cacheItemPool; return $this; diff --git a/composer.json b/composer.json index 95258ff..376ee7e 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ ], "require": { "php": ">=8.2", - "symfony/deprecation-contracts": "^2.5|^3", "symfony/property-info": "^6.4|^7.0" }, "require-dev": { From 3c2fe6d61ea2fc9dc852d30bc8c021d109e78b45 Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Sun, 2 Jul 2023 23:52:21 +0200 Subject: [PATCH 4/5] [Components] Convert to native return types --- PropertyAccessor.php | 5 +---- PropertyAccessorInterface.php | 4 +--- PropertyPathBuilder.php | 28 +++++++--------------------- PropertyPathInterface.php | 22 ++++++---------------- Tests/Fixtures/TestClassMagicGet.php | 2 +- Tests/Fixtures/Ticket5775Object.php | 2 +- 6 files changed, 17 insertions(+), 46 deletions(-) diff --git a/PropertyAccessor.php b/PropertyAccessor.php index ac45dbe..c34b88f 100644 --- a/PropertyAccessor.php +++ b/PropertyAccessor.php @@ -119,10 +119,7 @@ public function getValue(object|array $objectOrArray, string|PropertyPathInterfa return $propertyValues[\count($propertyValues) - 1][self::VALUE]; } - /** - * @return void - */ - public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value) + public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value): void { if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) { $zval = [ diff --git a/PropertyAccessorInterface.php b/PropertyAccessorInterface.php index 8336df4..2e25e9e 100644 --- a/PropertyAccessorInterface.php +++ b/PropertyAccessorInterface.php @@ -42,10 +42,8 @@ interface PropertyAccessorInterface * @throws Exception\InvalidArgumentException If the property path is invalid * @throws Exception\AccessException If a property/index does not exist or is not public * @throws Exception\UnexpectedTypeException If a value within the path is neither object nor array - * - * @return void */ - public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value); + public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value): void; /** * Returns the value at the end of the property path of the object graph. diff --git a/PropertyPathBuilder.php b/PropertyPathBuilder.php index a0154bd..a246f31 100644 --- a/PropertyPathBuilder.php +++ b/PropertyPathBuilder.php @@ -33,10 +33,8 @@ public function __construct(PropertyPathInterface|string $path = null) * * @param int $offset The offset where the appended piece starts in $path * @param int $length The length of the appended piece; if 0, the full path is appended - * - * @return void */ - public function append(PropertyPathInterface|string $path, int $offset = 0, int $length = 0) + public function append(PropertyPathInterface|string $path, int $offset = 0, int $length = 0): void { if (\is_string($path)) { $path = new PropertyPath($path); @@ -56,10 +54,8 @@ public function append(PropertyPathInterface|string $path, int $offset = 0, int /** * Appends an index element to the current path. - * - * @return void */ - public function appendIndex(string $name) + public function appendIndex(string $name): void { $this->elements[] = $name; $this->isIndex[] = true; @@ -67,10 +63,8 @@ public function appendIndex(string $name) /** * Appends a property element to the current path. - * - * @return void */ - public function appendProperty(string $name) + public function appendProperty(string $name): void { $this->elements[] = $name; $this->isIndex[] = false; @@ -79,11 +73,9 @@ public function appendProperty(string $name) /** * Removes elements from the current path. * - * @return void - * * @throws OutOfBoundsException if offset is invalid */ - public function remove(int $offset, int $length = 1) + public function remove(int $offset, int $length = 1): void { if (!isset($this->elements[$offset])) { throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset)); @@ -98,11 +90,9 @@ public function remove(int $offset, int $length = 1) * @param int $pathOffset The offset where the inserted piece starts in $path * @param int $pathLength The length of the inserted piece; if 0, the full path is inserted * - * @return void - * * @throws OutOfBoundsException If the offset is invalid */ - public function replace(int $offset, int $length, PropertyPathInterface|string $path, int $pathOffset = 0, int $pathLength = 0) + public function replace(int $offset, int $length, PropertyPathInterface|string $path, int $pathOffset = 0, int $pathLength = 0): void { if (\is_string($path)) { $path = new PropertyPath($path); @@ -130,11 +120,9 @@ public function replace(int $offset, int $length, PropertyPathInterface|string $ /** * Replaces a property element by an index element. * - * @return void - * * @throws OutOfBoundsException If the offset is invalid */ - public function replaceByIndex(int $offset, string $name = null) + public function replaceByIndex(int $offset, string $name = null): void { if (!isset($this->elements[$offset])) { throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset)); @@ -150,11 +138,9 @@ public function replaceByIndex(int $offset, string $name = null) /** * Replaces an index element by a property element. * - * @return void - * * @throws OutOfBoundsException If the offset is invalid */ - public function replaceByProperty(int $offset, string $name = null) + public function replaceByProperty(int $offset, string $name = null): void { if (!isset($this->elements[$offset])) { throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset)); diff --git a/PropertyPathInterface.php b/PropertyPathInterface.php index 9502b1a..a8c9400 100644 --- a/PropertyPathInterface.php +++ b/PropertyPathInterface.php @@ -27,10 +27,8 @@ public function __toString(): string; /** * Returns the length of the property path, i.e. the number of elements. - * - * @return int */ - public function getLength(); + public function getLength(): int; /** * Returns the parent property path. @@ -39,50 +37,42 @@ public function getLength(); * this one except for the last one. * * If this property path only contains one item, null is returned. - * - * @return self|null */ - public function getParent(); + public function getParent(): ?self; /** * Returns the elements of the property path as array. * * @return list */ - public function getElements(); + public function getElements(): array; /** * Returns the element at the given index in the property path. * * @param int $index The index key * - * @return string - * * @throws Exception\OutOfBoundsException If the offset is invalid */ - public function getElement(int $index); + public function getElement(int $index): string; /** * Returns whether the element at the given index is a property. * * @param int $index The index in the property path * - * @return bool - * * @throws Exception\OutOfBoundsException If the offset is invalid */ - public function isProperty(int $index); + public function isProperty(int $index): bool; /** * Returns whether the element at the given index is an array index. * * @param int $index The index in the property path * - * @return bool - * * @throws Exception\OutOfBoundsException If the offset is invalid */ - public function isIndex(int $index); + public function isIndex(int $index): bool; /** * Returns whether the element at the given index is null safe. diff --git a/Tests/Fixtures/TestClassMagicGet.php b/Tests/Fixtures/TestClassMagicGet.php index d1e4d23..50f3296 100644 --- a/Tests/Fixtures/TestClassMagicGet.php +++ b/Tests/Fixtures/TestClassMagicGet.php @@ -22,7 +22,7 @@ public function __construct($value) $this->magicProperty = $value; } - public function __set(string $property, $value) + public function __set(string $property, $value): void { if ('magicProperty' === $property) { $this->magicProperty = $value; diff --git a/Tests/Fixtures/Ticket5775Object.php b/Tests/Fixtures/Ticket5775Object.php index d154f55..280e1dc 100644 --- a/Tests/Fixtures/Ticket5775Object.php +++ b/Tests/Fixtures/Ticket5775Object.php @@ -24,7 +24,7 @@ private function setProperty() { } - public function __set(string $property, $value) + public function __set(string $property, $value): void { $this->$property = $value; } From 3778e819115bcb5166e2ab95a0d30dae6481647d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 21 Jul 2023 15:36:26 +0200 Subject: [PATCH 5/5] Add types to public and protected properties --- PropertyPathIterator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PropertyPathIterator.php b/PropertyPathIterator.php index 0312ba1..5f140e0 100644 --- a/PropertyPathIterator.php +++ b/PropertyPathIterator.php @@ -21,7 +21,7 @@ */ class PropertyPathIterator extends \ArrayIterator implements PropertyPathIteratorInterface { - protected $path; + protected PropertyPathInterface $path; public function __construct(PropertyPathInterface $path) {