REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 3.62 KB
Close
//opt/cpanel/ea-wappspector/vendor/rector/rector/vendor/rector/rector-symfony/src/NodeAnalyzer/FormInstanceToFormClassConstFetchConverter.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\Symfony\NodeAnalyzer; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\Variable; use PHPStan\Reflection\ClassReflection; use PHPStan\Type\TypeWithClassName; use Rector\Exception\ShouldNotHappenException; use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\PhpParser\Node\NodeFactory; use Rector\Symfony\NodeAnalyzer\FormType\CreateFormTypeOptionsArgMover; use Rector\Symfony\NodeAnalyzer\FormType\FormTypeClassResolver; use ReflectionMethod; final class FormInstanceToFormClassConstFetchConverter { /** * @readonly * @var \Rector\Symfony\NodeAnalyzer\FormType\CreateFormTypeOptionsArgMover */ private $createFormTypeOptionsArgMover; /** * @readonly * @var \Rector\PhpParser\Node\NodeFactory */ private $nodeFactory; /** * @readonly * @var \Rector\Symfony\NodeAnalyzer\FormType\FormTypeClassResolver */ private $formTypeClassResolver; /** * @readonly * @var \Rector\NodeTypeResolver\NodeTypeResolver */ private $nodeTypeResolver; public function __construct(CreateFormTypeOptionsArgMover $createFormTypeOptionsArgMover, NodeFactory $nodeFactory, FormTypeClassResolver $formTypeClassResolver, NodeTypeResolver $nodeTypeResolver) { $this->createFormTypeOptionsArgMover = $createFormTypeOptionsArgMover; $this->nodeFactory = $nodeFactory; $this->formTypeClassResolver = $formTypeClassResolver; $this->nodeTypeResolver = $nodeTypeResolver; } public function processNewInstance(MethodCall $methodCall, int $position, int $optionsPosition) : ?MethodCall { $args = $methodCall->getArgs(); if (!isset($args[$position])) { return null; } $argValue = $args[$position]->value; $formClassName = $this->formTypeClassResolver->resolveFromExpr($argValue); if ($formClassName === null) { return null; } // better skip and ahndle manualyl if ($argValue instanceof Variable && $this->isVariableOfTypeWithRequiredConstructorParmaeters($argValue)) { return null; } if ($argValue instanceof New_ && $argValue->getArgs() !== []) { $methodCall = $this->createFormTypeOptionsArgMover->moveArgumentsToOptions($methodCall, $position, $optionsPosition, $formClassName, $argValue->getArgs()); if (!$methodCall instanceof MethodCall) { throw new ShouldNotHappenException(); } } $classConstFetch = $this->nodeFactory->createClassConstReference($formClassName); $currentArg = $methodCall->getArgs()[$position]; $currentArg->value = $classConstFetch; return $methodCall; } private function isVariableOfTypeWithRequiredConstructorParmaeters(Variable $variable) : bool { // if form type is object with constructor args, handle manually $variableType = $this->nodeTypeResolver->getType($variable); if (!$variableType instanceof TypeWithClassName) { return \false; } $classReflection = $variableType->getClassReflection(); if (!$classReflection instanceof ClassReflection) { return \false; } if (!$classReflection->hasConstructor()) { return \false; } $nativeReflection = $classReflection->getNativeReflection(); $reflectionMethod = $nativeReflection->getConstructor(); if (!$reflectionMethod instanceof ReflectionMethod) { return \false; } return $reflectionMethod->getNumberOfRequiredParameters() > 0; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 2 × Files: 12
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
Annotations
DIR
-
drwxr-xr-x
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
FormType
DIR
-
drwxr-xr-x
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ClassAnalyzer.php
730 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
DependencyInjectionMethodCallAnalyzer.php
3.83 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
FormAddMethodCallAnalyzer.php
1.49 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
FormCollectionAnalyzer.php
1.21 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
FormInstanceToFormClassConstFetchConverter.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
FormOptionsArrayMatcher.php
508 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
LiteralCallLikeConstFetchReplacer.php
1.43 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
RouteRequiredParamNameToTypesResolver.php
5.08 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
ServiceTypeMethodCallResolver.php
1.52 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
SymfonyClosureExtensionMatcher.php
3.12 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
SymfonyPhpClosureDetector.php
2.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
SymfonyTestCaseAnalyzer.php
1.18 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).