mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-16 08:02:23 +00:00
[Php71] Skip property with array doc filled by __construct on CountOnNullRector (#1208)
* [Php71] Skip property with array doc on CountOnNullRector
* rename fixture
* Fixed 🎉
* Trigger notification
* clean up
* rectify
This commit is contained in:
parent
cd217264b7
commit
48a97d51c4
|
@ -51,6 +51,7 @@ abstract class AbstractRectorTestCase extends AbstractTestCase implements Rector
|
|||
if (file_exists(__DIR__ . '/../../../preload.php') && file_exists(__DIR__ . '/../../../vendor')) {
|
||||
require_once __DIR__ . '/../../../preload.php';
|
||||
}
|
||||
|
||||
if (\file_exists(__DIR__ . '/../../../vendor/scoper-autoload.php')) {
|
||||
require_once __DIR__ . '/../../../vendor/scoper-autoload.php';
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Php71\Rector\FuncCall\CountOnNullRector\Fixture;
|
||||
|
||||
final class SkipPropertyArrayFilledByConstruct
|
||||
{
|
||||
/** @var array */
|
||||
private $property;
|
||||
|
||||
public function __construct(array $property)
|
||||
{
|
||||
$this->property = $property;
|
||||
}
|
||||
|
||||
public function run(): int
|
||||
{
|
||||
return count($this->property);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ use PHPStan\Reflection\PropertyReflection;
|
|||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
|
@ -24,7 +25,8 @@ final class CountableAnalyzer
|
|||
public function __construct(
|
||||
private NodeTypeResolver $nodeTypeResolver,
|
||||
private NodeNameResolver $nodeNameResolver,
|
||||
private ReflectionProvider $reflectionProvider
|
||||
private ReflectionProvider $reflectionProvider,
|
||||
private PropertyFetchAnalyzer $propertyFetchAnalyzer
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -78,6 +80,10 @@ final class CountableAnalyzer
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($this->propertyFetchAnalyzer->isFilledByConstructParam($expr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$propertyDefaultValue = $propertiesDefaults[$propertyName];
|
||||
return $propertyDefaultValue === null;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ final class PropertyFetchAnalyzer
|
|||
return $this->isLocalPropertyFetch($node->var);
|
||||
}
|
||||
|
||||
public function isFilledByConstructParam(Property $property): bool
|
||||
public function isFilledByConstructParam(Property|PropertyFetch|StaticPropertyFetch $property): bool
|
||||
{
|
||||
$class = $this->betterNodeFinder->findParentType($property, Class_::class);
|
||||
if (! $class instanceof Class_) {
|
||||
|
@ -150,10 +150,17 @@ final class PropertyFetchAnalyzer
|
|||
}
|
||||
|
||||
/** @var string $propertyName */
|
||||
$propertyName = $this->nodeNameResolver->getName($property->props[0]->name);
|
||||
$kindPropertyFetch = $property->isStatic()
|
||||
? StaticPropertyFetch::class
|
||||
: PropertyFetch::class;
|
||||
$propertyName = $property instanceof Property
|
||||
? $this->nodeNameResolver->getName($property->props[0]->name)
|
||||
: $this->nodeNameResolver->getName($property);
|
||||
|
||||
if ($property instanceof Property) {
|
||||
$kindPropertyFetch = $property->isStatic()
|
||||
? StaticPropertyFetch::class
|
||||
: PropertyFetch::class;
|
||||
} else {
|
||||
$kindPropertyFetch = $property::class;
|
||||
}
|
||||
|
||||
return $this->isParamFilledStmts($params, $stmts, $propertyName, $kindPropertyFetch);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user