Skip to content

Commit a32bc86

Browse files
Add @param-out for PropertyAccessor
* Add param out for propertyAccessor * Fix stub
1 parent d8a0bc0 commit a32bc86

10 files changed

+79
-1
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require": {
1616
"php": "^7.2 || ^8.0",
1717
"ext-simplexml": "*",
18-
"phpstan/phpstan": "^1.10.36"
18+
"phpstan/phpstan": "^1.10.62"
1919
},
2020
"conflict": {
2121
"symfony/framework-bundle": "<3.0"

Diff for: extension.neon

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ parameters:
6666
- stubs/Symfony/Component/OptionsResolver/Exception/InvalidOptionsException.stub
6767
- stubs/Symfony/Component/OptionsResolver/Options.stub
6868
- stubs/Symfony/Component/Process/Process.stub
69+
- stubs/Symfony/Component/PropertyAccess/Exception/AccessException.stub
70+
- stubs/Symfony/Component/PropertyAccess/Exception/ExceptionInterface.stub
71+
- stubs/Symfony/Component/PropertyAccess/Exception/InvalidArgumentException.stub
72+
- stubs/Symfony/Component/PropertyAccess/Exception/RuntimeException.stub
73+
- stubs/Symfony/Component/PropertyAccess/Exception/UnexpectedTypeException.stub
74+
- stubs/Symfony/Component/PropertyAccess/PropertyAccessorInterface.stub
6975
- stubs/Symfony/Component/PropertyAccess/PropertyPathInterface.stub
7076
- stubs/Symfony/Component/Security/Acl/Model/AclInterface.stub
7177
- stubs/Symfony/Component/Security/Acl/Model/EntryInterface.stub
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyAccess\Exception;
4+
5+
class AccessException extends RuntimeException
6+
{
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyAccess\Exception;
4+
5+
interface ExceptionInterface extends \Throwable
6+
{
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyAccess\Exception;
4+
5+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
6+
{
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyAccess\Exception;
4+
5+
class RuntimeException extends \RuntimeException implements ExceptionInterface
6+
{
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyAccess\Exception;
4+
5+
class UnexpectedTypeException extends RuntimeException
6+
{
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyAccess;
4+
5+
interface PropertyAccessorInterface
6+
{
7+
8+
/**
9+
* @phpstan-template T of object|array<mixed>
10+
* @phpstan-param T &$objectOrArray
11+
* @phpstan-param-out ($objectOrArray is object ? T : array<mixed>) $objectOrArray
12+
* @phpstan-param string|PropertyPathInterface $propertyPath
13+
* @phpstan-param mixed $value
14+
*
15+
* @return void
16+
*
17+
* @throws Exception\InvalidArgumentException If the property path is invalid
18+
* @throws Exception\AccessException If a property/index does not exist or is not public
19+
* @throws Exception\UnexpectedTypeException If a value within the path is neither object nor array
20+
*/
21+
public function setValue(&$objectOrArray, $propertyPath, $value);
22+
23+
}

Diff for: tests/Type/Symfony/ExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function dataFileAsserts(): iterable
2828
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleOptionCommand.php');
2929
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleOptionLazyCommand.php');
3030
yield from $this->gatherAssertTypes(__DIR__ . '/data/kernel_interface.php');
31+
yield from $this->gatherAssertTypes(__DIR__ . '/data/property_accessor.php');
3132
yield from $this->gatherAssertTypes(__DIR__ . '/data/request_get_content.php');
3233

3334
$ref = new ReflectionMethod(Request::class, 'getSession');

Diff for: tests/Type/Symfony/data/property_accessor.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
use function PHPStan\Testing\assertType;
4+
5+
$propertyAccessor = new \Symfony\Component\PropertyAccess\PropertyAccessor();
6+
7+
$array = [1 => 'ea'];
8+
$propertyAccessor->setValue($array, 'foo', 'bar');
9+
assertType('array', $array);
10+
11+
$object = new \stdClass();
12+
$propertyAccessor->setValue($object, 'foo', 'bar');
13+
assertType('stdClass', $object);

0 commit comments

Comments
 (0)