Skip to content

Commit c2d96ae

Browse files
committed
[ci] fail on missed final class
1 parent 00db9a1 commit c2d96ae

6 files changed

Lines changed: 20 additions & 57 deletions

File tree

.github/workflows/code_analysis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
-
5252
name: 'Finalize classes'
53-
run: vendor/bin/swiss-knife finalize-classes src tests
53+
run: vendor/bin/swiss-knife finalize-classes src tests --dry-run
5454

5555
-
5656
name: 'Detect composer dependency issues'

rules-tests/TypeDeclaration/Rector/ClassMethod/AddReturnTypeFromTryCatchTypeRector/config/configured_rule_with_treat_classes_as_final.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

rules-tests/TypeDeclaration/Rector/ClassMethod/AddReturnTypeFromTryCatchTypeRector/config/intersection_config.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

rules-tests/TypeDeclaration/Rector/ClassMethod/AddReturnTypeFromTryCatchTypeRector/config/union_config.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ public function configure(array $configuration): void
101101
$this->arrayDimFetchToMethodCalls = $configuration;
102102
}
103103

104-
private function handleIsset(Isset_ $node): Expr|int|null
104+
private function handleIsset(Isset_ $isset): Expr|int|null
105105
{
106106
$issets = [];
107107
$exprs = [];
108108

109-
foreach ($node->vars as $var) {
109+
foreach ($isset->vars as $var) {
110110
if ($var instanceof ArrayDimFetch) {
111111
$methodCall = $this->getMethodCall($var, 'exists');
112112

113-
if ($methodCall !== null) {
113+
if ($methodCall instanceof MethodCall) {
114114
$exprs[] = $methodCall;
115115
continue;
116116
}
@@ -124,30 +124,30 @@ private function handleIsset(Isset_ $node): Expr|int|null
124124
}
125125

126126
if ($issets !== []) {
127-
$node->vars = $issets;
128-
array_unshift($exprs, $node);
127+
$isset->vars = $issets;
128+
array_unshift($exprs, $isset);
129129
}
130130

131131
return array_reduce(
132132
$exprs,
133-
fn (?Expr $carry, Expr $expr) => $carry === null ? $expr : new BooleanAnd($carry, $expr),
133+
fn (?Expr $carry, Expr $expr): Isset_|MethodCall|BooleanAnd => $carry instanceof Expr ? new BooleanAnd($carry, $expr) : $expr,
134134
null,
135135
);
136136
}
137137

138138
/**
139139
* @return Stmt[]|int
140140
*/
141-
private function handleUnset(Unset_ $node): array|int
141+
private function handleUnset(Unset_ $unset): array|int
142142
{
143143
$unsets = [];
144144
$stmts = [];
145145

146-
foreach ($node->vars as $var) {
146+
foreach ($unset->vars as $var) {
147147
if ($var instanceof ArrayDimFetch) {
148148
$methodCall = $this->getMethodCall($var, 'unset');
149149

150-
if ($methodCall !== null) {
150+
if ($methodCall instanceof MethodCall) {
151151
$stmts[] = new Expression($methodCall);
152152
continue;
153153
}
@@ -161,8 +161,8 @@ private function handleUnset(Unset_ $node): array|int
161161
}
162162

163163
if ($unsets !== []) {
164-
$node->vars = $unsets;
165-
array_unshift($stmts, $node);
164+
$unset->vars = $unsets;
165+
array_unshift($stmts, $unset);
166166
}
167167

168168
return $stmts;
@@ -171,14 +171,14 @@ private function handleUnset(Unset_ $node): array|int
171171
/**
172172
* @param 'get'|'set'|'exists'|'unset' $action
173173
*/
174-
private function getMethodCall(ArrayDimFetch $fetch, string $action, ?Expr $value = null): ?MethodCall
174+
private function getMethodCall(ArrayDimFetch $arrayDimFetch, string $action, ?Expr $expr = null): ?MethodCall
175175
{
176-
if (!$fetch->dim instanceof Node) {
176+
if (!$arrayDimFetch->dim instanceof Node) {
177177
return null;
178178
}
179179

180180
foreach ($this->arrayDimFetchToMethodCalls as $arrayDimFetchToMethodCall) {
181-
if (!$this->isObjectType($fetch->var, $arrayDimFetchToMethodCall->getObjectType())) {
181+
if (!$this->isObjectType($arrayDimFetch->var, $arrayDimFetchToMethodCall->getObjectType())) {
182182
continue;
183183
}
184184

@@ -193,13 +193,13 @@ private function getMethodCall(ArrayDimFetch $fetch, string $action, ?Expr $valu
193193
continue;
194194
}
195195

196-
$args = [new Arg($fetch->dim)];
196+
$args = [new Arg($arrayDimFetch->dim)];
197197

198-
if ($value instanceof Expr) {
199-
$args[] = new Arg($value);
198+
if ($expr instanceof Expr) {
199+
$args[] = new Arg($expr);
200200
}
201201

202-
return new MethodCall($fetch->var, $method, $args);
202+
return new MethodCall($arrayDimFetch->var, $method, $args);
203203
}
204204

205205
return null;

rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeFromTryCatchTypeRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function matchReturnType(TryCatch|Catch_ $tryOrCatch): ?Type
160160
continue;
161161
}
162162

163-
return $this->nodeTypeResolver->getType($stmt->expr);
163+
return $this->nodeTypeResolver->getNativeType($stmt->expr);
164164
}
165165

166166
return null;

0 commit comments

Comments
 (0)