2021-04-09 17:07:21 +02:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2021-04-09 17:07:21 +02:00
|
|
|
namespace Rector\Php70\NodeAnalyzer;
|
|
|
|
|
|
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
|
|
use PHPStan\Analyser\Scope;
|
|
|
|
use PHPStan\Reflection\ClassReflection;
|
|
|
|
use Rector\NodeTypeResolver\Node\AttributeKey;
|
|
|
|
final class Php4ConstructorClassMethodAnalyzer
|
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
public function detect(\PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
|
2021-04-09 17:07:21 +02:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
$scope = $classMethod->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
|
|
|
|
if (!$scope instanceof \PHPStan\Analyser\Scope) {
|
2021-05-09 20:15:43 +00:00
|
|
|
return \false;
|
2021-04-09 17:07:21 +02:00
|
|
|
}
|
|
|
|
// catch only classes without namespace
|
|
|
|
if ($scope->getNamespace() !== null) {
|
2021-05-09 20:15:43 +00:00
|
|
|
return \false;
|
2021-04-09 17:07:21 +02:00
|
|
|
}
|
|
|
|
if ($classMethod->isAbstract()) {
|
2021-05-09 20:15:43 +00:00
|
|
|
return \false;
|
2021-04-09 17:07:21 +02:00
|
|
|
}
|
|
|
|
if ($classMethod->isStatic()) {
|
2021-05-09 20:15:43 +00:00
|
|
|
return \false;
|
2021-04-09 17:07:21 +02:00
|
|
|
}
|
|
|
|
$classReflection = $scope->getClassReflection();
|
2021-05-10 22:23:08 +00:00
|
|
|
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
|
2021-05-09 20:15:43 +00:00
|
|
|
return \false;
|
2021-04-09 17:07:21 +02:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
return !$classReflection->isAnonymous();
|
2021-04-09 17:07:21 +02:00
|
|
|
}
|
|
|
|
}
|