Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser update #103

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ext-json": "*",
"composer/xdebug-handler": "^3.0",
"jetbrains/phpstorm-stubs": "2024.1",
"nikic/php-parser": "^4.19",
"nikic/php-parser": "^5",
"phpdocumentor/graphviz": "^2.1",
"phpdocumentor/type-resolver": "^1.6",
"phpstan/phpdoc-parser": "^1.5",
Expand Down
22 changes: 12 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@
$services->set(Lexer::class);
$services
->set(Parser::class)
->factory([service(ParserFactory::class), 'create'])
->args([
'$kind' => ParserFactory::PREFER_PHP7,
])
->factory([service(ParserFactory::class), 'createForNewestSupportedVersion'])
;
$services->set(AstFileReferenceInMemoryCache::class);
$services->alias(AstFileReferenceCacheInterface::class, AstFileReferenceInMemoryCache::class);
Expand Down
15 changes: 12 additions & 3 deletions src/Core/Ast/Parser/Extractors/AnnotationReferenceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
Expand All @@ -33,12 +32,22 @@ public function __construct(private readonly TypeResolver $typeResolver)
public function processNode(Node $node, ReferenceBuilder $referenceBuilder, TypeScope $typeScope): void
{
if (!$node instanceof Property
&& !$node instanceof Variable
&& !$node instanceof Node\Stmt\Expression
&& !$node instanceof ClassMethod
) {
return;
}

/**
* @see https://github.com/nikic/PHP-Parser/commit/4e27a17cd855b36abe0199efb81be143b144f40d#diff-4034fc485172f50147405c293a9d86685b0f333e69b666de5492da37406186afL44 for the change in nikic/php-parser
* @see https://github.com/patrickkusebauch/phpstan-src/commit/cc4bff635ebae19b010b81130360155692283ac6#diff-c4e3f0a39ea5d27cabb86159d23a29adbf4ba64b1931497f8a9bac2e720579d9R81 for the stolen implementation from PHPStan
*/
if ($node instanceof Node\Stmt\Expression) {
if (!$node->expr instanceof Node\Expr\Assign && !$node->expr instanceof Node\Expr\AssignRef) {
return;
}
}

$docComment = $node->getDocComment();
if (!$docComment instanceof Doc) {
return;
Expand All @@ -48,7 +57,7 @@ public function processNode(Node $node, ReferenceBuilder $referenceBuilder, Type
$docNode = $this->docParser->parse($tokens);
$templateTypes = array_merge(
array_map(
static fn (TemplateTagValueNode $node): string => $node->name,
static fn (TemplateTagValueNode $templateNode): string => $templateNode->name,
$docNode->getTemplateTagValues()
),
$referenceBuilder->getTokenTemplates()
Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Ast/AstMapFlattenGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Tests\Qossmic\Deptrac\Core\Ast;

use LogicException;
use PhpParser\Lexer;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
use Qossmic\Deptrac\Contract\Ast\AstFileAnalysedEvent;
Expand Down Expand Up @@ -59,7 +58,7 @@ protected function setUp(): void
);
$this->astLoader = new AstLoader(
new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
new TypeResolver(),
[]
Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Ast/AstMapGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Qossmic\Deptrac\Core\Ast;

use PhpParser\Lexer;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
use Qossmic\Deptrac\Core\Ast\AstLoader;
Expand Down Expand Up @@ -37,7 +36,7 @@ private function getAstMap(string $fixture): AstMap
$typeResolver = new TypeResolver();
$astRunner = new AstLoader(
new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
$typeResolver,
[
Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Ast/Parser/AnnotationReferenceExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Qossmic\Deptrac\Core\Ast\Parser;

use PhpParser\Lexer;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
use Qossmic\Deptrac\Core\Ast\Parser\Cache\AstFileReferenceInMemoryCache;
Expand All @@ -19,7 +18,7 @@ public function testPropertyDependencyResolving(): void
{
$typeResolver = new TypeResolver();
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
new TypeResolver(),
[
Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Ast/Parser/AnonymousClassExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Qossmic\Deptrac\Core\Ast\Parser;

use PhpParser\Lexer;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
use Qossmic\Deptrac\Core\Ast\Parser\Cache\AstFileReferenceInMemoryCache;
Expand All @@ -17,7 +16,7 @@ final class AnonymousClassExtractorTest extends TestCase
public function testPropertyDependencyResolving(): void
{
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
new TypeResolver(),
[
Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Ast/Parser/ClassConstantExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Qossmic\Deptrac\Core\Ast\Parser;

use PhpParser\Lexer;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
use Qossmic\Deptrac\Core\Ast\Parser\Cache\AstFileReferenceInMemoryCache;
Expand All @@ -17,7 +16,7 @@ final class ClassConstantExtractorTest extends TestCase
public function testPropertyDependencyResolving(): void
{
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
new TypeResolver(),
[
Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Ast/Parser/ClassDocBlockExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Qossmic\Deptrac\Core\Ast\Parser;

use PhpParser\Lexer;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
use Qossmic\Deptrac\Contract\Ast\DependencyType;
Expand All @@ -27,7 +26,7 @@ public function testMethodResolving(): void
{
$typeResolver = new TypeResolver();
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
$typeResolver,
[
Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Ast/Parser/FunctionLikeExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Qossmic\Deptrac\Core\Ast\Parser;

use PhpParser\Lexer;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
use Qossmic\Deptrac\Core\Ast\AstMap\ClassLike\ClassLikeReference;
Expand All @@ -23,7 +22,7 @@ public function testPropertyDependencyResolving(): void
{
$typeResolver = new TypeResolver();
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
$typeResolver,
[
Expand Down
19 changes: 4 additions & 15 deletions tests/Core/Ast/Parser/NikicPhpParser/NikicPhpParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Qossmic\Deptrac\Core\Ast\Parser\NikicPhpParser;

use PhpParser\Lexer;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -62,10 +61,7 @@ public function testParseTemplateTypes(): void
{
$typeResolver = new TypeResolver();
$parser = new NikicPhpParser(
(new ParserFactory())->create(
ParserFactory::ONLY_PHP7,
new Lexer()
),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
$typeResolver,
[new AnnotationReferenceExtractor($typeResolver)]
Expand Down Expand Up @@ -126,17 +122,10 @@ private function refsByName(array $refs): array

private function createParser(): NikicPhpParser
{
$typeResolver = new TypeResolver();
$parser = new NikicPhpParser(
(new ParserFactory())->create(
ParserFactory::ONLY_PHP7,
new Lexer()
),
new AstFileReferenceInMemoryCache(),
$typeResolver,
return new NikicPhpParser(
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(), new TypeResolver(),
[]
);

return $parser;
}
}
3 changes: 1 addition & 2 deletions tests/Core/Dependency/Emitter/EmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Qossmic\Deptrac\Core\Dependency\Emitter;

use PhpParser\Lexer;
use PhpParser\ParserFactory;
use Qossmic\Deptrac\Contract\Dependency\DependencyInterface;
use Qossmic\Deptrac\Core\Ast\AstLoader;
Expand Down Expand Up @@ -33,7 +32,7 @@ public function getEmittedDependencies(DependencyEmitterInterface $emitter, $fil

$typeResolver = new TypeResolver();
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
(new ParserFactory())->createForNewestSupportedVersion(),
new AstFileReferenceInMemoryCache(),
$typeResolver,
[
Expand Down
Loading