Skip to content

Commit 6b8286d

Browse files
authored
Simplify unnecessary continue constructs (#1054)
1 parent 9faf59a commit 6b8286d

33 files changed

+296
-454
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
8888
- Remove deprecated public property access to `FieldDefinition::$type`
8989
- Remove alias `GraphQL\Validator\Rules\AbstractQuerySecurity`, use `GraphQL\Validator\Rules\QuerySecurityRule`
9090
- Remove alias `GraphQL\Validator\Rules\AbstractValidationRule`, use `GraphQL\Validator\Rules\ValidationRule`
91+
- Remove alias `GraphQL\Utils\FindBreakingChanges`, use `GraphQL\Utils\BreakingChangesFinder`
9192
- Remove `OperationParams` method `getOriginalInput()` in favor of public property `$originalInput`
9293
- Remove `OperationParams` method `isReadOnly()` in favor of public property `$readOnly`
9394
- Remove `Utils::withErrorHandling()`

benchmarks/Utils/QueryGenerator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ public function __construct(Schema $schema, float $percentOfLeafFields)
3535

3636
$totalFields = 0;
3737
foreach ($schema->getTypeMap() as $type) {
38-
if (! ($type instanceof ObjectType)) {
39-
continue;
38+
if ($type instanceof ObjectType) {
39+
$totalFields += count($type->getFieldNames());
4040
}
41-
42-
$totalFields += count($type->getFieldNames());
4341
}
4442

4543
$this->maxLeafFields = max(1, (int) round($totalFields * $percentOfLeafFields));

generate-class-reference.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ function renderClass(ReflectionClass $class, array $options): string
8686
if ($options['props'] ?? true) {
8787
$props = [];
8888
foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
89-
if (! isApi($property)) {
90-
continue;
89+
if (isApi($property)) {
90+
$props[] = renderProp($property);
9191
}
92-
93-
$props[] = renderProp($property);
9492
}
9593

9694
if (count($props) > 0) {
@@ -102,11 +100,9 @@ function renderClass(ReflectionClass $class, array $options): string
102100
if ($options['methods'] ?? true) {
103101
$methods = [];
104102
foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
105-
if (! isApi($method)) {
106-
continue;
103+
if (isApi($method)) {
104+
$methods[] = renderMethod($method);
107105
}
108-
109-
$methods[] = renderMethod($method);
110106
}
111107

112108
if (count($methods) > 0) {

src/Error/Error.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,9 @@ public function getPositions(): array
206206

207207
if (isset($this->nodes)) {
208208
foreach ($this->nodes as $node) {
209-
$start = $node->loc->start ?? null;
210-
if (null === $start) {
211-
continue;
209+
if (isset($node->loc->start)) {
210+
$this->positions[] = $node->loc->start;
212211
}
213-
214-
$this->positions[] = $start;
215212
}
216213
}
217214
}
@@ -248,11 +245,9 @@ public function getLocations(): array
248245
}
249246
} elseif (null !== $nodes && 0 !== count($nodes)) {
250247
foreach ($nodes as $node) {
251-
if (! isset($node->loc->source)) {
252-
continue;
248+
if (isset($node->loc->source)) {
249+
$this->locations[] = $node->loc->source->getLocation($node->loc->start);
253250
}
254-
255-
$this->locations[] = $node->loc->source->getLocation($node->loc->start);
256251
}
257252
}
258253
}

src/Error/FormattedError.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,14 @@ public static function printError(Error $error): string
6262
$nodes = $error->nodes;
6363
if (isset($nodes) && count($nodes) > 0) {
6464
foreach ($nodes as $node) {
65-
if (! isset($node->loc->source)) {
66-
continue;
65+
if (isset($node->loc->source)) {
66+
$location = $node->loc;
67+
$source = $location->source;
68+
$printedLocations[] = self::highlightSourceAtLocation(
69+
$source,
70+
$source->getLocation($location->start)
71+
);
6772
}
68-
69-
$location = $node->loc;
70-
$source = $location->source;
71-
$printedLocations[] = self::highlightSourceAtLocation(
72-
$source,
73-
$source->getLocation($location->start)
74-
);
7573
}
7674
} elseif (null !== $error->getSource() && 0 !== count($error->getLocations())) {
7775
$source = $error->getSource();

src/Executor/Promise/Adapter/ReactPromiseAdapter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ public function all(array $promisesOrValues): Promise
5757
// TODO: rework with generators when PHP minimum required version is changed to 5.5+
5858

5959
foreach ($promisesOrValues as &$promiseOrValue) {
60-
if (! ($promiseOrValue instanceof Promise)) {
61-
continue;
60+
if ($promiseOrValue instanceof Promise) {
61+
$promiseOrValue = $promiseOrValue->adoptedPromise;
6262
}
63-
64-
$promiseOrValue = $promiseOrValue->adoptedPromise;
6563
}
6664

6765
$promise = all($promisesOrValues)->then(static function ($values) use ($promisesOrValues): array {

src/Executor/ReferenceExecutor.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,16 +1253,14 @@ protected function collectSubFields(ObjectType $returnType, ArrayObject $fieldNo
12531253
$subFieldNodes = new ArrayObject();
12541254
$visitedFragmentNames = new ArrayObject();
12551255
foreach ($fieldNodes as $fieldNode) {
1256-
if (! isset($fieldNode->selectionSet)) {
1257-
continue;
1256+
if (isset($fieldNode->selectionSet)) {
1257+
$subFieldNodes = $this->collectFields(
1258+
$returnType,
1259+
$fieldNode->selectionSet,
1260+
$subFieldNodes,
1261+
$visitedFragmentNames
1262+
);
12581263
}
1259-
1260-
$subFieldNodes = $this->collectFields(
1261-
$returnType,
1262-
$fieldNode->selectionSet,
1263-
$subFieldNodes,
1264-
$visitedFragmentNames
1265-
);
12661264
}
12671265

12681266
$returnTypeCache[$fieldNodes] = $subFieldNodes;

src/GraphQL.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,9 @@ public static function promiseToExecute(
134134
$queryComplexity->setRawVariableValues($variableValues);
135135
} else {
136136
foreach ($validationRules as $rule) {
137-
if (! ($rule instanceof QueryComplexity)) {
138-
continue;
137+
if ($rule instanceof QueryComplexity) {
138+
$rule->setRawVariableValues($variableValues);
139139
}
140-
141-
$rule->setRawVariableValues($variableValues);
142140
}
143141
}
144142

src/Server/OperationParams.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,9 @@ public static function create(array $params, bool $readonly = false): OperationP
109109
];
110110

111111
foreach ($params as &$value) {
112-
if ('' !== $value) {
113-
continue;
112+
if ('' === $value) {
113+
$value = null;
114114
}
115-
116-
$value = null;
117115
}
118116

119117
$instance->query = $params['query'];

src/Type/Definition/ResolveInfo.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,12 @@ public function getFieldSelection(int $depth = 0): array
185185
$fields = [];
186186

187187
foreach ($this->fieldNodes as $fieldNode) {
188-
if (null === $fieldNode->selectionSet) {
189-
continue;
188+
if (isset($fieldNode->selectionSet)) {
189+
$fields = array_merge_recursive(
190+
$fields,
191+
$this->foldSelectionSet($fieldNode->selectionSet, $depth)
192+
);
190193
}
191-
192-
$fields = array_merge_recursive(
193-
$fields,
194-
$this->foldSelectionSet($fieldNode->selectionSet, $depth)
195-
);
196194
}
197195

198196
return $fields;

0 commit comments

Comments
 (0)