?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/Php82.tar
???????
Rector/Param/AddSensitiveParameterAttributeRector.php 0000644 00000005354 15127513543 0017056 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php82\Rector\Param; use PhpParser\Node; use PhpParser\Node\Attribute; use PhpParser\Node\AttributeGroup; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Param; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use RectorPrefix202411\Webmozart\Assert\Assert; /** * @see \Rector\Tests\Php82\Rector\Param\AddSensitiveParameterAttributeRector\AddSensitiveParameterAttributeRectorTest */ final class AddSensitiveParameterAttributeRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface { /** * @readonly * @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer */ private $phpAttributeAnalyzer; public const SENSITIVE_PARAMETERS = 'sensitive_parameters'; /** * @var string[] */ private $sensitiveParameters = []; public function __construct(PhpAttributeAnalyzer $phpAttributeAnalyzer) { $this->phpAttributeAnalyzer = $phpAttributeAnalyzer; } /** * @param mixed[] $configuration */ public function configure(array $configuration) : void { Assert::allString($configuration[self::SENSITIVE_PARAMETERS] ?? []); $this->sensitiveParameters = (array) ($configuration[self::SENSITIVE_PARAMETERS] ?? []); } public function getNodeTypes() : array { return [Param::class]; } /** * @param Node\Param $node */ public function refactor(Node $node) : ?Param { if (!$this->isNames($node, $this->sensitiveParameters)) { return null; } if ($this->phpAttributeAnalyzer->hasPhpAttribute($node, 'SensitiveParameter')) { return null; } $node->attrGroups[] = new AttributeGroup([new Attribute(new FullyQualified('SensitiveParameter'))]); return $node; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Add SensitiveParameter attribute to method and function configured parameters', [new ConfiguredCodeSample(<<<'CODE_SAMPLE' class SomeClass { public function run(string $password) { } } CODE_SAMPLE , <<<'CODE_SAMPLE' class SomeClass { public function run(#[\SensitiveParameter] string $password) { } } CODE_SAMPLE , [self::SENSITIVE_PARAMETERS => ['password']])]); } public function provideMinPhpVersion() : int { return PhpVersionFeature::SENSITIVE_PARAMETER_ATTRIBUTE; } } Rector/Class_/ReadOnlyClassRector.php 0000644 00000022004 15127513543 0013605 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php82\Rector\Class_; use PhpParser\Node; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; use PHPStan\Analyser\Scope; use PHPStan\BetterReflection\Reflection\Adapter\ReflectionProperty; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ReflectionProvider; use Rector\NodeAnalyzer\ClassAnalyzer; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; use Rector\Php81\Enum\AttributeName; use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Rector\AbstractScopeAwareRector; use Rector\ValueObject\MethodName; use Rector\ValueObject\PhpVersionFeature; use Rector\ValueObject\Visibility; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\ReadOnlyClassRectorTest */ final class ReadOnlyClassRector extends AbstractScopeAwareRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\NodeAnalyzer\ClassAnalyzer */ private $classAnalyzer; /** * @readonly * @var \Rector\Privatization\NodeManipulator\VisibilityManipulator */ private $visibilityManipulator; /** * @readonly * @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer */ private $phpAttributeAnalyzer; /** * @readonly * @var \PHPStan\Reflection\ReflectionProvider */ private $reflectionProvider; public function __construct(ClassAnalyzer $classAnalyzer, VisibilityManipulator $visibilityManipulator, PhpAttributeAnalyzer $phpAttributeAnalyzer, ReflectionProvider $reflectionProvider) { $this->classAnalyzer = $classAnalyzer; $this->visibilityManipulator = $visibilityManipulator; $this->phpAttributeAnalyzer = $phpAttributeAnalyzer; $this->reflectionProvider = $reflectionProvider; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Decorate read-only class with `readonly` attribute', [new CodeSample(<<<'CODE_SAMPLE' final class SomeClass { public function __construct( private readonly string $name ) { } } CODE_SAMPLE , <<<'CODE_SAMPLE' final readonly class SomeClass { public function __construct( private string $name ) { } } CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Class_::class]; } /** * @param Class_ $node */ public function refactorWithScope(Node $node, Scope $scope) : ?Node { if ($this->shouldSkip($node, $scope)) { return null; } $this->visibilityManipulator->makeReadonly($node); $constructClassMethod = $node->getMethod(MethodName::CONSTRUCT); if ($constructClassMethod instanceof ClassMethod) { foreach ($constructClassMethod->getParams() as $param) { $this->visibilityManipulator->removeReadonly($param); if ($param->attrGroups !== []) { // invoke reprint with correct newline $param->setAttribute(AttributeKey::ORIGINAL_NODE, null); } } } foreach ($node->getProperties() as $property) { $this->visibilityManipulator->removeReadonly($property); if ($property->attrGroups !== []) { // invoke reprint with correct newline $property->setAttribute(AttributeKey::ORIGINAL_NODE, null); } } if ($node->attrGroups !== []) { // invoke reprint with correct readonly newline $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); } return $node; } public function provideMinPhpVersion() : int { return PhpVersionFeature::READONLY_CLASS; } /** * @return ClassReflection[] */ private function resolveParentClassReflections(Scope $scope) : array { $classReflection = $scope->getClassReflection(); if (!$classReflection instanceof ClassReflection) { return []; } return $classReflection->getParents(); } /** * @param Property[] $properties */ private function hasNonTypedProperty(array $properties) : bool { foreach ($properties as $property) { // properties of readonly class must always have type if ($property->type === null) { return \true; } } return \false; } private function shouldSkip(Class_ $class, Scope $scope) : bool { $classReflection = $scope->getClassReflection(); if (!$classReflection instanceof ClassReflection) { return \true; } if ($this->shouldSkipClass($class)) { return \true; } $parents = $this->resolveParentClassReflections($scope); if (!$class->isFinal()) { return !$this->isExtendsReadonlyClass($parents); } foreach ($parents as $parent) { if (!$parent->isReadOnly()) { return \true; } } $properties = $class->getProperties(); if ($this->hasWritableProperty($properties)) { return \true; } if ($this->hasNonTypedProperty($properties)) { return \true; } if ($this->shouldSkipConsumeTraitProperty($class)) { return \true; } $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); if (!$constructClassMethod instanceof ClassMethod) { // no __construct means no property promotion, skip if class has no property defined return $properties === []; } $params = $constructClassMethod->getParams(); if ($params === []) { // no params means no property promotion, skip if class has no property defined return $properties === []; } return $this->shouldSkipParams($params); } private function shouldSkipConsumeTraitProperty(Class_ $class) : bool { $traitUses = $class->getTraitUses(); foreach ($traitUses as $traitUse) { foreach ($traitUse->traits as $trait) { $traitName = $trait->toString(); // trait not autoloaded if (!$this->reflectionProvider->hasClass($traitName)) { return \true; } $traitClassReflection = $this->reflectionProvider->getClass($traitName); $nativeReflection = $traitClassReflection->getNativeReflection(); if ($this->hasReadonlyProperty($nativeReflection->getProperties())) { return \true; } } } return \false; } /** * @param ReflectionProperty[] $properties */ private function hasReadonlyProperty(array $properties) : bool { foreach ($properties as $property) { if (!$property->isReadOnly()) { return \true; } } return \false; } /** * @param ClassReflection[] $parents */ private function isExtendsReadonlyClass(array $parents) : bool { foreach ($parents as $parent) { if ($parent->isReadOnly()) { return \true; } } return \false; } /** * @param Property[] $properties */ private function hasWritableProperty(array $properties) : bool { foreach ($properties as $property) { if (!$property->isReadonly()) { return \true; } } return \false; } private function shouldSkipClass(Class_ $class) : bool { // need to have test fixture once feature added to nikic/PHP-Parser if ($this->visibilityManipulator->hasVisibility($class, Visibility::READONLY)) { return \true; } if ($this->classAnalyzer->isAnonymousClass($class)) { return \true; } if ($this->phpAttributeAnalyzer->hasPhpAttribute($class, AttributeName::ALLOW_DYNAMIC_PROPERTIES)) { return \true; } return $class->extends instanceof FullyQualified && !$this->reflectionProvider->hasClass($class->extends->toString()); } /** * @param Param[] $params */ private function shouldSkipParams(array $params) : bool { foreach ($params as $param) { // has non-readonly property promotion if (!$this->visibilityManipulator->hasVisibility($param, Visibility::READONLY) && $param->flags !== 0) { return \true; } // type is missing, invalid syntax if ($param->type === null) { return \true; } } return \false; } } Rector/Encapsed/VariableInStringInterpolationFixerRector.php 0000644 00000004203 15127513543 0020372 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php82\Rector\Encapsed; use PhpParser\Node; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\Encapsed; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php82\Rector\Encapsed\VariableInStringInterpolationFixerRector\VariableInStringInterpolationFixerRectorTest */ final class VariableInStringInterpolationFixerRector extends AbstractRector implements MinPhpVersionInterface { public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Replace deprecated "${var}" to "{$var}"', [new CodeSample(<<<'CODE_SAMPLE' $c = "football"; echo "I like playing ${c}"; CODE_SAMPLE , <<<'CODE_SAMPLE' $c = "football"; echo "I like playing {$c}"; CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Encapsed::class]; } /** * @param Encapsed $node */ public function refactor(Node $node) : ?Node { $oldTokens = $this->file->getOldTokens(); $hasChanged = \false; foreach ($node->parts as $part) { if (!$part instanceof Variable) { continue; } $startTokenPos = $part->getStartTokenPos(); if (!isset($oldTokens[$startTokenPos])) { continue; } if (!\is_array($oldTokens[$startTokenPos])) { continue; } if ($oldTokens[$startTokenPos][1] !== '${') { continue; } $part->setAttribute(AttributeKey::ORIGINAL_NODE, null); $hasChanged = \true; } if (!$hasChanged) { return null; } return $node; } public function provideMinPhpVersion() : int { return PhpVersionFeature::DEPRECATE_VARIABLE_IN_STRING_INTERPOLATION; } } Rector/New_/FilesystemIteratorSkipDotsRector.php 0000644 00000006551 15127513543 0016116 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php82\Rector\New_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\BitwiseOr; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\New_; use PhpParser\Node\Name\FullyQualified; use PHPStan\Type\ObjectType; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php82\Rector\New_\FilesystemIteratorSkipDotsRector\FilesystemIteratorSkipDotsRectorTest */ final class FilesystemIteratorSkipDotsRector extends AbstractRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\PhpParser\Node\Value\ValueResolver */ private $valueResolver; public function __construct(ValueResolver $valueResolver) { $this->valueResolver = $valueResolver; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Prior PHP 8.2 FilesystemIterator::SKIP_DOTS was always set and could not be removed, therefore FilesystemIterator::SKIP_DOTS is added in order to keep this behaviour.', [new CodeSample('new FilesystemIterator(__DIR__, FilesystemIterator::KEY_AS_FILENAME);', 'new FilesystemIterator(__DIR__, FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::SKIP_DOTS);')]); } public function getNodeTypes() : array { return [New_::class]; } /** * Add {@see \FilesystemIterator::SKIP_DOTS} to $node when required. * * @param New_ $node */ public function refactor(Node $node) : ?New_ { if ($node->isFirstClassCallable()) { return null; } if (!$this->isObjectType($node->class, new ObjectType('FilesystemIterator'))) { return null; } if (!isset($node->args[1])) { return null; } $flags = $node->getArgs()[1]->value; if ($this->isSkipDotsPresent($flags)) { return null; } $classConstFetch = new ClassConstFetch(new FullyQualified('FilesystemIterator'), 'SKIP_DOTS'); $node->args[1] = new Arg(new BitwiseOr($flags, $classConstFetch)); return $node; } public function provideMinPhpVersion() : int { return PhpVersionFeature::FILESYSTEM_ITERATOR_SKIP_DOTS; } /** * Is the constant {@see \FilesystemIterator::SKIP_DOTS} present within $node? */ private function isSkipDotsPresent(Expr $expr) : bool { while ($expr instanceof BitwiseOr) { if ($this->isSkipDots($expr->right)) { return \true; } $expr = $expr->left; } return $this->isSkipDots($expr); } /** * Tells if $expr is equal to {@see \FilesystemIterator::SKIP_DOTS}. */ private function isSkipDots(Expr $expr) : bool { if (!$expr instanceof ClassConstFetch) { // can be anything return \true; } if (!\defined('FilesystemIterator::SKIP_DOTS')) { return \true; } $value = \constant('FilesystemIterator::SKIP_DOTS'); return $this->valueResolver->isValue($expr, $value); } } Rector/FuncCall/Utf8DecodeEncodeToMbConvertEncodingRector.php 0000644 00000004106 15127513543 0020232 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php82\Rector\FuncCall; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; use PhpParser\Node\Scalar\String_; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see https://3v4l.org/Q14UR * @see \Rector\Tests\Php82\Rector\FuncCall\Utf8DecodeEncodeToMbConvertEncodingRector\Utf8DecodeEncodeToMbConvertEncodingRectorTest */ final class Utf8DecodeEncodeToMbConvertEncodingRector extends AbstractRector implements MinPhpVersionInterface { public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Change deprecated utf8_decode and utf8_encode to mb_convert_encoding', [new CodeSample(<<<'CODE_SAMPLE' utf8_decode($value); utf8_encode($value); CODE_SAMPLE , <<<'CODE_SAMPLE' mb_convert_encoding($value, 'ISO-8859-1'); mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1'); CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [FuncCall::class]; } /** * @param FuncCall $node */ public function refactor(Node $node) : ?Node { if ($node->isFirstClassCallable()) { return null; } if ($this->isName($node, 'utf8_decode')) { $node->name = new Name('mb_convert_encoding'); $node->args[1] = new Arg(new String_('ISO-8859-1')); return $node; } if ($this->isName($node, 'utf8_encode')) { $node->name = new Name('mb_convert_encoding'); $node->args[1] = new Arg(new String_('UTF-8')); $node->args[2] = new Arg(new String_('ISO-8859-1')); return $node; } return null; } public function provideMinPhpVersion() : int { return PhpVersionFeature::DEPRECATE_UTF8_DECODE_ENCODE_FUNCTION; } }
| ver. 1.6 |
Github
|
.
| PHP 8.2.30 | ??????????? ?????????: 0 |
proxy
|
phpinfo
|
???????????