Skip to content

Commit

Permalink
fix for phpdocmentor v6
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Dec 3, 2024
1 parent 8618423 commit c285f93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Core/src/Testing/Reflection/ReflectionHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace Google\Cloud\Core\Testing\Reflection;

use phpDocumentor\Reflection\Php\Factory\Argument;

/**
* Class for determining which verison of phpdocumentor/reflection is being used.
* @internal
Expand All @@ -28,6 +30,8 @@ class ReflectionHandlerFactory
*/
public static function create()
{
return new ReflectionHandlerV5();
return class_exists(Argument::class)
? new ReflectionHandlerV5()
: new ReflectionHandlerV6();

Check failure on line 35 in Core/src/Testing/Reflection/ReflectionHandlerFactory.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis

Instantiated class Google\Cloud\Core\Testing\Reflection\ReflectionHandlerV6 not found.
}
}
26 changes: 21 additions & 5 deletions Core/src/Testing/Reflection/ReflectionHandlerV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,31 @@ public function classes(array $files)
}

/**
* @return ProjectFactory
* Split this into a separate method because ReflectionHandler V6 looks
* different
*/
public function createProjectFactory()
protected function createParser()
{
$parser = (new ParserFactory())->create(
return (new ParserFactory())->create(
ParserFactory::ONLY_PHP7,
new Lexer\Emulative(['phpVersion' => Lexer\Emulative::PHP_8_0])
);
}

/**
* Split this into a separate method because V6 does not support it
*/
protected function getAdditionalStrategies()
{
return [new Factory\Argument(new PrettyPrinter())];

Check failure on line 118 in Core/src/Testing/Reflection/ReflectionHandlerV5.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis

Instantiated class phpDocumentor\Reflection\Php\Factory\Argument not found.
}

/**
* @return ProjectFactory
*/
public function createProjectFactory()
{
$parser = $this->createParser();
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor(new NameResolver());
$nodeTraverser->addVisitor(new ElementNameResolver());
Expand All @@ -119,7 +136,6 @@ public function createProjectFactory()
$strategies = new ProjectFactoryStrategies(
[
new Factory\Namespace_(),
new Factory\Argument(new PrettyPrinter()),
new Factory\Class_($docblockFactory),
new Factory\Enum_($docblockFactory),
new Factory\EnumCase($docblockFactory, new PrettyPrinter()),
Expand All @@ -134,7 +150,7 @@ public function createProjectFactory()
new Factory\Trait_($docblockFactory),
new Factory\IfStatement(),
new TraitUse(),
]
] + $this->getAdditionalStrategies()
);

$strategies->addStrategy(
Expand Down

0 comments on commit c285f93

Please sign in to comment.