Skip to content

Commit 743d9a0

Browse files
committed
feat: create new SafeDeclareStrictTypesRector
1 parent 13f7abd commit 743d9a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1031
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"tests/debug_functions.php",
100100
"rules-tests/Transform/Rector/FuncCall/FuncCallToMethodCallRector/Source/some_view_function.php",
101101
"rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Source/FunctionTyped.php",
102+
"rules-tests/TypeDeclaration/Rector/StmtsAwareInterface/SafeDeclareStrictTypesRector/Source/functions.php",
102103
"rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Source/ParentClass.php",
103104
"rules-tests/CodingStyle/Rector/Closure/StaticClosureRector/Source/functions.php"
104105
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
class Test
46
{
57
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
4+
5+
$arrow = fn (): int => 42;
6+
7+
$arrowWithParam = fn (int $x): int => $x + 1;
8+
9+
$arrowString = fn (): string => 'hello';
10+
11+
?>
12+
-----
13+
<?php
14+
15+
declare(strict_types=1);
16+
17+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
18+
19+
$arrow = fn (): int => 42;
20+
21+
$arrowWithParam = fn (int $x): int => $x + 1;
22+
23+
$arrowString = fn (): string => 'hello';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
4+
5+
$closure = function (): int {
6+
return 42;
7+
};
8+
9+
$closureWithParam = function (int $x): int {
10+
return $x + 1;
11+
};
12+
13+
?>
14+
-----
15+
<?php
16+
17+
declare(strict_types=1);
18+
19+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
20+
21+
$closure = function (): int {
22+
return 42;
23+
};
24+
25+
$closureWithParam = function (int $x): int {
26+
return $x + 1;
27+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
4+
5+
use Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Source\TypedClass;
6+
7+
new TypedClass('John', 25);
8+
9+
?>
10+
-----
11+
<?php
12+
13+
declare(strict_types=1);
14+
15+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
16+
17+
use Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Source\TypedClass;
18+
19+
new TypedClass('John', 25);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
4+
5+
use function Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Source\acceptsInt;
6+
7+
function callWithCast(): void
8+
{
9+
acceptsInt((int) '123');
10+
}
11+
12+
?>
13+
-----
14+
<?php
15+
16+
declare(strict_types=1);
17+
18+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
19+
20+
use function Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Source\acceptsInt;
21+
22+
function callWithCast(): void
23+
{
24+
acceptsInt((int) '123');
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
4+
5+
$fn = strlen(...);
6+
7+
$upperFn = strtoupper(...);
8+
9+
?>
10+
-----
11+
<?php
12+
13+
declare(strict_types=1);
14+
15+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
16+
17+
$fn = strlen(...);
18+
19+
$upperFn = strtoupper(...);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
4+
5+
use function Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Source\acceptsFloat;
6+
7+
acceptsFloat(123);
8+
9+
?>
10+
-----
11+
<?php
12+
13+
declare(strict_types=1);
14+
15+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
16+
17+
use function Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Source\acceptsFloat;
18+
19+
acceptsFloat(123);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
4+
5+
use Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Source\TypedClass;
6+
7+
function useMethodCalls(TypedClass $obj): void
8+
{
9+
$obj->add(1, 2);
10+
}
11+
12+
?>
13+
-----
14+
<?php
15+
16+
declare(strict_types=1);
17+
18+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
19+
20+
use Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Source\TypedClass;
21+
22+
function useMethodCalls(TypedClass $obj): void
23+
{
24+
$obj->add(1, 2);
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
4+
5+
function acceptsNamedArgs(string $name, int $age): void
6+
{
7+
}
8+
9+
function callWithNamedArgs(): void
10+
{
11+
acceptsNamedArgs(age: 25, name: 'John');
12+
}
13+
14+
?>
15+
-----
16+
<?php
17+
18+
declare(strict_types=1);
19+
20+
namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;
21+
22+
function acceptsNamedArgs(string $name, int $age): void
23+
{
24+
}
25+
26+
function callWithNamedArgs(): void
27+
{
28+
acceptsNamedArgs(age: 25, name: 'John');
29+
}

0 commit comments

Comments
 (0)