Skip to content

Commit 7cc26a5

Browse files
authored
Prefer foreach over for (#1107)
1 parent 9052398 commit 7cc26a5

File tree

8 files changed

+8
-13
lines changed

8 files changed

+8
-13
lines changed

src/Language/BlockString.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public static function dedentValue(string $rawString): string
3232

3333
if ($commonIndent > 0) {
3434
for ($i = 1; $i < $linesLength; ++$i) {
35-
$line = $lines[$i];
36-
$lines[$i] = mb_substr($line, $commonIndent);
35+
$lines[$i] = mb_substr($lines[$i], $commonIndent);
3736
}
3837
}
3938

src/Language/Visitor.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,7 @@ public static function visit(object $root, array $visitor, ?array $keyMap = null
221221
}
222222

223223
$editOffset = 0;
224-
for ($ii = 0; $ii < count($edits); ++$ii) {
225-
$editKey = $edits[$ii][0];
226-
$editValue = $edits[$ii][1];
227-
224+
foreach ($edits as [$editKey, $editValue]) {
228225
if ($inArray) {
229226
$editKey -= $editOffset;
230227
}

src/Validator/Rules/NoFragmentCycles.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ protected function detectCycleRecursive(FragmentDefinitionNode $fragment, QueryV
6464

6565
$this->spreadPathIndexByName[$fragmentName] = count($this->spreadPath);
6666

67-
for ($i = 0; $i < count($spreadNodes); ++$i) {
68-
$spreadNode = $spreadNodes[$i];
67+
foreach ($spreadNodes as $spreadNode) {
6968
$spreadName = $spreadNode->name->value;
7069
$cycleIndex = $this->spreadPathIndexByName[$spreadName] ?? null;
7170

src/Validator/Rules/OverlappingFieldsCanBeMerged.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function findConflictsWithinSelectionSet(
102102

103103
$conflicts = [];
104104

105-
// (A) Find find all conflicts "within" the fields of this selection set.
105+
// (A) Find all conflicts "within" the fields of this selection set.
106106
// Note: this is the *only place* `collectConflictsWithin` is called.
107107
$this->collectConflictsWithin(
108108
$context,

tests/Language/LexerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use function json_decode;
1515
use PHPUnit\Framework\TestCase;
1616

17-
class LexerTest extends TestCase
17+
final class LexerTest extends TestCase
1818
{
1919
use ArraySubsetAsserts;
2020

tests/Language/VisitorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use function is_numeric;
2727
use function Safe\file_get_contents;
2828

29-
class VisitorTest extends ValidatorTestCase
29+
final class VisitorTest extends ValidatorTestCase
3030
{
3131
/**
3232
* @see it('validates path argument')

tests/Validator/QueryComplexityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use GraphQL\Validator\Rules\QueryComplexity;
1212
use GraphQL\Validator\ValidationContext;
1313

14-
class QueryComplexityTest extends QuerySecurityTestCase
14+
final class QueryComplexityTest extends QuerySecurityTestCase
1515
{
1616
private static QueryComplexity $rule;
1717

tests/Validator/QueryDepthTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use function sprintf;
77
use function str_replace;
88

9-
class QueryDepthTest extends QuerySecurityTestCase
9+
final class QueryDepthTest extends QuerySecurityTestCase
1010
{
1111
/**
1212
* @param array<int, array<string, mixed>> $expectedErrors

0 commit comments

Comments
 (0)