diff --git a/composer.dingo.json b/composer.dingo.json index 22a63842..0c743344 100644 --- a/composer.dingo.json +++ b/composer.dingo.json @@ -27,11 +27,11 @@ "illuminate/support": "^8.0|^9.0", "league/flysystem": "^1.1.4|^2.1.1|^3.0", "mpociot/reflection-docblock": "^1.0.1", - "nikic/php-parser": "^4.10", - "nunomaduro/collision": "^5.10|^6.0", + "nikic/php-parser": "^5.0", + "nunomaduro/collision": "^5.10|^6.0|^7.0|^8.0", "ramsey/uuid": "^4.2.2", "shalvah/clara": "^3.1.0", - "shalvah/upgrader": "0.*", + "shalvah/upgrader": ">=0.6.0", "spatie/data-transfer-object": "^2.6|^3.0", "symfony/var-exporter": "^5.4|^6.0|^7.0", "symfony/yaml": "^5.4|^6.0|^7.0" diff --git a/composer.json b/composer.json index 46a57107..da355f90 100644 --- a/composer.json +++ b/composer.json @@ -26,11 +26,11 @@ "illuminate/support": "^8.0|^9.0|^10.0", "league/flysystem": "^1.1.4|^2.1.1|^3.0", "mpociot/reflection-docblock": "^1.0.1", - "nikic/php-parser": "^4.10", + "nikic/php-parser": "^5.0", "nunomaduro/collision": "^5.10|^6.0|^7.0|^8.0", "ramsey/uuid": "^4.2.2", "shalvah/clara": "^3.1.0", - "shalvah/upgrader": "^0.3.0", + "shalvah/upgrader": ">=0.6.0", "spatie/data-transfer-object": "^2.6|^3.0", "symfony/var-exporter": "^5.4|^6.0|^7.0", "symfony/yaml": "^5.4|^6.0|^7.0" diff --git a/src/Extracting/MethodAstParser.php b/src/Extracting/MethodAstParser.php index 87c739b7..99f6fe6d 100644 --- a/src/Extracting/MethodAstParser.php +++ b/src/Extracting/MethodAstParser.php @@ -43,7 +43,7 @@ public static function getMethodAst(ReflectionFunctionAbstract $method) */ protected static function parseClassSourceCode(string $sourceCode): ?array { - $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); + $parser = (new ParserFactory)->createForHostVersion(); try { $ast = $parser->parse($sourceCode); } catch (Throwable $error) { diff --git a/src/Extracting/Shared/ValidationRulesFinders/ValidatorMake.php b/src/Extracting/Shared/ValidationRulesFinders/ValidatorMake.php index a3bec16b..e5b2856d 100644 --- a/src/Extracting/Shared/ValidationRulesFinders/ValidatorMake.php +++ b/src/Extracting/Shared/ValidationRulesFinders/ValidatorMake.php @@ -24,8 +24,8 @@ public static function find(Node $node) if ( $expr instanceof Node\Expr\StaticCall - && !empty($expr->class->parts) - && end($expr->class->parts) == "Validator" + && !empty($expr->class->name) + && str_ends_with($expr->class->name, "Validator") && $expr->name->name == "make" ) { return $expr->args[1]->value; diff --git a/src/Extracting/Strategies/GetFromInlineValidatorBase.php b/src/Extracting/Strategies/GetFromInlineValidatorBase.php index e14c516d..5757b55a 100644 --- a/src/Extracting/Strategies/GetFromInlineValidatorBase.php +++ b/src/Extracting/Strategies/GetFromInlineValidatorBase.php @@ -63,7 +63,7 @@ public function lookForInlineValidationRules(ClassMethod $methodAst): array $rules = []; $customParameterData = []; foreach ($validationRules->items as $item) { - /** @var Node\Expr\ArrayItem $item */ + /** @var Node\ArrayItem $item */ if (!$item->key instanceof Node\Scalar\String_) { continue; } @@ -77,7 +77,7 @@ public function lookForInlineValidationRules(ClassMethod $methodAst): array } else if ($item->value instanceof Node\Expr\Array_) { $rulesList = []; foreach ($item->value->items as $arrayItem) { - /** @var Node\Expr\ArrayItem $arrayItem */ + /** @var Node\ArrayItem $arrayItem */ if ($arrayItem->value instanceof Node\Scalar\String_) { $rulesList[] = $arrayItem->value->value; } @@ -122,14 +122,14 @@ enum_exists($enum) && method_exists($enum, 'tryFrom') return [$rules, $customParameterData]; } - protected function extractEnumClassFromArrayItem(Node\Expr\ArrayItem $arrayItem): ?string + protected function extractEnumClassFromArrayItem(Node\ArrayItem $arrayItem): ?string { $args = []; // Enum rule with the form "new Enum(...)" if ($arrayItem->value instanceof Node\Expr\New_ && $arrayItem->value->class instanceof Node\Name && - last($arrayItem->value->class->parts) === 'Enum' + str_ends_with($arrayItem->value->class->name, 'Enum') ) { $args = $arrayItem->value->args; } @@ -137,7 +137,7 @@ protected function extractEnumClassFromArrayItem(Node\Expr\ArrayItem $arrayItem) // Enum rule with the form "Rule::enum(...)" else if ($arrayItem->value instanceof Node\Expr\StaticCall && $arrayItem->value->class instanceof Node\Name && - last($arrayItem->value->class->parts) === 'Rule' && + str_ends_with($arrayItem->value->class->name, 'Rule') && $arrayItem->value->name instanceof Node\Identifier && $arrayItem->value->name->name === 'enum' ) { @@ -150,7 +150,7 @@ protected function extractEnumClassFromArrayItem(Node\Expr\ArrayItem $arrayItem) if ($arg->value instanceof Node\Expr\ClassConstFetch && $arg->value->class instanceof Node\Name ) { - return '\\' . implode('\\', $arg->value->class->parts); + return '\\' . $arg->value->class->name; } else if ($arg->value instanceof Node\Scalar\String_) { return $arg->value->value; }