Replies: 3 comments 1 reply
-
Regression tests took me a long time, especially because I wanted to find a way to handle Parser errors correctly (see https://github.com/composer-unused/symbol-parser/blob/0.2.2/src/Parser/PHP/SymbolNameParser.php#L43) Now all it's ok and PR will come shortly. But it's time for explains about error handler ! PHP-Parser has it's own error handler recovery system. <?php
namespace ComposerUnused\SymbolParser\Parser\PHP;
use PhpParser\ErrorHandler;
final class ParserErrorCollector extends ErrorHandler\Collecting implements ParserErrorCollectorInterface
{
} <?php
namespace ComposerUnused\SymbolParser\Parser\PHP;
use PhpParser\ErrorHandler;
interface ParserErrorCollectorInterface extends ErrorHandler
{
public function getErrors(): array;
public function hasErrors() : bool;
public function clearErrors();
} As the default error handling strategy is By using the default But you've also the alternative to stop symbol name parsing by explicitly specify the Default behavior (collect errors) without to specify the error handler is not recommanded, because the PHP-Parser For example : <?php
use ComposerUnused\SymbolParser\Parser\PHP\ConsumedSymbolCollector;
use ComposerUnused\SymbolParser\Parser\PHP\SymbolNameParser;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\ParserFactory;
$symbolNameParser = new SymbolNameParser(
(new ParserFactory())->createForNewestSupportedVersion(),
new NameResolver(),
new ConsumedSymbolCollector($strategies)
);
$symbols = $symbolNameParser->parseSymbolNames($code); Recommended way is to use : <?php
use ComposerUnused\SymbolParser\Parser\PHP\ConsumedSymbolCollector;
use ComposerUnused\SymbolParser\Parser\PHP\ParserErrorCollector;
use ComposerUnused\SymbolParser\Parser\PHP\SymbolNameParser;
use PhpParser\ErrorHandler\Throwing;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\ParserFactory;
$errorHandler = new ParserErrorCollector();
// or alternative
// $errorHandler = new Throwing();
$symbolNameParser = new SymbolNameParser(
(new ParserFactory())->createForNewestSupportedVersion(),
new NameResolver($errorHandler),
new ConsumedSymbolCollector($strategies),
$errorHandler
);
$symbols = $symbolNameParser->parseSymbolNames($code); |
Beta Was this translation helpful? Give feedback.
-
Even, if PR 138 was already merged, I've an enhanced version available with commit ac04199 |
Beta Was this translation helpful? Give feedback.
-
Will close this discussion because the |
Beta Was this translation helpful? Give feedback.
-
Behind this goal, there is a bug available with latest version 0.2.2 but also all new stuffs added since then.
Idea behind that is to simplify usage with only the
ConsumedSymbolCollector
(with one or more strategies), and removed (or deprecated usage of) theDefinedSymbolCollector
.To fix the #136 issue, I'll propose a new PR with the new
DefineStrategy
.Its goal is to provide all symbols (classes, interfaces, traits, functions, constants, namespaces) where traits and namespaces were missing when using the
DefinedSymbolCollector
.Here is an example how to use the new
DefineStrategy
Beta Was this translation helpful? Give feedback.
All reactions