From 6b2dcb91008e88dfee4ac3dc8e0a086ef1b7805d Mon Sep 17 00:00:00 2001 From: Herberto Graca Date: Sun, 10 Sep 2023 11:49:47 +0200 Subject: [PATCH] Simplify usage of FileParserFactory By allowing createFileParser to be called with null we need less code everywhere else to create a default file parser. --- src/Analyzer/FileParserFactory.php | 8 +++++--- src/CLI/TargetPhpVersion.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Analyzer/FileParserFactory.php b/src/Analyzer/FileParserFactory.php index e8c3b93f..1755c660 100644 --- a/src/Analyzer/FileParserFactory.php +++ b/src/Analyzer/FileParserFactory.php @@ -9,13 +9,15 @@ class FileParserFactory { - public static function createFileParser(TargetPhpVersion $targetPhpVersion, bool $parseCustomAnnotations = true): FileParser - { + public static function createFileParser( + TargetPhpVersion $targetPhpVersion = null, + bool $parseCustomAnnotations = true + ): FileParser { return new FileParser( new NodeTraverser(), new FileVisitor(new ClassDescriptionBuilder()), new NameResolver(null, ['parseCustomAnnotations' => $parseCustomAnnotations]), - $targetPhpVersion + $targetPhpVersion ?? TargetPhpVersion::create() ); } } diff --git a/src/CLI/TargetPhpVersion.php b/src/CLI/TargetPhpVersion.php index 8ec80100..3f033afb 100644 --- a/src/CLI/TargetPhpVersion.php +++ b/src/CLI/TargetPhpVersion.php @@ -26,7 +26,7 @@ private function __construct(?string $version) $this->version = $version; } - public static function create(?string $version): self + public static function create(string $version = null): self { if (null === $version) { return new self(phpversion());