mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2024-11-27 04:14:56 +01:00
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:
parent
4eb4dae6ea
commit
00bae73943
39
src/Stubs/common/PropertyAccessorInterface.stubphp
Normal file
39
src/Stubs/common/PropertyAccessorInterface.stubphp
Normal 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);
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue
Block a user