Skip to content

Commit

Permalink
[Php74] Handle conflict with alias on TypedPropertyRector (#899)
Browse files Browse the repository at this point in the history
* [Php74] Handle conflict with alias on TypedPropertyRector

* update

* more conflict example

* update

* update

* Fixed 🎉

* added failing fixture alias never used

* Fixed 🎉

* clean up

* clean up

* union failign test

* Fixed 🎉

* cs fix

* Fixed 🎉

* Fixed 🎉

* skip nullable var union

* more fixtures on use alias only

* final touch: more fixture
  • Loading branch information
samsonasik committed Sep 20, 2021
1 parent a8a79d0 commit e78fadd
Show file tree
Hide file tree
Showing 14 changed files with 527 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias
{
/**
* @var Alias
*/
private $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias
{
private Alias $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias2
{
/**
* @var AnotherClass
*/
private $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias2
{
private \Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias3
{
/**
* @var AnotherClass|\stdClass
*/
private $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}

public function setStdClass()
{
$this->anotherClass = new \stdClass;
}
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias3
{
private \Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass|\stdClass $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}

public function setStdClass()
{
$this->anotherClass = new \stdClass;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias4
{
/**
* @var Alias|\stdClass
*/
private $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}

public function setStdClass()
{
$this->anotherClass = new \stdClass;
}
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias4
{
private Alias|\stdClass $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}

public function setStdClass()
{
$this->anotherClass = new \stdClass;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class SkipInvalidvarNullable
{
/**
* @var ?AnotherClass|\stdClass
*/
private $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}

public function setStdClass()
{
$this->anotherClass = new \stdClass;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class UseAliasOnly
{
/**
* @var Alias
*/
private $anotherClass;

public function __construct(Alias $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class UseAliasOnly
{
private Alias $anotherClass;

public function __construct(Alias $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class UseAliasOnly2
{
/**
* @var Alias|\stdClass
*/
private $anotherClass;

public function __construct(Alias $anotherClass)
{
$this->anotherClass = $anotherClass;
}

public function setStdClass()
{
$this->anotherClass = new \stdClass;
}
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class UseAliasOnly2
{
private Alias|\stdClass $anotherClass;

public function __construct(Alias $anotherClass)
{
$this->anotherClass = $anotherClass;
}

public function setStdClass()
{
$this->anotherClass = new \stdClass;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class UseAliasOnly3
{
private $anotherClass;

public function __construct(Alias $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class UseAliasOnly3
{
private Alias $anotherClass;

public function __construct(Alias $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureImported;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias
{
/**
* @var Alias
*/
private $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\Property\TypedPropertyRector\FixtureImported;

use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Tests\Php74\Rector\Property\TypedPropertyRector\Source\AnotherClass as Alias;

final class ConflictWithAlias
{
private Alias $anotherClass;

public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}

?>

0 comments on commit e78fadd

Please sign in to comment.