-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59809f3
commit 1258576
Showing
8 changed files
with
133 additions
and
177 deletions.
There are no files selected for viewing
71 changes: 0 additions & 71 deletions
71
...ges/BetterPhpDocParser/Annotation/ChangeResolvedClassInParticularContextForAnnotation.php
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
packages/BetterPhpDocParser/Annotation/InverseJoinColumnCorrector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\BetterPhpDocParser\Annotation; | ||
|
||
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode; | ||
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode; | ||
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey; | ||
use Rector\Php80\ValueObject\AnnotationToAttribute; | ||
|
||
final class InverseJoinColumnCorrector | ||
{ | ||
public function correctInverseJoinColumn( | ||
AnnotationToAttribute $annotationToAttribute, | ||
DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode | ||
): void { | ||
$docNodeValue = $doctrineAnnotationTagValueNode->getValue('inverseJoinColumns'); | ||
if ($annotationToAttribute->getTag() !== 'Doctrine\ORM\Mapping\JoinTable') { | ||
return; | ||
} | ||
|
||
if (! $docNodeValue instanceof CurlyListNode) { | ||
return; | ||
} | ||
|
||
$values = [$docNodeValue->getValues(), $docNodeValue->getOriginalValues()]; | ||
|
||
foreach ($values as $value) { | ||
if (! array_key_exists(0, $value) && ! ($value[0] instanceof DoctrineAnnotationTagValueNode)) { | ||
continue; | ||
} | ||
|
||
$identifierTypeNode = $value[0]->identifierTypeNode; | ||
$identifierTypeNode->setAttribute( | ||
PhpDocAttributeKey::RESOLVED_CLASS, | ||
'Doctrine\ORM\Mapping\InverseJoinColumn' | ||
); | ||
} | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
packages/BetterPhpDocParser/ValueObject/ChangeResolvedClassInParticularContext.php
This file was deleted.
Oops, something went wrong.
66 changes: 33 additions & 33 deletions
66
...l/DowngradeFirstClassCallableSyntaxRector/DowngradeFirstClassCallableSyntaxRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class DowngradeFirstClassCallableSyntaxRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class DowngradeFirstClassCallableSyntaxRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
rules/Compatibility/NodeAnalyzer/RequiredAnnotationPropertyAnalyzer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Compatibility\NodeAnalyzer; | ||
|
||
use PhpParser\Node\Expr; | ||
use PhpParser\Node\NullableType; | ||
use PhpParser\Node\Stmt\Property; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; | ||
use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode; | ||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; | ||
use Rector\Core\PhpParser\Node\Value\ValueResolver; | ||
|
||
final class RequiredAnnotationPropertyAnalyzer | ||
{ | ||
public function __construct( | ||
private ValueResolver $valueResolver | ||
) { | ||
} | ||
|
||
public function isRequiredProperty(PhpDocInfo $phpDocInfo, Property $property): bool | ||
{ | ||
if ($phpDocInfo->hasByAnnotationClass('Doctrine\Common\Annotations\Annotation\Required')) { | ||
return true; | ||
} | ||
|
||
// sometimes property has default null, but @var says its not null - that's due to nullability of typed properties | ||
// in that case, we should treat property as required | ||
$firstProperty = $property->props[0]; | ||
if (! $firstProperty->default instanceof Expr) { | ||
return false; | ||
} | ||
|
||
if (! $this->valueResolver->isNull($firstProperty->default)) { | ||
return false; | ||
} | ||
|
||
$varTagValueNode = $phpDocInfo->getVarTagValueNode(); | ||
if (! $varTagValueNode instanceof VarTagValueNode) { | ||
return false; | ||
} | ||
|
||
if ($varTagValueNode->type instanceof NullableTypeNode) { | ||
return false; | ||
} | ||
|
||
return $property->type instanceof NullableType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters