From 77b679d82b2782b047a26768fd20996fa7b0a941 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 16 Oct 2019 18:45:03 +0200 Subject: [PATCH 1/3] skip if option is missing --- src/Autoloading/AdditionalAutoloader.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Autoloading/AdditionalAutoloader.php b/src/Autoloading/AdditionalAutoloader.php index 47333afee73d..0352e006217c 100644 --- a/src/Autoloading/AdditionalAutoloader.php +++ b/src/Autoloading/AdditionalAutoloader.php @@ -76,6 +76,10 @@ public function autoloadWithInputAndSource(InputInterface $input, array $source) private function autoloadFileFromInput(InputInterface $input): void { + if (! $input->hasOption(Option::OPTION_AUTOLOAD_FILE)) { + return; + } + /** @var string|null $autoloadFile */ $autoloadFile = $input->getOption(Option::OPTION_AUTOLOAD_FILE); if ($autoloadFile === null) { From f04d663e41c3f6c5391fbb2739e7dd8c585c42a0 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 16 Oct 2019 23:04:41 +0200 Subject: [PATCH 2/3] fix re-throw --- .../src/AnnotationReader/NodeAnnotationReader.php | 2 +- utils/DocumentationGenerator/src/Command/DumpNodesCommand.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/BetterPhpDocParser/src/AnnotationReader/NodeAnnotationReader.php b/packages/BetterPhpDocParser/src/AnnotationReader/NodeAnnotationReader.php index a653d8155c85..31d93c7db3e7 100644 --- a/packages/BetterPhpDocParser/src/AnnotationReader/NodeAnnotationReader.php +++ b/packages/BetterPhpDocParser/src/AnnotationReader/NodeAnnotationReader.php @@ -108,7 +108,7 @@ private function createPropertyReflectionFromPropertyNode(Property $property): ? return null; } - throw new $throwable(); + throw $throwable; } } diff --git a/utils/DocumentationGenerator/src/Command/DumpNodesCommand.php b/utils/DocumentationGenerator/src/Command/DumpNodesCommand.php index b70b49710099..76c0fe199afa 100644 --- a/utils/DocumentationGenerator/src/Command/DumpNodesCommand.php +++ b/utils/DocumentationGenerator/src/Command/DumpNodesCommand.php @@ -49,6 +49,7 @@ use PhpParser\Node\Expr\YieldFrom; use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\NullableType; use PhpParser\Node\Param; use PhpParser\Node\Scalar\DNumber; @@ -298,7 +299,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } elseif ($nodeClass === Alias::class) { $node = new Alias(new Name('SomeTrait'), 'method', Class_::MODIFIER_PUBLIC, 'aliasedMethod'); } elseif ($nodeClass === Throw_::class) { - $node = new Throw_(new New_(new Variable('someException'))); + $node = new Throw_(new New_(new FullyQualified('SomeException'))); } elseif ($nodeClass === TryCatch::class) { $node = new TryCatch([new Function_('someFunction')], [new Function_('logException')]); } elseif ($nodeClass === Interface_::class) { From ec584212cc9d4147047be4eefe5b7d109eb88059 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 16 Oct 2019 23:55:36 +0200 Subject: [PATCH 3/3] skip missing property reflection --- .../src/AnnotationReader/NodeAnnotationReader.php | 8 ++------ phpstan.neon | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/BetterPhpDocParser/src/AnnotationReader/NodeAnnotationReader.php b/packages/BetterPhpDocParser/src/AnnotationReader/NodeAnnotationReader.php index 31d93c7db3e7..25321c553476 100644 --- a/packages/BetterPhpDocParser/src/AnnotationReader/NodeAnnotationReader.php +++ b/packages/BetterPhpDocParser/src/AnnotationReader/NodeAnnotationReader.php @@ -13,7 +13,6 @@ use Rector\NodeTypeResolver\ClassExistenceStaticHelper; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\Resolver\NameResolver; -use Rector\Testing\PHPUnit\PHPUnitEnvironment; use ReflectionClass; use ReflectionMethod; use ReflectionProperty; @@ -104,11 +103,8 @@ private function createPropertyReflectionFromPropertyNode(Property $property): ? try { return new ReflectionProperty($className, $propertyName); } catch (Throwable $throwable) { - if (PHPUnitEnvironment::isPHPUnitRun()) { - return null; - } - - throw $throwable; + // in case of PHPUnit property or just-added property + return null; } } diff --git a/phpstan.neon b/phpstan.neon index 9e59ab7294b8..54f39eb175d5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -207,3 +207,5 @@ parameters: - '#PHPDoc tag @param references unknown parameter\: \$commanders#' - '#In method "Rector\\Rector\\AbstractRector\:\:autowireAbstractRectorDependencies", parameter \$symfonyStyle type is type\-hinted to "Symfony\\Component\\Console\\Style\\SymfonyStyle" but the @param annotation says it is a "array"\. Please fix the @param annotation#' - '#PHPDoc tag @param for parameter \$symfonyStyle with type array is incompatible with native type Symfony\\Component\\Console\\Style\\SymfonyStyle#' + + - '#In method "Rector\\BetterPhpDocParser\\AnnotationReader\\NodeAnnotationReader\:\:createPropertyReflectionFromPropertyNode", caught "Throwable" must be rethrown\. Either catch a more specific exception or add a "throw" clause in the "catch" block to propagate the exception\. More info\: http\://bit\.ly/failloud#'