Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeDeclaration] optionally only add types for hard coded return val…
…ues in `ReturnTypeFromStrictScalarReturnExprRector` (#5364)
- Loading branch information
Showing
19 changed files
with
466 additions
and
13 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
35 changes: 35 additions & 0 deletions
35
.../ClassMethod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/bool.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\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class Bool | ||
{ | ||
public function test($value) | ||
{ | ||
if ($value) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class Bool | ||
{ | ||
public function test($value): bool | ||
{ | ||
if ($value) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> |
49 changes: 49 additions & 0 deletions
49
...thod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/final_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,49 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class UntypedBaseClass | ||
{ | ||
public function test() | ||
{ | ||
return 0; | ||
} | ||
} | ||
|
||
class SomeChild2 extends UntypedBaseClass | ||
{ | ||
final public function test() | ||
{ | ||
return 'abc'; | ||
} | ||
|
||
} | ||
|
||
class SomeChild2Child extends SomeChild2 {} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class UntypedBaseClass | ||
{ | ||
public function test() | ||
{ | ||
return 0; | ||
} | ||
} | ||
|
||
class SomeChild2 extends UntypedBaseClass | ||
{ | ||
final public function test(): string | ||
{ | ||
return 'abc'; | ||
} | ||
|
||
} | ||
|
||
class SomeChild2Child extends SomeChild2 {} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...ClassMethod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/float.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\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class Float | ||
{ | ||
public function test() | ||
{ | ||
return 10.4; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class Float | ||
{ | ||
public function test(): float | ||
{ | ||
return 10.4; | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...od/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/float_negative.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\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class FloatNegative | ||
{ | ||
public function test() | ||
{ | ||
return -23.1; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class FloatNegative | ||
{ | ||
public function test(): float | ||
{ | ||
return -23.1; | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...od/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/float_positive.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\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class FloatPositive | ||
{ | ||
public function test() | ||
{ | ||
return +33.9; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class FloatPositive | ||
{ | ||
public function test(): float | ||
{ | ||
return +33.9; | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...r/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/int.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\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class Int | ||
{ | ||
public function test() | ||
{ | ||
return 1; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class Int | ||
{ | ||
public function test(): int | ||
{ | ||
return 1; | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...thod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/int_negative.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\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class IntNegative | ||
{ | ||
public function test() | ||
{ | ||
return -3; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class IntNegative | ||
{ | ||
public function test(): int | ||
{ | ||
return -3; | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...thod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/int_positive.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\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class IntPositive | ||
{ | ||
public function test() | ||
{ | ||
return +1; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class IntPositive | ||
{ | ||
public function test(): int | ||
{ | ||
return +1; | ||
} | ||
} | ||
|
||
?> |
11 changes: 11 additions & 0 deletions
11
...sMethod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/skip_calc.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,11 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class SkipCalc | ||
{ | ||
public function test() | ||
{ | ||
return 1 + 2; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...sMethod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/skip_call.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,11 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class SkipCall | ||
{ | ||
public function test($value) | ||
{ | ||
return strlen($value); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ethod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/skip_concat.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,11 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class SkipConcat | ||
{ | ||
public function test() | ||
{ | ||
return 'hello' . 'world'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...thod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/skip_ternary.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,11 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class SkipTernary | ||
{ | ||
public function test($value) | ||
{ | ||
return $value ? 10 : 0; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...hod/ReturnTypeFromStrictScalarReturnExprRector/FixtureHardCodedOnly/skip_variable.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,12 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\FixtureHardCodedOnly; | ||
|
||
class SkipVariable | ||
{ | ||
public function test() | ||
{ | ||
$value = 'test'; | ||
return $value; | ||
} | ||
} |
Oops, something went wrong.