Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"Rector\\ConsoleDiffer\\": "packages/ConsoleDiffer/src",
"Rector\\DeadCode\\": "packages/DeadCode/src",
"Rector\\Doctrine\\": "packages/Doctrine/src",
"Rector\\DoctrinePhpDocParser\\": "packages/DoctrinePhpDocParser/src",
"Rector\\ElasticSearchDSL\\": "packages/ElasticSearchDSL/src",
"Rector\\FileSystemRector\\": "packages/FileSystemRector/src",
"Rector\\Guzzle\\": "packages/Guzzle/src",
Expand Down Expand Up @@ -112,7 +111,6 @@
"Rector\\CodingStyle\\Tests\\": "packages/CodingStyle/tests",
"Rector\\DeadCode\\Tests\\": "packages/DeadCode/tests",
"Rector\\Doctrine\\Tests\\": "packages/Doctrine/tests",
"Rector\\DoctrinePhpDocParser\\Tests\\": "packages/DoctrinePhpDocParser/tests",
"Rector\\ElasticSearchDSL\\Tests\\": "packages/ElasticSearchDSL/tests",
"Rector\\Guzzle\\Tests\\": "packages/Guzzle/tests",
"Rector\\Laravel\\Tests\\": "packages/Laravel/tests",
Expand Down
2 changes: 1 addition & 1 deletion docs/AllRectorsOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3041,7 +3041,7 @@ services:
+ /**
+ * @return int[]
+ */
+ public function provideDataForTest(): iterable
+ public function provideDataForTest(): \Iterator
+ {
+ yield [1];
+ yield [2];
Expand Down
3 changes: 1 addition & 2 deletions ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,14 @@ parameters:

Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
- 'packages/Doctrine/src/Rector/ClassMethod/AddMethodCallBasedParamTypeRector.php'
- 'packages/DoctrinePhpDocParser/src/PhpDocParser/OrmTagParser.php'
- 'packages/TypeDeclaration/src/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInferer.php'
- 'packages/NodeTypeResolver/src/NodeTypeResolver.php'
- 'packages/NodeTypeResolver/src/PerNodeTypeResolver/VariableTypeResolver.php'
- 'packages/Php71/src/Rector/FuncCall/RemoveExtraParametersRector.php'
- 'packages/SOLID/src/Analyzer/ClassConstantFetchAnalyzer.php'
# tough logic
- 'packages/PHPUnit/src/Rector/Class_/ArrayArgumentInTestToDataProviderRector.php'
- 'packages/DoctrinePhpDocParser/src/Ast/PhpDoc/*/*TagValueNode.php'
- 'packages/BetterPhpDocParser/src/Ast/PhpDoc/*/*TagValueNode.php'
- 'packages/NodeTypeResolver/src/PhpDoc/NodeAnalyzer/FqnNamePhpDocNodeDecorator.php'
- 'packages/NodeTypeResolver/src/PHPStan/Type/StaticTypeAnalyzer.php'
- 'src/NodeContainer/ParsedNodesByType.php'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Architecture\Tests\Rector\Class_\RemoveRepositoryFromEntityAnnotationRector\RemoveRepositoryFromEntityAnnotationRectorTest;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_\EntityTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rector\Architecture\Tests\Rector\Class_\ConstructorInjectionToActionInjectionRector;

use Iterator;
use Rector\Architecture\Rector\Class_\ConstructorInjectionToActionInjectionRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

Expand All @@ -15,10 +16,7 @@ public function test(string $file): void
$this->doTestFile($file);
}

/**
* @return string[]
*/
public function provideDataForTest(): iterable
public function provideDataForTest(): Iterator
{
yield [__DIR__ . '/Fixture/fixture.php.inc'];
yield [__DIR__ . '/Fixture/duplicate.php.inc'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rector\Architecture\Tests\Rector\Class_\RemoveRepositoryFromEntityAnnotationRector;

use Iterator;
use Rector\Architecture\Rector\Class_\RemoveRepositoryFromEntityAnnotationRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

Expand All @@ -15,10 +16,7 @@ public function test(string $file): void
$this->doTestFile($file);
}

/**
* @return string[]
*/
public function provideDataForTest(): iterable
public function provideDataForTest(): Iterator
{
yield [__DIR__ . '/Fixture/fixture.php.inc'];
yield [__DIR__ . '/Fixture/skip_done.php.inc'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Autodiscovery\FileMover\FileMover;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_\EntityTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
use Rector\FileSystemRector\Rector\AbstractFileSystemRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public function test(string $originalFile, string $expectedFileLocation, string
$this->assertFileEquals($expectedFileContent, $expectedFileLocation);
}

/**
* @return string[]
*/
public function provideDataForTest(): Iterator
{
yield [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public function test(string $originalFile, string $expectedFileLocation, string
$this->assertFileEquals($expectedFileContent, $expectedFileLocation);
}

/**
* @return string[]
*/
public function provideDataForTest(): Iterator
{
yield [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public function test(string $originalFile, string $expectedFileLocation, string
$this->assertFileEquals($expectedFileContent, $expectedFileLocation);
}

/**
* @return string[]
*/
public function provideDataForTest(): Iterator
{
yield [
Expand Down
2 changes: 1 addition & 1 deletion packages/BetterPhpDocParser/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:

Rector\BetterPhpDocParser\:
resource: '../src'
exclude: '../src/{HttpKernel,ValueObject/*,*/*Info.php,*Info.php,Attributes/Ast/PhpDoc/*,Ast/PhpDoc/*}'
exclude: '../src/{HttpKernel,ValueObject/*,*/*Info.php,*Info.php,Attributes/Ast/PhpDoc/*,Ast/PhpDoc/*,PhpDocNode/*}'

PHPStan\PhpDocParser\Lexer\Lexer: ~
PHPStan\PhpDocParser\Parser\TypeParser: ~
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Rector\DoctrinePhpDocParser\AnnotationReader;
namespace Rector\BetterPhpDocParser\AnnotationReader;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
Expand All @@ -17,10 +17,22 @@ public function create(): AnnotationReader
// don't forget to add it to "stubs/Doctrine/Empty" directory, because the class needs to exists
// and run "composer dump-autoload", because the directory is loaded by classmap
$annotationReader::addGlobalIgnoredName('ORM\GeneratedValue');
$annotationReader::addGlobalIgnoredName('GeneratedValue');

$annotationReader::addGlobalIgnoredName('ORM\InheritanceType');
$annotationReader::addGlobalIgnoredName('InheritanceType');

$annotationReader::addGlobalIgnoredName('ORM\OrderBy');
$annotationReader::addGlobalIgnoredName('OrderBy');

$annotationReader::addGlobalIgnoredName('ORM\DiscriminatorMap');
$annotationReader::addGlobalIgnoredName('DiscriminatorMap');

$annotationReader::addGlobalIgnoredName('ORM\UniqueEntity');
$annotationReader::addGlobalIgnoredName('UniqueEntity');

$annotationReader::addGlobalIgnoredName('Gedmo\SoftDeleteable');
$annotationReader::addGlobalIgnoredName('SoftDeleteable');

// warning: nested tags must be parse-able, e.g. @ORM\Table must include @ORM\UniqueConstraint!

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php declare(strict_types=1);

namespace Rector\DoctrinePhpDocParser\AnnotationReader;
namespace Rector\BetterPhpDocParser\AnnotationReader;

use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\Mapping\Annotation;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\Resolver\NameResolver;
Expand Down Expand Up @@ -51,20 +51,22 @@ public function readMethodAnnotation(ClassMethod $classMethod, string $annotatio

$reflectionMethod = new ReflectionMethod($className, $methodName);

return $this->annotationReader->getMethodAnnotation($reflectionMethod, $annotationClassName);
try {
return $this->annotationReader->getMethodAnnotation($reflectionMethod, $annotationClassName);
} catch (AnnotationException $annotationException) {
// unable to laod
return null;
}
}

public function readClassAnnotation(Class_ $class, string $annotationClassName): Annotation
/**
* @return object|null
*/
public function readClassAnnotation(Class_ $class, string $annotationClassName)
{
$classReflection = $this->createClassReflectionFromNode($class);

/** @var Annotation|null $classAnnotation */
$classAnnotation = $this->annotationReader->getClassAnnotation($classReflection, $annotationClassName);
if ($classAnnotation === null) {
throw new ShouldNotHappenException();
}

return $classAnnotation;
return $this->annotationReader->getClassAnnotation($classReflection, $annotationClassName);
}

/**
Expand All @@ -80,7 +82,7 @@ public function readPropertyAnnotation(Property $property, string $annotationCla
/** @var Annotation|null $propertyAnnotation */
$propertyAnnotation = $this->annotationReader->getPropertyAnnotation($propertyReflection, $annotationClassName);
if ($propertyAnnotation === null) {
throw new ShouldNotHappenException();
return null;
}

return $propertyAnnotation;
Expand All @@ -91,15 +93,12 @@ private function createPropertyReflectionFromPropertyNode(Property $property): ?
/** @var string $propertyName */
$propertyName = $this->nameResolver->getName($property);

/** @var string $className */
/** @var string|null $className */
$className = $property->getAttribute(AttributeKey::CLASS_NAME);

if ($className === null || ! ClassExistenceStaticHelper::doesClassLikeExist($className)) {
throw new ShouldNotHappenException(sprintf(
'Class "%s" for property "%s" was not found.',
(string) $className,
$propertyName
));
// probably fresh node
return null;
}

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
namespace Rector\BetterPhpDocParser\Contract\Doctrine;

use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
namespace Rector\BetterPhpDocParser\Contract\Doctrine;

use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
namespace Rector\BetterPhpDocParser\Contract\Doctrine;

interface InversedByNodeInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
namespace Rector\BetterPhpDocParser\Contract\Doctrine;

interface MappedByNodeInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Rector\BetterPhpDocParser\Contract\Doctrine;

interface OriginalTagAwareInterface
{
public function getOriginalTag(): ?string;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
namespace Rector\BetterPhpDocParser\Contract\Doctrine;

interface ToManyTagNodeInterface extends DoctrineRelationTagValueNodeInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
namespace Rector\BetterPhpDocParser\Contract\Doctrine;

interface ToOneTagNodeInterface extends DoctrineRelationTagValueNodeInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types=1);

namespace Rector\BetterPhpDocParser\Contract;

use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;

interface PhpDocNodeFactoryInterface
{
public function getName(): string;

public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

namespace Rector\BetterPhpDocParser\Contract;

use PHPStan\PhpDocParser\Parser\PhpDocParser;

interface PhpDocParserAwareInterface
{
public function setPhpDocParser(PhpDocParser $phpDocParser): void;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwarePhpDocNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute;
use Rector\BetterPhpDocParser\Attributes\Contract\Ast\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\PhpDocParser\OrmTagParser;
use Rector\Configuration\CurrentNodeProvider;
use Rector\DoctrinePhpDocParser\PhpDocParser\OrmTagParser;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\StaticTypeMapper;

Expand Down
Loading