REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 5.91 KB
Close
//opt/cpanel/ea-wappspector/vendor/rector/rector/src/NodeAnalyzer/PropertyPresenceChecker.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\NodeAnalyzer; use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Property; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\Php\PhpPropertyReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\Type; use PHPStan\Type\TypeWithClassName; use Rector\NodeNameResolver\NodeNameResolver; use Rector\Php80\NodeAnalyzer\PromotedPropertyResolver; use Rector\PhpParser\AstResolver; use Rector\PostRector\ValueObject\PropertyMetadata; /** * Can be local property, parent property etc. */ final class PropertyPresenceChecker { /** * @readonly * @var \Rector\Php80\NodeAnalyzer\PromotedPropertyResolver */ private $promotedPropertyResolver; /** * @readonly * @var \Rector\NodeNameResolver\NodeNameResolver */ private $nodeNameResolver; /** * @readonly * @var \PHPStan\Reflection\ReflectionProvider */ private $reflectionProvider; /** * @readonly * @var \Rector\PhpParser\AstResolver */ private $astResolver; public function __construct(PromotedPropertyResolver $promotedPropertyResolver, NodeNameResolver $nodeNameResolver, ReflectionProvider $reflectionProvider, AstResolver $astResolver) { $this->promotedPropertyResolver = $promotedPropertyResolver; $this->nodeNameResolver = $nodeNameResolver; $this->reflectionProvider = $reflectionProvider; $this->astResolver = $astResolver; } /** * Includes parent classes and traits */ public function hasClassContextProperty(Class_ $class, PropertyMetadata $propertyMetadata) : bool { $propertyOrParam = $this->getClassContextProperty($class, $propertyMetadata); return $propertyOrParam !== null; } /** * @return \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param|null */ public function getClassContextProperty(Class_ $class, PropertyMetadata $propertyMetadata) { $className = $this->nodeNameResolver->getName($class); if ($className === null) { return null; } $property = $class->getProperty($propertyMetadata->getName()); if ($property instanceof Property) { return $property; } $property = $this->matchPropertyByParentNonPrivateProperties($className, $propertyMetadata); if ($property instanceof Property || $property instanceof Param) { return $property; } $promotedPropertyParams = $this->promotedPropertyResolver->resolveFromClass($class); foreach ($promotedPropertyParams as $promotedPropertyParam) { if ($this->nodeNameResolver->isName($promotedPropertyParam, $propertyMetadata->getName())) { return $promotedPropertyParam; } } return null; } /** * @return PhpPropertyReflection[] */ private function getParentClassNonPrivatePropertyReflections(string $className) : array { if (!$this->reflectionProvider->hasClass($className)) { return []; } $classReflection = $this->reflectionProvider->getClass($className); $propertyReflections = []; foreach ($classReflection->getParents() as $parentClassReflection) { $propertyNames = $this->resolveNonPrivatePropertyNames($parentClassReflection); foreach ($propertyNames as $propertyName) { $propertyReflections[] = $parentClassReflection->getNativeProperty($propertyName); } } return $propertyReflections; } /** * @return \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param|null */ private function matchPropertyByType(PropertyMetadata $propertyMetadata, PhpPropertyReflection $phpPropertyReflection) { if (!$propertyMetadata->getType() instanceof Type) { return null; } if (!$propertyMetadata->getType() instanceof TypeWithClassName) { return null; } if (!$phpPropertyReflection->getWritableType() instanceof TypeWithClassName) { return null; } $propertyObjectTypeWithClassName = $propertyMetadata->getType(); if (!$propertyObjectTypeWithClassName->equals($phpPropertyReflection->getWritableType())) { return null; } return $this->astResolver->resolvePropertyFromPropertyReflection($phpPropertyReflection); } /** * @return \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param|null */ private function matchPropertyByParentNonPrivateProperties(string $className, PropertyMetadata $propertyMetadata) { $availablePropertyReflections = $this->getParentClassNonPrivatePropertyReflections($className); foreach ($availablePropertyReflections as $availablePropertyReflection) { // 1. match type by priority $property = $this->matchPropertyByType($propertyMetadata, $availablePropertyReflection); if ($property instanceof Property || $property instanceof Param) { return $property; } $nativePropertyReflection = $availablePropertyReflection->getNativeReflection(); // 2. match by name if ($nativePropertyReflection->getName() === $propertyMetadata->getName()) { return $this->astResolver->resolvePropertyFromPropertyReflection($availablePropertyReflection); } } return null; } /** * @return string[] */ private function resolveNonPrivatePropertyNames(ClassReflection $classReflection) : array { $propertyNames = []; $nativeReflection = $classReflection->getNativeReflection(); foreach ($nativeReflection->getProperties() as $reflectionProperty) { if ($reflectionProperty->isPrivate()) { continue; } $propertyNames[] = $reflectionProperty->getName(); } return $propertyNames; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 17
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
ArgsAnalyzer.php
418 B
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
BinaryOpAnalyzer.php
1.14 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CallAnalyzer.php
2.37 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ClassAnalyzer.php
463 B
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CompactFuncCallAnalyzer.php
2.06 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ConstFetchAnalyzer.php
1.02 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
DoctrineEntityAnalyzer.php
1.99 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ExprAnalyzer.php
3.62 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
MagicClassMethodAnalyzer.php
717 B
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ParamAnalyzer.php
5.39 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
PropertyAnalyzer.php
1.66 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
PropertyFetchAnalyzer.php
7.38 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
PropertyPresenceChecker.php
5.91 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ScopeAnalyzer.php
683 B
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
TerminatedNodeAnalyzer.php
5.25 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
VariableAnalyzer.php
603 B
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
VariadicAnalyzer.php
1.51 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).