-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add ParamAnnotationIncorrectNullableRector for fixing incor…
- Loading branch information
1 parent
1c1732f
commit c509923
Showing
27 changed files
with
959 additions
and
2 deletions.
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
47 changes: 47 additions & 0 deletions
47
...assMethod/ParamAnnotationIncorrectNullableRector/Fixture/param-annotation-complex.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,47 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationComplex | ||
{ | ||
/** | ||
* @Serializer\VirtualProperty | ||
* @Serializer\Type("array<DateTime>") | ||
* @Assert\All({ | ||
* @Assert\NotBlank, | ||
* @AppAssert\Country, | ||
* }) | ||
* @param \DateTime[] $dateTimes | ||
*/ | ||
public function setDateTimes(?array $dateTimes): self | ||
{ | ||
$this->dateTimes = $dateTimes; | ||
|
||
return $this; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationComplex | ||
{ | ||
/** | ||
* @Serializer\VirtualProperty | ||
* @Serializer\Type("array<DateTime>") | ||
* @Assert\All({ | ||
* @Assert\NotBlank, | ||
* @AppAssert\Country, | ||
* }) | ||
* @param \DateTime[]|null $dateTimes | ||
*/ | ||
public function setDateTimes(?array $dateTimes): self | ||
{ | ||
$this->dateTimes = $dateTimes; | ||
|
||
return $this; | ||
} | ||
} | ||
?> |
27 changes: 27 additions & 0 deletions
27
...rectNullableRector/Fixture/param-annotation-incorrectly-includes-null-in-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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
/** | ||
* @param \DateTime[]|null $dateTimes | ||
*/ | ||
function reverseDateTimes(array $dateTimes): array | ||
{ | ||
return array_reverse($dateTimes); | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
/** | ||
* @param \DateTime[] $dateTimes | ||
*/ | ||
function reverseDateTimes(array $dateTimes): array | ||
{ | ||
return array_reverse($dateTimes); | ||
} | ||
|
||
?> |
35 changes: 35 additions & 0 deletions
35
...orrectNullableRector/Fixture/param-annotation-incorrectly-includes-null-on-scalar.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIncorrectlyIncludesNullOnScalar | ||
{ | ||
/** | ||
* @param string|null $text | ||
*/ | ||
public function setDateTimes(string $text): self | ||
{ | ||
$this->text = $text; | ||
|
||
return $this; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIncorrectlyIncludesNullOnScalar | ||
{ | ||
/** | ||
* @param string $text | ||
*/ | ||
public function setDateTimes(string $text): self | ||
{ | ||
$this->text = $text; | ||
|
||
return $this; | ||
} | ||
} | ||
?> |
35 changes: 35 additions & 0 deletions
35
...or/Fixture/param-annotation-incorrectly-includes-null-with-non-null-default-value.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIncorrectlyIncludesNullWithNonNullDefaultValue | ||
{ | ||
/** | ||
* @param bool|null $flag | ||
*/ | ||
public function setFlag(bool $flag = true): self | ||
{ | ||
$this->flag = $flag; | ||
|
||
return $this; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIncorrectlyIncludesNullWithNonNullDefaultValue | ||
{ | ||
/** | ||
* @param bool $flag | ||
*/ | ||
public function setFlag(bool $flag = true): self | ||
{ | ||
$this->flag = $flag; | ||
|
||
return $this; | ||
} | ||
} | ||
?> |
39 changes: 39 additions & 0 deletions
39
...ure/param-annotation-incorrectly-includes-null-with-null-default-value-from-const.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,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIncorrectlyIncludesNullWithNonNullDefaultValueFromConst | ||
{ | ||
private const FLAG_DEFAULT_VALUE = true; | ||
|
||
/** | ||
* @param bool|null $flag | ||
*/ | ||
public function setFlag(bool $flag = self::FLAG_DEFAULT_VALUE): self | ||
{ | ||
$this->flag = $flag; | ||
|
||
return $this; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIncorrectlyIncludesNullWithNonNullDefaultValueFromConst | ||
{ | ||
private const FLAG_DEFAULT_VALUE = true; | ||
|
||
/** | ||
* @param bool $flag | ||
*/ | ||
public function setFlag(bool $flag = self::FLAG_DEFAULT_VALUE): self | ||
{ | ||
$this->flag = $flag; | ||
|
||
return $this; | ||
} | ||
} | ||
?> |
35 changes: 35 additions & 0 deletions
35
...otationIncorrectNullableRector/Fixture/param-annotation-incorrectly-includes-null.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIncorrectlyIncludesNull | ||
{ | ||
/** | ||
* @param \DateTime[]|null $dateTimes | ||
*/ | ||
public function setDateTimes(array $dateTimes): self | ||
{ | ||
$this->dateTimes = $dateTimes; | ||
|
||
return $this; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIncorrectlyIncludesNull | ||
{ | ||
/** | ||
* @param \DateTime[] $dateTimes | ||
*/ | ||
public function setDateTimes(array $dateTimes): self | ||
{ | ||
$this->dateTimes = $dateTimes; | ||
|
||
return $this; | ||
} | ||
} | ||
?> |
27 changes: 27 additions & 0 deletions
27
...ationIncorrectNullableRector/Fixture/param-annotation-is-missing-null-in-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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
/** | ||
* @param \DateTime[] $dateTimes | ||
*/ | ||
function reverseDateTimes(?array $dateTimes): array | ||
{ | ||
return array_reverse($dateTimes); | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
/** | ||
* @param \DateTime[]|null $dateTimes | ||
*/ | ||
function reverseDateTimes(?array $dateTimes): array | ||
{ | ||
return array_reverse($dateTimes); | ||
} | ||
|
||
?> |
43 changes: 43 additions & 0 deletions
43
...notationIncorrectNullableRector/Fixture/param-annotation-is-missing-null-multiple.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\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIsMissingNullMultiple | ||
{ | ||
/** | ||
* @param \DateTime[] $dateTimes | ||
* @param array<\DateTimeImmutable> $immutableDateTimes | ||
* @param array<\DateTimeInterface>|null $dateTimeInterfaces | ||
*/ | ||
public function setDateTimes(?array $dateTimes, ?array $immutableDateTimes, ?array $dateTimeInterfaces): self | ||
{ | ||
$this->dateTimes = $dateTimes; | ||
$this->immutableDateTimes = $immutableDateTimes; | ||
$this->dateTimeInterfaces = $dateTimeInterfaces; | ||
|
||
return $this; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIsMissingNullMultiple | ||
{ | ||
/** | ||
* @param \DateTime[]|null $dateTimes | ||
* @param \DateTimeImmutable[]|null $immutableDateTimes | ||
* @param array<\DateTimeInterface>|null $dateTimeInterfaces | ||
*/ | ||
public function setDateTimes(?array $dateTimes, ?array $immutableDateTimes, ?array $dateTimeInterfaces): self | ||
{ | ||
$this->dateTimes = $dateTimes; | ||
$this->immutableDateTimes = $immutableDateTimes; | ||
$this->dateTimeInterfaces = $dateTimeInterfaces; | ||
|
||
return $this; | ||
} | ||
} | ||
?> |
35 changes: 35 additions & 0 deletions
35
...ncorrectNullableRector/Fixture/param-annotation-is-missing-null-with-default-null.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIsMissingNullWithDefaultNull | ||
{ | ||
/** | ||
* @param \DateTime[] $dateTimes | ||
*/ | ||
public function setDateTimes(array $dateTimes = null): self | ||
{ | ||
$this->dateTimes = $dateTimes; | ||
|
||
return $this; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\Fixture; | ||
|
||
final class ParamAnnotationIsMissingNullWithDefaultNull | ||
{ | ||
/** | ||
* @param \DateTime[]|null $dateTimes | ||
*/ | ||
public function setDateTimes(array $dateTimes = null): self | ||
{ | ||
$this->dateTimes = $dateTimes; | ||
|
||
return $this; | ||
} | ||
} | ||
?> |
Oops, something went wrong.