Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify unnecessary continue constructs #1054

Merged
merged 5 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
- Remove deprecated public property access to `FieldDefinition::$type`
- Remove alias `GraphQL\Validator\Rules\AbstractQuerySecurity`, use `GraphQL\Validator\Rules\QuerySecurityRule`
- Remove alias `GraphQL\Validator\Rules\AbstractValidationRule`, use `GraphQL\Validator\Rules\ValidationRule`
- Remove alias `GraphQL\Utils\FindBreakingChanges`, use `GraphQL\Utils\BreakingChangesFinder`
- Remove `OperationParams` method `getOriginalInput()` in favor of public property `$originalInput`
- Remove `OperationParams` method `isReadOnly()` in favor of public property `$readOnly`
- Remove `Utils::withErrorHandling()`
Expand Down
6 changes: 2 additions & 4 deletions benchmarks/Utils/QueryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ public function __construct(Schema $schema, float $percentOfLeafFields)

$totalFields = 0;
foreach ($schema->getTypeMap() as $type) {
if (! ($type instanceof ObjectType)) {
continue;
if ($type instanceof ObjectType) {
$totalFields += count($type->getFieldNames());
}

$totalFields += count($type->getFieldNames());
}

$this->maxLeafFields = max(1, (int) round($totalFields * $percentOfLeafFields));
Expand Down
12 changes: 4 additions & 8 deletions generate-class-reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ function renderClass(ReflectionClass $class, array $options): string
if ($options['props'] ?? true) {
$props = [];
foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
if (! isApi($property)) {
continue;
if (isApi($property)) {
$props[] = renderProp($property);
}

$props[] = renderProp($property);
}

if (count($props) > 0) {
Expand All @@ -102,11 +100,9 @@ function renderClass(ReflectionClass $class, array $options): string
if ($options['methods'] ?? true) {
$methods = [];
foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if (! isApi($method)) {
continue;
if (isApi($method)) {
$methods[] = renderMethod($method);
}

$methods[] = renderMethod($method);
}

if (count($methods) > 0) {
Expand Down
13 changes: 4 additions & 9 deletions src/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,9 @@ public function getPositions(): array

if (isset($this->nodes)) {
foreach ($this->nodes as $node) {
$start = $node->loc->start ?? null;
if (null === $start) {
continue;
if (isset($node->loc->start)) {
$this->positions[] = $node->loc->start;
}

$this->positions[] = $start;
}
}
}
Expand Down Expand Up @@ -248,11 +245,9 @@ public function getLocations(): array
}
} elseif (null !== $nodes && 0 !== count($nodes)) {
foreach ($nodes as $node) {
if (! isset($node->loc->source)) {
continue;
if (isset($node->loc->source)) {
$this->locations[] = $node->loc->source->getLocation($node->loc->start);
}

$this->locations[] = $node->loc->source->getLocation($node->loc->start);
}
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/Error/FormattedError.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ public static function printError(Error $error): string
$nodes = $error->nodes;
if (isset($nodes) && count($nodes) > 0) {
foreach ($nodes as $node) {
if (! isset($node->loc->source)) {
continue;
if (isset($node->loc->source)) {
$location = $node->loc;
$source = $location->source;
$printedLocations[] = self::highlightSourceAtLocation(
$source,
$source->getLocation($location->start)
);
}

$location = $node->loc;
$source = $location->source;
$printedLocations[] = self::highlightSourceAtLocation(
$source,
$source->getLocation($location->start)
);
}
} elseif (null !== $error->getSource() && 0 !== count($error->getLocations())) {
$source = $error->getSource();
Expand Down
6 changes: 2 additions & 4 deletions src/Executor/Promise/Adapter/ReactPromiseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ public function all(array $promisesOrValues): Promise
// TODO: rework with generators when PHP minimum required version is changed to 5.5+

foreach ($promisesOrValues as &$promiseOrValue) {
if (! ($promiseOrValue instanceof Promise)) {
continue;
if ($promiseOrValue instanceof Promise) {
$promiseOrValue = $promiseOrValue->adoptedPromise;
}

$promiseOrValue = $promiseOrValue->adoptedPromise;
}

$promise = all($promisesOrValues)->then(static function ($values) use ($promisesOrValues): array {
Expand Down
16 changes: 7 additions & 9 deletions src/Executor/ReferenceExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1253,16 +1253,14 @@ protected function collectSubFields(ObjectType $returnType, ArrayObject $fieldNo
$subFieldNodes = new ArrayObject();
$visitedFragmentNames = new ArrayObject();
foreach ($fieldNodes as $fieldNode) {
if (! isset($fieldNode->selectionSet)) {
continue;
if (isset($fieldNode->selectionSet)) {
$subFieldNodes = $this->collectFields(
$returnType,
$fieldNode->selectionSet,
$subFieldNodes,
$visitedFragmentNames
);
}

$subFieldNodes = $this->collectFields(
$returnType,
$fieldNode->selectionSet,
$subFieldNodes,
$visitedFragmentNames
);
}

$returnTypeCache[$fieldNodes] = $subFieldNodes;
Expand Down
6 changes: 2 additions & 4 deletions src/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ public static function promiseToExecute(
$queryComplexity->setRawVariableValues($variableValues);
} else {
foreach ($validationRules as $rule) {
if (! ($rule instanceof QueryComplexity)) {
continue;
if ($rule instanceof QueryComplexity) {
$rule->setRawVariableValues($variableValues);
}

$rule->setRawVariableValues($variableValues);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/Server/OperationParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ public static function create(array $params, bool $readonly = false): OperationP
];

foreach ($params as &$value) {
if ('' !== $value) {
continue;
if ('' === $value) {
$value = null;
}

$value = null;
}

$instance->query = $params['query'];
Expand Down
12 changes: 5 additions & 7 deletions src/Type/Definition/ResolveInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,12 @@ public function getFieldSelection(int $depth = 0): array
$fields = [];

foreach ($this->fieldNodes as $fieldNode) {
if (null === $fieldNode->selectionSet) {
continue;
if (isset($fieldNode->selectionSet)) {
$fields = array_merge_recursive(
$fields,
$this->foldSelectionSet($fieldNode->selectionSet, $depth)
);
}

$fields = array_merge_recursive(
$fields,
$this->foldSelectionSet($fieldNode->selectionSet, $depth)
);
}

return $fields;
Expand Down
22 changes: 7 additions & 15 deletions src/Type/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use function is_array;
use function is_callable;
use function is_iterable;
use function sprintf;

/**
* Schema Definition (see [schema definition docs](schema-definition.md)).
Expand Down Expand Up @@ -197,11 +196,9 @@ private function collectAllTypes(): array

foreach ($this->getDirectives() as $directive) {
// @phpstan-ignore-next-line generics are not strictly enforceable, error will be caught during schema validation
if (! $directive instanceof Directive) {
continue;
if ($directive instanceof Directive) {
TypeInfo::extractTypesFromDirectives($directive, $typeMap);
}

TypeInfo::extractTypesFromDirectives($directive, $typeMap);
}

// When types are set as array they are resolved in constructor
Expand Down Expand Up @@ -531,17 +528,12 @@ public function assertValid(): void
$type->assertValid();

// Make sure type loader returns the same instance as registered in other places of schema
if (null === $this->config->typeLoader) {
continue;
if (isset($this->config->typeLoader)) {
Utils::invariant(
$this->loadType($name) === $type,
"Type loader returns different instance for {$name} than field/argument definitions. Make sure you always return the same instance for the same type name."
);
}

Utils::invariant(
$this->loadType($name) === $type,
sprintf(
'Type loader returns different instance for %s than field/argument definitions. Make sure you always return the same instance for the same type name.',
$name
)
);
}
}

Expand Down