Skip to content

Commit

Permalink
Add support for annotations 2 (#1013)
Browse files Browse the repository at this point in the history
* Remove call to deprecated method

It is no longer necessary since v1.10, and is removed in v2.0

* Add support for annotations 2

It should allow other packages to add support for doctrine/lexer 3
  • Loading branch information
greg0ire authored Dec 19, 2022
1 parent cfd2c32 commit 719948b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ext-reflection": "*",
"ext-spl": "*",
"ext-tokenizer": "*",
"doctrine/annotations": "^1.13",
"doctrine/annotations": "^1.13 || ^2.0",
"phpbench/container": "^2.1",
"phpbench/dom": "~0.3.1",
"psr/log": "^1.1 || ^2.0 || ^3.0",
Expand Down
11 changes: 2 additions & 9 deletions lib/Benchmark/Metadata/AnnotationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace PhpBench\Benchmark\Metadata;

use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\DocParser;
use Doctrine\Common\Annotations\TokenParser;
use PhpBench\Reflection\ReflectionClass;
Expand Down Expand Up @@ -143,12 +142,6 @@ public function __construct(bool $importUse = false)
$this->docParser = new DocParser();
$this->docParser->setIgnoredAnnotationNames(self::$globalIgnoredNames);
$this->importUse = $importUse;

AnnotationRegistry::registerLoader(function ($classFqn) {
if (class_exists($classFqn)) {
return true;
}
});
}

/**
Expand Down Expand Up @@ -197,7 +190,7 @@ private function getUseImports(ReflectionClass $class)

$content = file_get_contents($class->path);
$tokenizer = new TokenParser('<?php ' . $content);
$useImports = $tokenizer->parseUseStatements($class->namespace);
$useImports = $tokenizer->parseUseStatements($class->namespace ?? '');
$this->useImports[$class->class] = $useImports;

return $useImports;
Expand All @@ -212,7 +205,7 @@ private function getUseImports(ReflectionClass $class)
private function parse($input, $context = ''): array
{
try {
$annotations = @$this->docParser->parse($input, $context);
$annotations = @$this->docParser->parse($input ?? '', $context);
} catch (AnnotationException $e) {
if (!preg_match('/The annotation "(.*)" .* was never imported/', $e->getMessage(), $matches)) {
throw new CouldNotLoadMetadataException($e->getMessage(), 0, $e);
Expand Down

0 comments on commit 719948b

Please sign in to comment.