Skip to content

Commit 39f490b

Browse files
committed
Improve types
1 parent 25e0384 commit 39f490b

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/CodePatcher.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ private function applyPatch(Patch $patch, string $code): string
121121
return $this->printer->prettyPrintFile($statements);
122122
}
123123

124+
/**
125+
* @param array<Stmt> $statements
126+
*/
124127
public function isFirstStatementStrictTypesDeclare(array $statements): bool
125128
{
126129
return isset($statements[0])

src/Patch/ForceStrictTypes.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
namespace PhpSchool\PhpWorkshop\Patch;
44

55
use PhpParser\Node\Scalar\LNumber;
6+
use PhpParser\Node\Stmt;
67
use PhpParser\Node\Stmt\Declare_;
78
use PhpParser\Node\Stmt\DeclareDeclare;
89

910
class ForceStrictTypes implements Transformer
1011
{
11-
public function transform(array $ast): array
12+
/**
13+
* @param array<Stmt> $statements
14+
* @return array<Stmt>
15+
*/
16+
public function transform(array $statements): array
1217
{
13-
if ($this->isFirstStatementStrictTypesDeclare($ast)) {
14-
return $ast;
18+
if ($this->isFirstStatementStrictTypesDeclare($statements)) {
19+
return $statements;
1520
}
1621

1722
$declare = new \PhpParser\Node\Stmt\Declare_([
@@ -21,11 +26,14 @@ public function transform(array $ast): array
2126
)
2227
]);
2328

24-
return array_merge([$declare], $ast);
29+
return array_merge([$declare], $statements);
2530
}
2631

32+
/**
33+
* @param array<Stmt> $statements
34+
*/
2735
public function isFirstStatementStrictTypesDeclare(array $statements): bool
2836
{
2937
return isset($statements[0]) && $statements[0] instanceof Declare_;
3038
}
31-
}
39+
}

src/Patch/Transformer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
namespace PhpSchool\PhpWorkshop\Patch;
44

5+
use PhpParser\Node\Stmt;
6+
57
interface Transformer
68
{
7-
public function transform(array $ast): array;
9+
/**
10+
* @param array<Stmt> $statements
11+
* @return array<Stmt>
12+
*/
13+
public function transform(array $statements): array;
814
}

0 commit comments

Comments
 (0)