diff --git a/src/Error/Error.php b/src/Error/Error.php index 5976e1c..e31ccf1 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -5,7 +5,6 @@ use GraphQL\Language\Source; use GraphQL\Language\SourceLocation; use GraphQL\Utils; - /** * Class Error * A GraphQLError describes an Error found during the parse, validate, or @@ -141,8 +140,12 @@ class Error extends \Exception implements \JsonSerializable { if (null === $this->positions) { if (!empty($this->nodes)) { - $positions = array_map(function($node) { return isset($node->loc) ? $node->loc->start : null; }, $this->nodes); - $this->positions = array_filter($positions, function($p) {return $p !== null;}); + $positions = array_map(function($node) { + return isset($node->loc) ? $node->loc->start : null; + }, $this->nodes); + $this->positions = array_filter($positions, function($p) { + return $p !== null; + }); } } return $this->positions; diff --git a/src/Error/SyntaxError.php b/src/Error/SyntaxError.php index 9fc2820..36bf7db 100644 --- a/src/Error/SyntaxError.php +++ b/src/Error/SyntaxError.php @@ -4,10 +4,6 @@ namespace GraphQL\Error; use GraphQL\Language\Source; use GraphQL\Language\SourceLocation; -/** - * Class SyntaxError - * @package GraphQL\Error - */ class SyntaxError extends Error { /** @@ -33,9 +29,9 @@ class SyntaxError extends Error public static function highlightSourceAtLocation(Source $source, SourceLocation $location) { $line = $location->line; - $prevLineNum = (string)($line - 1); - $lineNum = (string)$line; - $nextLineNum = (string)($line + 1); + $prevLineNum = (string) ($line - 1); + $lineNum = (string) $line; + $nextLineNum = (string) ($line + 1); $padLen = mb_strlen($nextLineNum, 'UTF-8'); $unicodeChars = json_decode('"\u2028\u2029"'); // Quick hack to get js-compatible representation of these chars diff --git a/src/Language/Printer.php b/src/Language/Printer.php index e24f6b4..16b9bc5 100644 --- a/src/Language/Printer.php +++ b/src/Language/Printer.php @@ -42,11 +42,17 @@ class Printer { public function doPrint($ast) { - return Visitor::visit($ast, array( - 'leave' => array( - Node::NAME => function($node) {return '' . $node->value;}, - Node::VARIABLE => function($node) {return '$' . $node->name;}, - Node::DOCUMENT => function(Document $node) {return $this->join($node->definitions, "\n\n") . "\n";}, + return Visitor::visit($ast, [ + 'leave' => [ + Node::NAME => function($node) { + return '' . $node->value; + }, + Node::VARIABLE => function($node) { + return '$' . $node->name; + }, + Node::DOCUMENT => function(Document $node) { + return $this->join($node->definitions, "\n\n") . "\n"; + }, Node::OPERATION_DEFINITION => function(OperationDefinition $node) { $op = $node->operation; $name = $node->name; @@ -187,13 +193,15 @@ class Printer $this->block($def->fields) ], ' '); }, - Node::TYPE_EXTENSION_DEFINITION => function(TypeExtensionDefinition $def) {return "extend {$def->definition}";}, + Node::TYPE_EXTENSION_DEFINITION => function(TypeExtensionDefinition $def) { + return "extend {$def->definition}"; + }, Node::DIRECTIVE_DEFINITION => function(DirectiveDefinition $def) { return 'directive @' . $def->name . $this->wrap('(', $this->join($def->arguments, ', '), ')') . ' on ' . $this->join($def->locations, ' | '); } - ) - )); + ] + ]); } /** diff --git a/src/Language/Source.php b/src/Language/Source.php index 1d3d335..5083f40 100644 --- a/src/Language/Source.php +++ b/src/Language/Source.php @@ -36,7 +36,7 @@ class Source $utfChars = json_decode('"\u2028\u2029"'); $lineRegexp = '/\r\n|[\n\r'.$utfChars.']/su'; - $matches = array(); + $matches = []; preg_match_all($lineRegexp, mb_substr($this->body, 0, $position, 'UTF-8'), $matches, PREG_OFFSET_CAPTURE); foreach ($matches[0] as $index => $match) { diff --git a/src/Language/Visitor.php b/src/Language/Visitor.php index 4cf650f..1b0e714 100644 --- a/src/Language/Visitor.php +++ b/src/Language/Visitor.php @@ -38,7 +38,7 @@ class Visitor return $r; } - public static $visitorKeys = array( + public static $visitorKeys = [ Node::NAME => [], Node::DOCUMENT => ['definitions'], Node::OPERATION_DEFINITION => ['name', 'variableDefinitions', 'directives', 'selectionSet'], @@ -77,7 +77,7 @@ class Visitor Node::INPUT_OBJECT_TYPE_DEFINITION => [ 'name', 'directives', 'fields' ], Node::TYPE_EXTENSION_DEFINITION => [ 'definition' ], Node::DIRECTIVE_DEFINITION => [ 'name', 'arguments', 'locations' ] - ); + ]; /** * visit() will walk through an AST using a depth first traversal, calling @@ -279,16 +279,16 @@ class Visitor } if (!$isLeaving) { - $stack = array( + $stack = [ 'inArray' => $inArray, 'index' => $index, 'keys' => $keys, 'edits' => $edits, 'prev' => $stack - ); + ]; $inArray = is_array($node); - $keys = ($inArray ? $node : $visitorKeys[$node->kind]) ?: array(); + $keys = ($inArray ? $node : $visitorKeys[$node->kind]) ?: []; $index = -1; $edits = []; if ($parent) { diff --git a/src/Utils.php b/src/Utils.php index 24912d1..17f32f0 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -11,10 +11,12 @@ class Utils { /** * @param object $obj - * @param array $vars + * @param array $vars + * @param array $requiredKeys + * * @return array */ - public static function assign($obj, array $vars, array $requiredKeys = array()) + public static function assign($obj, array $vars, array $requiredKeys = []) { foreach ($requiredKeys as $key) { if (!isset($key, $vars)) {