Added stub for PropertyAccessorInterface::setValue() (#76)

* Added stub for PropertyAccessorInterface::setValue()

* Update src/Stubs/common/PropertyAccessorInterface.stubphp

Co-authored-by: Farhad Safarov <farhad.safarov@gmail.com>
This commit is contained in:
Wouter J 2020-09-13 19:03:33 +02:00 committed by GitHub
parent 4eb4dae6ea
commit 00bae73943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,39 @@
<?php
namespace Symfony\Component\PropertyAccess;
interface PropertyAccessorInterface
{
/**
* @template T as object|array
* @psalm-param T $objectOrArray
* @psalm-param string|PropertyPathInterface $propertyPath
* @psalm-param mixed $value
* @psalm-self-out T $objectOrArray
*/
public function setValue(&$objectOrArray, $propertyPath, $value);
/**
* @param object|array $objectOrArray
* @param string|PropertyPathInterface $propertyPath
*
* @return mixed
*/
public function getValue($objectOrArray, $propertyPath);
/**
* @param object|array $objectOrArray
* @param string|PropertyPathInterface $propertyPath
*
* @return bool
*/
public function isWritable($objectOrArray, $propertyPath);
/**
* @param object|array $objectOrArray
* @param string|PropertyPathInterface $propertyPath
*
* @return bool
*/
public function isReadable($objectOrArray, $propertyPath);
}

View File

@ -0,0 +1,53 @@
@symfony-common
Feature: PropertyAccessorInterface
Background:
Given I have the following config
"""
<?xml version="1.0"?>
<psalm errorLevel="1">
<projectFiles>
<directory name="."/>
</projectFiles>
<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins>
</psalm>
"""
And I have the following code preamble
"""
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
$propertyAccessor = PropertyAccess::createPropertyAccessor();
"""
Scenario: Set value keeps array type if array is passed
Given I have the following code
"""
$company = ['name' => 'Acme'];
$propertyAccessor->setValue($company, 'name', 'Acme v2');
array_key_exists('name', $company);
"""
When I run Psalm
Then I see no errors
Scenario: Set value keeps object instance if an object is passed
Given I have the following code
"""
class Company
{
public string $name = 'Acme';
}
$company = new Company();
$propertyAccessor->setValue($company, 'name', 'Acme v2');
echo $company->name;
"""
When I run Psalm
Then I see no errors