Skip to content

Commit

Permalink
fix cs
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Mar 27, 2021
1 parent 30275cd commit 1052cef
Show file tree
Hide file tree
Showing 231 changed files with 3,838 additions and 3,141 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Expand Up @@ -605,11 +605,6 @@ parameters:
count: 1
path: tests/Executor/DirectivesTest.php

-
message: "#^Anonymous function should have native return typehint \"class@anonymous/tests/Executor/ExecutorTest\\.php\\:1329\"\\.$#"
count: 1
path: tests/Executor/ExecutorTest.php

-
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\InterfaceType given\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/Deferred.php
Expand Up @@ -11,7 +11,7 @@ class Deferred extends SyncPromise
/**
* @param callable() : mixed $executor
*/
public static function create(callable $executor) : self
public static function create(callable $executor): self
{
return new self($executor);
}
Expand Down
21 changes: 12 additions & 9 deletions src/Error/Error.php
Expand Up @@ -12,6 +12,7 @@
use JsonSerializable;
use Throwable;
use Traversable;

use function array_filter;
use function array_map;
use function array_values;
Expand Down Expand Up @@ -121,7 +122,7 @@ public function __construct(
if ($previous instanceof ClientAware) {
$this->isClientSafe = $previous->isClientSafe();
$cat = $previous->getCategory();
$this->category = $cat === '' || $cat === null ? self::CATEGORY_INTERNAL: $cat;
$this->category = $cat === '' || $cat === null ? self::CATEGORY_INTERNAL : $cat;
} elseif ($previous !== null) {
$this->isClientSafe = false;
$this->category = self::CATEGORY_INTERNAL;
Expand Down Expand Up @@ -207,7 +208,7 @@ public function getCategory()
return $this->category;
}

public function getSource() : ?Source
public function getSource(): ?Source
{
if ($this->source === null) {
if (isset($this->nodes[0]) && $this->nodes[0]->loc !== null) {
Expand All @@ -221,19 +222,19 @@ public function getSource() : ?Source
/**
* @return int[]
*/
public function getPositions() : array
public function getPositions(): array
{
if (count($this->positions) === 0 && count($this->nodes ?? []) > 0) {
$positions = array_map(
static function ($node) : ?int {
static function ($node): ?int {
return isset($node->loc) ? $node->loc->start : null;
},
$this->nodes
);

$positions = array_filter(
$positions,
static function ($p) : bool {
static function ($p): bool {
return $p !== null;
}
);
Expand All @@ -259,7 +260,7 @@ static function ($p) : bool {
*
* @api
*/
public function getLocations() : array
public function getLocations(): array
{
if (! isset($this->locations)) {
$positions = $this->getPositions();
Expand All @@ -268,15 +269,15 @@ public function getLocations() : array

if ($source !== null && count($positions) !== 0) {
$this->locations = array_map(
static function ($pos) use ($source) : SourceLocation {
static function ($pos) use ($source): SourceLocation {
return $source->getLocation($pos);
},
$positions
);
} elseif ($nodes !== null && count($nodes) !== 0) {
$locations = array_filter(
array_map(
static function ($node) : ?SourceLocation {
static function ($node): ?SourceLocation {
if (isset($node->loc->source)) {
return $node->loc->source->getLocation($node->loc->start);
}
Expand Down Expand Up @@ -341,17 +342,19 @@ public function toSerializableArray()

$locations = Utils::map(
$this->getLocations(),
static function (SourceLocation $loc) : array {
static function (SourceLocation $loc): array {
return $loc->toSerializableArray();
}
);

if (count($locations) > 0) {
$arr['locations'] = $locations;
}

if (count($this->path ?? []) > 0) {
$arr['path'] = $this->path;
}

if (count($this->extensions ?? []) > 0) {
$arr['extensions'] = $this->extensions;
}
Expand Down
30 changes: 20 additions & 10 deletions src/Error/FormattedError.php
Expand Up @@ -13,6 +13,7 @@
use GraphQL\Type\Definition\WrappingType;
use GraphQL\Utils\Utils;
use Throwable;

use function addcslashes;
use function array_filter;
use function array_intersect_key;
Expand Down Expand Up @@ -171,7 +172,7 @@ private static function lpad($len, $str)
*
* @api
*/
public static function createFromException(Throwable $exception, int $debug = DebugFlag::NONE, $internalErrorMessage = null) : array
public static function createFromException(Throwable $exception, int $debug = DebugFlag::NONE, $internalErrorMessage = null): array
{
$internalErrorMessage = $internalErrorMessage ?? self::$internalErrorMessage;

Expand All @@ -194,7 +195,7 @@ public static function createFromException(Throwable $exception, int $debug = De
if ($exception instanceof Error) {
$locations = Utils::map(
$exception->getLocations(),
static function (SourceLocation $loc) : array {
static function (SourceLocation $loc): array {
return $loc->toSerializableArray();
}
);
Expand All @@ -205,6 +206,7 @@ static function (SourceLocation $loc) : array {
if (count($exception->path ?? []) > 0) {
$formattedError['path'] = $exception->path;
}

if (count($exception->getExtensions() ?? []) > 0) {
$formattedError['extensions'] = $exception->getExtensions() + $formattedError['extensions'];
}
Expand All @@ -227,7 +229,7 @@ static function (SourceLocation $loc) : array {
*
* @throws Throwable
*/
public static function addDebugEntries(array $formattedError, Throwable $e, int $debugFlag) : array
public static function addDebugEntries(array $formattedError, Throwable $e, int $debugFlag): array
{
if ($debugFlag === DebugFlag::NONE) {
return $formattedError;
Expand Down Expand Up @@ -277,13 +279,13 @@ public static function addDebugEntries(array $formattedError, Throwable $e, int
* Prepares final error formatter taking in account $debug flags.
* If initial formatter is not set, FormattedError::createFromException is used
*/
public static function prepareFormatter(?callable $formatter, int $debug) : callable
public static function prepareFormatter(?callable $formatter, int $debug): callable
{
$formatter = $formatter ?? static function ($e) : array {
$formatter = $formatter ?? static function ($e): array {
return FormattedError::createFromException($e);
};
if ($debug !== DebugFlag::NONE) {
$formatter = static function ($e) use ($formatter, $debug) : array {
$formatter = static function ($e) use ($formatter, $debug): array {
return FormattedError::addDebugEntries($formatter($e), $e, $debug);
};
}
Expand All @@ -304,17 +306,19 @@ public static function toSafeTrace($error)
{
$trace = $error->getTrace();

if (isset($trace[0]['function']) && isset($trace[0]['class']) &&
if (
isset($trace[0]['function']) && isset($trace[0]['class']) &&
// Remove invariant entries as they don't provide much value:
($trace[0]['class'] . '::' . $trace[0]['function'] === 'GraphQL\Utils\Utils::invariant')) {
($trace[0]['class'] . '::' . $trace[0]['function'] === 'GraphQL\Utils\Utils::invariant')
) {
array_shift($trace);
} elseif (! isset($trace[0]['file'])) {
// Remove root call as it's likely error handler trace:
array_shift($trace);
}

return array_map(
static function ($err) : array {
static function ($err): array {
$safeErr = array_intersect_key($err, ['file' => true, 'line' => true]);

if (isset($err['function'])) {
Expand Down Expand Up @@ -354,21 +358,27 @@ public static function printVar($var)
if (is_object($var)) {
return 'instance of ' . get_class($var) . ($var instanceof Countable ? '(' . count($var) . ')' : '');
}

if (is_array($var)) {
return 'array(' . count($var) . ')';
}

if ($var === '') {
return '(empty string)';
}

if (is_string($var)) {
return "'" . addcslashes($var, "'") . "'";
}

if (is_bool($var)) {
return $var ? 'true' : 'false';
}

if (is_scalar($var)) {
return $var;
}

if ($var === null) {
return 'null';
}
Expand All @@ -390,7 +400,7 @@ public static function create($error, array $locations = [])

if (count($locations) > 0) {
$formatted['locations'] = array_map(
static function ($loc) : array {
static function ($loc): array {
return $loc->toArray();
},
$locations
Expand Down
2 changes: 1 addition & 1 deletion src/Error/InvariantViolation.php
Expand Up @@ -13,7 +13,7 @@
*/
class InvariantViolation extends LogicException
{
public static function shouldNotHappen() : self
public static function shouldNotHappen(): self
{
return new self('This should not have happened');
}
Expand Down
1 change: 1 addition & 0 deletions src/Error/SyntaxError.php
Expand Up @@ -5,6 +5,7 @@
namespace GraphQL\Error;

use GraphQL\Language\Source;

use function sprintf;

class SyntaxError extends Error
Expand Down
12 changes: 7 additions & 5 deletions src/Error/Warning.php
Expand Up @@ -5,8 +5,10 @@
namespace GraphQL\Error;

use GraphQL\Exception\InvalidArgument;

use function is_int;
use function trigger_error;

use const E_USER_WARNING;

/**
Expand Down Expand Up @@ -39,7 +41,7 @@ final class Warning
*
* @api
*/
public static function setWarningHandler(?callable $warningHandler = null) : void
public static function setWarningHandler(?callable $warningHandler = null): void
{
self::$warningHandler = $warningHandler;
}
Expand All @@ -56,7 +58,7 @@ public static function setWarningHandler(?callable $warningHandler = null) : voi
*
* @api
*/
public static function suppress($suppress = true) : void
public static function suppress($suppress = true): void
{
if ($suppress === true) {
self::$enableWarnings = 0;
Expand All @@ -81,7 +83,7 @@ public static function suppress($suppress = true) : void
*
* @api
*/
public static function enable($enable = true) : void
public static function enable($enable = true): void
{
if ($enable === true) {
self::$enableWarnings = self::ALL;
Expand All @@ -94,7 +96,7 @@ public static function enable($enable = true) : void
}
}

public static function warnOnce(string $errorMessage, int $warningId, ?int $messageLevel = null) : void
public static function warnOnce(string $errorMessage, int $warningId, ?int $messageLevel = null): void
{
$messageLevel = $messageLevel ?? E_USER_WARNING;

Expand All @@ -107,7 +109,7 @@ public static function warnOnce(string $errorMessage, int $warningId, ?int $mess
}
}

public static function warn(string $errorMessage, int $warningId, ?int $messageLevel = null) : void
public static function warn(string $errorMessage, int $warningId, ?int $messageLevel = null): void
{
$messageLevel = $messageLevel ?? E_USER_WARNING;

Expand Down
3 changes: 2 additions & 1 deletion src/Exception/InvalidArgument.php
Expand Up @@ -5,6 +5,7 @@
namespace GraphQL\Exception;

use InvalidArgumentException;

use function gettype;
use function sprintf;

Expand All @@ -13,7 +14,7 @@ final class InvalidArgument extends InvalidArgumentException
/**
* @param mixed $argument
*/
public static function fromExpectedTypeAndArgument(string $expectedType, $argument) : self
public static function fromExpectedTypeAndArgument(string $expectedType, $argument): self
{
return new self(sprintf('Expected type "%s", got "%s"', $expectedType, gettype($argument)));
}
Expand Down
5 changes: 3 additions & 2 deletions src/Executor/ExecutionResult.php
Expand Up @@ -8,6 +8,7 @@
use GraphQL\Error\Error;
use GraphQL\Error\FormattedError;
use JsonSerializable;

use function array_map;
use function count;

Expand Down Expand Up @@ -133,12 +134,12 @@ public function jsonSerialize()
*
* @api
*/
public function toArray(int $debug = DebugFlag::NONE) : array
public function toArray(int $debug = DebugFlag::NONE): array
{
$result = [];

if (count($this->errors ?? []) > 0) {
$errorsHandler = $this->errorsHandler ?? static function (array $errors, callable $formatter) : array {
$errorsHandler = $this->errorsHandler ?? static function (array $errors, callable $formatter): array {
return array_map($formatter, $errors);
};

Expand Down
7 changes: 4 additions & 3 deletions src/Executor/Executor.php
Expand Up @@ -12,6 +12,7 @@
use GraphQL\Language\AST\DocumentNode;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Schema;

use function is_array;
use function is_object;

Expand All @@ -29,7 +30,7 @@ class Executor
/** @var callable */
private static $implementationFactory = [ReferenceExecutor::class, 'create'];

public static function getDefaultFieldResolver() : callable
public static function getDefaultFieldResolver(): callable
{
return self::$defaultFieldResolver;
}
Expand All @@ -42,7 +43,7 @@ public static function setDefaultFieldResolver(callable $fieldResolver)
self::$defaultFieldResolver = $fieldResolver;
}

public static function getPromiseAdapter() : PromiseAdapter
public static function getPromiseAdapter(): PromiseAdapter
{
return self::$defaultPromiseAdapter ?? (self::$defaultPromiseAdapter = new SyncPromiseAdapter());
}
Expand All @@ -55,7 +56,7 @@ public static function setPromiseAdapter(?PromiseAdapter $defaultPromiseAdapter
self::$defaultPromiseAdapter = $defaultPromiseAdapter;
}

public static function getImplementationFactory() : callable
public static function getImplementationFactory(): callable
{
return self::$implementationFactory;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Executor/ExecutorImplementation.php
Expand Up @@ -11,5 +11,5 @@ interface ExecutorImplementation
/**
* Returns promise of {@link ExecutionResult}. Promise should always resolve, never reject.
*/
public function doExecute() : Promise;
public function doExecute(): Promise;
}

0 comments on commit 1052cef

Please sign in to comment.