Skip to content

Commit

Permalink
Merge ee02e66 into 762a149
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Mar 27, 2021
2 parents 762a149 + ee02e66 commit 2ecf33f
Show file tree
Hide file tree
Showing 233 changed files with 3,867 additions and 3,224 deletions.
7 changes: 3 additions & 4 deletions composer.json
Expand Up @@ -9,13 +9,13 @@
"API"
],
"require": {
"php": "^7.3||^8.0",
"php": "^7.3 || ^8.0",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"amphp/amp": "^2.3",
"doctrine/coding-standard": "^6.0",
"doctrine/coding-standard": "^8.2",
"nyholm/psr7": "^1.2",
"phpbench/phpbench": "^0.16.10",
"phpstan/extension-installer": "^1.0",
Expand All @@ -25,8 +25,7 @@
"phpunit/phpunit": "^7.2|^8.5",
"psr/http-message": "^1.0",
"react/promise": "2.*",
"simpod/php-coveralls-mirror": "^3.0",
"squizlabs/php_codesniffer": "3.5.4"
"simpod/php-coveralls-mirror": "^3.0"
},
"config": {
"preferred-install": "dist",
Expand Down
105 changes: 26 additions & 79 deletions phpcs.xml.dist
Expand Up @@ -13,90 +13,37 @@
<file>tests</file>

<rule ref="Doctrine">
<!-- Disable PHP7+ features that might cause BC breaks for now -->
<exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility.MissingConstantVisibility" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" />
<!-- Enable when Slevomat starts supporting variadics, see https://github.com/slevomat/coding-standard/issues/251 -->
<exclude name="SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse" />
</rule>
<!-- Remove when PHP 7.4 is minimum version requirement -->
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator.RequiredNullCoalesceEqualOperator" />

<!--@api annotation is required for now -->
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<properties>
<property
name="usefulAnnotations"
type="array"
value="
@after,
@afterClass,
@AfterMethods,
@api,
@Attribute,
@Attributes,
@before,
@beforeClass,
@BeforeMethods,
@covers,
@coversDefaultClass,
@coversNothing,
@dataProvider,
@depends,
@deprecated,
@doesNotPerformAssertions,
@Enum,
@expectedDeprecation,
@expectedException,
@expectedExceptionCode,
@expectedExceptionMessage,
@expectedExceptionMessageRegExp,
@group,
@Groups,
@IgnoreAnnotation,
@internal,
@Iterations,
@link,
@ODM\,
@ORM\,
@requires,
@Required,
@Revs,
@runInSeparateProcess,
@runTestsInSeparateProcesses,
@see,
@Target,
@test,
@throws,
@uses
"
/>
</properties>
<!-- To fix -->
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility.MissingConstantVisibility" />
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion" />
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
<exclude name="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps" />
<exclude name="Squiz.NamingConventions.ValidVariableName.NotCamelCaps" />
</rule>

<!-- Forbid useless annotations -->
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<properties>
<property
name="forbiddenAnnotations"
type="array"
value="
@author,
@category,
@copyright,
@created,
@license,
@package,
@since,
@subpackage,
@version
"
/>
</properties>
</rule>

<!-- IDEs sort by PSR12, Slevomat coding standard uses old sorting for BC -->
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
<property name="psr12Compatible" type="bool" value="true" />
<property name="forbiddenAnnotations" type="array">
<element value="@author"/>
<element value="@category"/>
<element value="@copyright"/>
<element value="@created"/>
<element value="@license"/>
<element value="@package"/>
<element value="@since"/>
<element value="@subpackage"/>
<element value="@version"/>
</property>
</properties>
</rule>
</ruleset>
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

0 comments on commit 2ecf33f

Please sign in to comment.