mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
503a6059f8
a8922f7431
skip temporarily match + throws downagrade in symfony/console, very unlikely to run
42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Naming\Guard;
|
|
|
|
use DateTimeInterface;
|
|
use PHPStan\Type\TypeWithClassName;
|
|
use Rector\Core\Util\StringUtils;
|
|
use Rector\Naming\ValueObject\PropertyRename;
|
|
use Rector\NodeTypeResolver\NodeTypeResolver;
|
|
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
|
final class DateTimeAtNamingConventionGuard
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
|
*/
|
|
private $nodeTypeResolver;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper
|
|
*/
|
|
private $typeUnwrapper;
|
|
public function __construct(NodeTypeResolver $nodeTypeResolver, TypeUnwrapper $typeUnwrapper)
|
|
{
|
|
$this->nodeTypeResolver = $nodeTypeResolver;
|
|
$this->typeUnwrapper = $typeUnwrapper;
|
|
}
|
|
public function isConflicting(PropertyRename $propertyRename) : bool
|
|
{
|
|
$type = $this->nodeTypeResolver->getType($propertyRename->getProperty());
|
|
$type = $this->typeUnwrapper->unwrapFirstObjectTypeFromUnionType($type);
|
|
if (!$type instanceof TypeWithClassName) {
|
|
return \false;
|
|
}
|
|
if (!\is_a($type->getClassName(), DateTimeInterface::class, \true)) {
|
|
return \false;
|
|
}
|
|
return StringUtils::isMatch($propertyRename->getCurrentName(), \Rector\Naming\Guard\BreakingVariableRenameGuard::AT_NAMING_REGEX . '');
|
|
}
|
|
}
|