-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not prepend a \ to the type, if it is already Fully Qualified (#1863)
* Do not prepend a \ to the type, if it is already Fully Qualified * add test for issue #7023 * fix issue #7023 for php versions >= 7.4 * add test for issue #7023 with php version <= 7.3 * removed unused use
- Loading branch information
Showing
7 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
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
36 changes: 36 additions & 0 deletions
36
tests/Issues/Issue7023/DoNotPrependAnotherBackslashIfAlreadyPresent73Test.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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\Issue7023; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
/** | ||
* @see https://github.com/rectorphp/rector/issues/7023 | ||
*/ | ||
final class DoNotPrependAnotherBackslashIfAlreadyPresent73Test 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/7.3'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule_73.php'; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/Issues/Issue7023/DoNotPrependAnotherBackslashIfAlreadyPresentTest.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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\Issue7023; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
/** | ||
* @see https://github.com/rectorphp/rector/issues/7023 | ||
*/ | ||
final class DoNotPrependAnotherBackslashIfAlreadyPresentTest 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/7.4'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.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,43 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\Issue7023\Fixture; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Acme\Entity\User; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class Fixture | ||
{ | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="\Acme\Entity\User", inversedBy="images") | ||
* @ORM\JoinColumn(name="data_id", nullable=true) | ||
* @var User | ||
*/ | ||
private $user; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\Issue7023\Fixture; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Acme\Entity\User; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class Fixture | ||
{ | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="\Acme\Entity\User", inversedBy="images") | ||
* @ORM\JoinColumn(name="data_id", nullable=true) | ||
* @var \Acme\Entity\User|null | ||
*/ | ||
private $user; | ||
} | ||
?> |
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,43 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\Issue7023\Fixture; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Acme\Entity\User; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class Fixture | ||
{ | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="\Acme\Entity\User", inversedBy="images") | ||
* @ORM\JoinColumn(name="data_id", nullable=true) | ||
* @var User | ||
*/ | ||
private $user; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\Issue7023\Fixture; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Acme\Entity\User; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class Fixture | ||
{ | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="\Acme\Entity\User", inversedBy="images") | ||
* @ORM\JoinColumn(name="data_id", nullable=true) | ||
* @var User | ||
*/ | ||
private ?\Acme\Entity\User $user = null; | ||
} | ||
?> |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Doctrine\Rector\Property\TypedPropertyFromToOneRelationTypeRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(TypedPropertyFromToOneRelationTypeRector::class); | ||
}; |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Core\Configuration\Option; | ||
use Rector\Core\ValueObject\PhpVersionFeature; | ||
use Rector\Doctrine\Rector\Property\TypedPropertyFromToOneRelationTypeRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$parameters = $containerConfigurator->parameters(); | ||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::TYPED_PROPERTIES - 1); | ||
|
||
$services = $containerConfigurator->services(); | ||
$services->set(TypedPropertyFromToOneRelationTypeRector::class); | ||
}; |