Skip to content

Commit a593f14

Browse files
minor #60860 Move property accessor phpdoc to interface (VincentLanglet)
This PR was merged into the 7.2 branch. Discussion ---------- Move property accessor phpdoc to interface | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT This gives the same help for static analyser than #60374 but for the Interface. I targeted the 7.2 branch since it's the one the phpdoc was introduced. I copy the explanation: > This pull request was made to help static code analyzers understand that when calling PropertyAccessor::setValue, this will > not change the type of the passed $objectOrArray. > At the moment static analysis will point out that the value of $objectOrArray can be any object or an array after calling the > setValue method, which is of course not the case. > The solution comes directly from this closed PHPStan issue: phpstan/phpstan#12399 > (Other tools like Psalm also support `@param`-out) According to the Interface description this behavior shouldn't be restricted to PropertyAccessor but should be enforced/described in the interface too. Commits ------- 2e40d28 Move property accessor phpdoc to interface
2 parents e8401ca + 2e40d28 commit a593f14

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ public function getValue(object|array $objectOrArray, string|PropertyPathInterfa
109109
return $propertyValues[\count($propertyValues) - 1][self::VALUE];
110110
}
111111

112-
/**
113-
* @template T of object|array
114-
* @param T $objectOrArray
115-
* @param-out ($objectOrArray is array ? array : T) $objectOrArray
116-
*/
117112
public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value): void
118113
{
119114
if (\is_object($objectOrArray) && (false === strpbrk((string) $propertyPath, '.[') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {

src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ interface PropertyAccessorInterface
3939
*
4040
* If neither is found, an exception is thrown.
4141
*
42+
* @template T of object|array
43+
*
44+
* @param T $objectOrArray
45+
*
46+
* @param-out ($objectOrArray is array ? array : T) $objectOrArray
47+
*
4248
* @throws Exception\InvalidArgumentException If the property path is invalid
4349
* @throws Exception\AccessException If a property/index does not exist or is not public
4450
* @throws Exception\UnexpectedTypeException If a value within the path is neither object nor array

0 commit comments

Comments
 (0)