-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [TypeDeclaration] Convert inline @var tag to assert() * Remove rule from set * Add incorrectly removed comma * Improve check for changed phpdoc and add new tests * Update node removal * Update check for php doc and update how we get the var tags * Return null instead of false
- Loading branch information
1 parent
71fb2e4
commit 7f9c6b0
Showing
23 changed files
with
819 additions
and
1 deletion.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...n/Rector/Expression/InlineVarDocTagToAssertRector/Fixture/convert_all_basic_types.php.inc
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,73 @@ | ||
<?php | ||
|
||
/** @var false $foo */ | ||
$foo = getFalse(); | ||
|
||
/** @var true $foo */ | ||
$foo = getTrue(); | ||
|
||
/** @var string $foo */ | ||
$foo = getString(); | ||
|
||
/** @var float $foo */ | ||
$foo = getFloat(); | ||
|
||
/** @var int $foo */ | ||
$foo = getInt(); | ||
|
||
/** @var bool $foo */ | ||
$foo = getBool(); | ||
|
||
/** @var null $foo */ | ||
$foo = getNull(); | ||
|
||
/** @var callable $foo */ | ||
$foo = getCallable(); | ||
|
||
/** @var object $foo */ | ||
$foo = getObject(); | ||
|
||
/** @var array $foo */ | ||
$foo = getArray(); | ||
|
||
/** @var iterable $foo */ | ||
$foo = getIterable(); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
$foo = getFalse(); | ||
assert($foo === false); | ||
|
||
$foo = getTrue(); | ||
assert($foo === true); | ||
|
||
$foo = getString(); | ||
assert(is_string($foo)); | ||
|
||
$foo = getFloat(); | ||
assert(is_float($foo)); | ||
|
||
$foo = getInt(); | ||
assert(is_int($foo)); | ||
|
||
$foo = getBool(); | ||
assert(is_bool($foo)); | ||
|
||
$foo = getNull(); | ||
assert($foo === null); | ||
|
||
$foo = getCallable(); | ||
assert(is_callable($foo)); | ||
|
||
$foo = getObject(); | ||
assert(is_object($foo)); | ||
|
||
$foo = getArray(); | ||
assert(is_array($foo)); | ||
|
||
$foo = getIterable(); | ||
assert(is_iterable($foo)); | ||
|
||
?> |
43 changes: 43 additions & 0 deletions
43
...r/Expression/InlineVarDocTagToAssertRector/Fixture/convert_classes_and_interfaces.php.inc
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\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\Fixture; | ||
|
||
use Foo\Bar; | ||
use Rector\Tests\Renaming\Rector\MethodCall\RenameMethodRector\Source\FooInterface; | ||
use Traversable; | ||
|
||
/** @var Bar $foo */ | ||
$foo = getBar(); | ||
|
||
/** @var \Foo\Bar $foo */ | ||
$foo = getFooBar(); | ||
|
||
/** @var FooInterface $foo */ | ||
$foo = getFooInterface(); | ||
|
||
/** @var Traversable $foo */ | ||
$foo = getTraversable(); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\Fixture; | ||
|
||
use Foo\Bar; | ||
use Rector\Tests\Renaming\Rector\MethodCall\RenameMethodRector\Source\FooInterface; | ||
use Traversable; | ||
|
||
$foo = getBar(); | ||
assert($foo instanceof Bar); | ||
|
||
$foo = getFooBar(); | ||
assert($foo instanceof \Foo\Bar); | ||
|
||
$foo = getFooInterface(); | ||
assert($foo instanceof FooInterface); | ||
|
||
$foo = getTraversable(); | ||
assert($foo instanceof Traversable); | ||
|
||
?> |
19 changes: 19 additions & 0 deletions
19
...ector/Expression/InlineVarDocTagToAssertRector/Fixture/convert_intersection_types.php.inc
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,19 @@ | ||
<?php | ||
|
||
/** @var Foo&Bar $foo */ | ||
$foo = getFooAndBar(); | ||
|
||
/** @var \Foo&\Bar $foo */ | ||
$foo = getFooAndBar(); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
$foo = getFooAndBar(); | ||
assert($foo instanceof Foo && $foo instanceof Bar); | ||
|
||
$foo = getFooAndBar(); | ||
assert($foo instanceof \Foo && $foo instanceof \Bar); | ||
|
||
?> |
19 changes: 19 additions & 0 deletions
19
...on/Rector/Expression/InlineVarDocTagToAssertRector/Fixture/convert_nullable_types.php.inc
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,19 @@ | ||
<?php | ||
|
||
/** @var ?string $foo */ | ||
$foo = getNullableString(); | ||
|
||
/** @var ?Foo $foo */ | ||
$foo = getNullableFoo(); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
$foo = getNullableString(); | ||
assert(is_string($foo) || $foo === null); | ||
|
||
$foo = getNullableFoo(); | ||
assert($foo instanceof Foo || $foo === null); | ||
|
||
?> |
45 changes: 45 additions & 0 deletions
45
...r/Expression/InlineVarDocTagToAssertRector/Fixture/convert_self_static_and_parent.php.inc
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,45 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\Fixture; | ||
|
||
class OtherClass {} | ||
|
||
class SomeClass extends OtherClass | ||
{ | ||
function test() | ||
{ | ||
/** @var self $foo */ | ||
$foo = getSelf(); | ||
|
||
/** @var static $foo */ | ||
$foo = getStatic(); | ||
|
||
/** @var parent $foo */ | ||
$foo = getParent(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\Fixture; | ||
|
||
class OtherClass {} | ||
|
||
class SomeClass extends OtherClass | ||
{ | ||
function test() | ||
{ | ||
$foo = getSelf(); | ||
assert($foo instanceof self); | ||
|
||
$foo = getStatic(); | ||
assert($foo instanceof static); | ||
|
||
$foo = getParent(); | ||
assert($foo instanceof parent); | ||
} | ||
} | ||
|
||
?> |
43 changes: 43 additions & 0 deletions
43
...ation/Rector/Expression/InlineVarDocTagToAssertRector/Fixture/convert_union_types.php.inc
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 | ||
|
||
/** @var string|false $foo */ | ||
$foo = getStringOrFalse(); | ||
|
||
/** @var string|int|null $foo */ | ||
$foo = getStringOrFalse(); | ||
|
||
/** @var int|float|bool|string|array $foo */ | ||
$foo = getMultipleTypes(); | ||
|
||
/** @var string|Foo $foo */ | ||
$foo = getStringOrFoo(); | ||
|
||
/** @var Foo|Bar $foo */ | ||
$foo = getFooOrBar(); | ||
|
||
/** @var \Foo|\Bar $foo */ | ||
$foo = getFooOrBar(); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
$foo = getStringOrFalse(); | ||
assert(is_string($foo) || $foo === false); | ||
|
||
$foo = getStringOrFalse(); | ||
assert(is_string($foo) || is_int($foo) || $foo === null); | ||
|
||
$foo = getMultipleTypes(); | ||
assert(is_int($foo) || is_float($foo) || is_bool($foo) || is_string($foo) || is_array($foo)); | ||
|
||
$foo = getStringOrFoo(); | ||
assert(is_string($foo) || $foo instanceof Foo); | ||
|
||
$foo = getFooOrBar(); | ||
assert($foo instanceof Foo || $foo instanceof Bar); | ||
|
||
$foo = getFooOrBar(); | ||
assert($foo instanceof \Foo || $foo instanceof \Bar); | ||
|
||
?> |
21 changes: 21 additions & 0 deletions
21
...xpression/InlineVarDocTagToAssertRector/Fixture/convert_variable_in_some_function.php.inc
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,21 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\Fixture; | ||
|
||
function test() { | ||
/** @var string $foo */ | ||
$foo = getString(); | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\Fixture; | ||
|
||
function test() { | ||
$foo = getString(); | ||
assert(is_string($foo)); | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
.../Expression/InlineVarDocTagToAssertRector/Fixture/convert_variable_in_some_method.php.inc
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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\Fixture; | ||
|
||
final class SomeClass | ||
{ | ||
function test() { | ||
/** @var string $foo */ | ||
$foo = getString(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\Fixture; | ||
|
||
final class SomeClass | ||
{ | ||
function test() { | ||
$foo = getString(); | ||
assert(is_string($foo)); | ||
} | ||
} | ||
|
||
?> |
93 changes: 93 additions & 0 deletions
93
...aration/Rector/Expression/InlineVarDocTagToAssertRector/Fixture/preserve_comments.php.inc
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,93 @@ | ||
<?php | ||
|
||
/** | ||
* @var string $foo | ||
* This is the string | ||
*/ | ||
$foo = getString(); | ||
|
||
/** | ||
* We are going to do something | ||
* @var string $foo | ||
*/ | ||
$foo = getString(); | ||
|
||
/** | ||
* @var string $foo | ||
* @deprecated | ||
*/ | ||
$foo = getString(); | ||
|
||
/** | ||
* @var string $foo | ||
* @see getStringTest() | ||
* Please do not change | ||
*/ | ||
$foo = getString(); | ||
|
||
/** | ||
* @var string $foo | ||
* @var int $bar | ||
*/ | ||
$foo = getString(); | ||
$bar = getInt(); | ||
|
||
/** @var string $foo this is the string */ | ||
$foo = getString(); | ||
|
||
/* normal comment */ | ||
/** @var string $foo */ | ||
$foo = getString(); | ||
|
||
/** @var string $foo */ | ||
// normal comment | ||
$foo = getString(); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
/** | ||
* @var string $foo | ||
* This is the string | ||
*/ | ||
$foo = getString(); | ||
|
||
/** | ||
* We are going to do something | ||
*/ | ||
$foo = getString(); | ||
assert(is_string($foo)); | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
$foo = getString(); | ||
assert(is_string($foo)); | ||
|
||
/** | ||
* @see getStringTest() | ||
* Please do not change | ||
*/ | ||
$foo = getString(); | ||
assert(is_string($foo)); | ||
|
||
/** | ||
* @var int $bar | ||
*/ | ||
$foo = getString(); | ||
assert(is_string($foo)); | ||
$bar = getInt(); | ||
|
||
/** @var string $foo this is the string */ | ||
$foo = getString(); | ||
|
||
/* normal comment */ | ||
$foo = getString(); | ||
assert(is_string($foo)); | ||
|
||
// normal comment | ||
$foo = getString(); | ||
assert(is_string($foo)); | ||
|
||
?> |
Oops, something went wrong.