diff --git a/UPGRADE.md b/UPGRADE.md index 0a7e12639..325b34a30 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -21,7 +21,7 @@ $e = new Error( 'msg', null, null, - null, + [], null, null, ['foo' => 'bar'] diff --git a/src/Error/Error.php b/src/Error/Error.php index 35bedb6da..ecf383ebf 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -66,7 +66,7 @@ class Error extends Exception implements JsonSerializable, ClientAware */ private $source; - /** @var int[]|null */ + /** @var int[] */ private $positions; /** @var bool */ @@ -81,7 +81,7 @@ class Error extends Exception implements JsonSerializable, ClientAware /** * @param string $message * @param Node|Node[]|Traversable|null $nodes - * @param mixed[]|null $positions + * @param mixed[] $positions * @param mixed[]|null $path * @param Throwable $previous * @param mixed[] $extensions @@ -90,7 +90,7 @@ public function __construct( $message, $nodes = null, ?Source $source = null, - $positions = null, + array $positions = [], $path = null, $previous = null, array $extensions = [] @@ -100,7 +100,7 @@ public function __construct( // Compute list of blame nodes. if ($nodes instanceof Traversable) { $nodes = iterator_to_array($nodes); - } elseif ($nodes && ! is_array($nodes)) { + } elseif ($nodes !== null && ! is_array($nodes)) { $nodes = [$nodes]; } @@ -109,7 +109,7 @@ public function __construct( $this->positions = $positions; $this->path = $path; $this->extensions = count($extensions) > 0 ? $extensions : ( - $previous && $previous instanceof self + $previous instanceof self ? $previous->extensions : [] ); @@ -118,7 +118,7 @@ public function __construct( $this->isClientSafe = $previous->isClientSafe(); $cat = $previous->getCategory(); $this->category = $cat === '' || $cat === null ? self::CATEGORY_INTERNAL: $cat; - } elseif ($previous) { + } elseif ($previous !== null) { $this->isClientSafe = false; $this->category = self::CATEGORY_INTERNAL; } else { @@ -141,7 +141,7 @@ public function __construct( public static function createLocatedError($error, $nodes = null, $path = null) { if ($error instanceof self) { - if ($error->path && $error->nodes) { + if ($error->path !== null && $error->nodes !== null && count($error->nodes) !== 0) { return $error; } @@ -149,8 +149,10 @@ public static function createLocatedError($error, $nodes = null, $path = null) $path = $path ?? $error->path; } - $source = $positions = $originalError = null; - $extensions = []; + $source = null; + $originalError = null; + $positions = []; + $extensions = []; if ($error instanceof self) { $message = $error->getMessage(); @@ -218,9 +220,9 @@ public function getSource() /** * @return int[] */ - public function getPositions() + public function getPositions() : array { - if ($this->positions === null && ! empty($this->nodes)) { + if (count($this->positions) === 0 && ! empty($this->nodes)) { $positions = array_map( static function ($node) : ?int { return isset($node->loc) ? $node->loc->start : null; @@ -263,14 +265,14 @@ public function getLocations() $source = $this->getSource(); $nodes = $this->nodes; - if ($positions && $source) { + if ($source !== null && count($positions) !== 0) { $this->locations = array_map( static function ($pos) use ($source) : SourceLocation { return $source->getLocation($pos); }, $positions ); - } elseif ($nodes) { + } elseif ($nodes !== null && count($nodes) !== 0) { $locations = array_filter( array_map( static function ($node) : ?SourceLocation { diff --git a/src/Utils/ASTDefinitionBuilder.php b/src/Utils/ASTDefinitionBuilder.php index 05a3b5ad5..226c6332b 100644 --- a/src/Utils/ASTDefinitionBuilder.php +++ b/src/Utils/ASTDefinitionBuilder.php @@ -215,7 +215,7 @@ private function internalBuildType($typeName, $typeNode = null) sprintf('when building %s type: %s', $typeName, $e->getMessage()), null, null, - null, + [], null, $e ); diff --git a/src/Utils/Value.php b/src/Utils/Value.php index 2920883a6..e1e42e98e 100644 --- a/src/Utils/Value.php +++ b/src/Utils/Value.php @@ -249,7 +249,7 @@ private static function coercionError( ($subMessage ? '; ' . $subMessage : '.'), $blameNode, null, - null, + [], null, $originalError ); diff --git a/tests/Error/ErrorTest.php b/tests/Error/ErrorTest.php index 4614177d5..9486ce90b 100644 --- a/tests/Error/ErrorTest.php +++ b/tests/Error/ErrorTest.php @@ -20,7 +20,7 @@ class ErrorTest extends TestCase public function testUsesTheStackOfAnOriginalError() : void { $prev = new Exception('Original'); - $err = new Error('msg', null, null, null, null, $prev); + $err = new Error('msg', null, null, [], null, $prev); self::assertSame($err->getPrevious(), $prev); } @@ -134,7 +134,7 @@ public function testSerializesToIncludePath() : void 'msg', null, null, - null, + [], ['path', 3, 'to', 'field'] ); @@ -151,7 +151,7 @@ public function testDefaultErrorFormatterIncludesExtensionFields() : void 'msg', null, null, - null, + [], null, null, ['foo' => 'bar'] diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index 33ae342b7..7ad87a607 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -461,7 +461,7 @@ public function testNullsOutErrorSubtrees() : void 'Error getting asyncReturnErrorWithExtensions', null, null, - null, + [], null, null, ['foo' => 'bar']