mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-11 10:09:24 +03:00
[style changes] arrays and callback
This commit is contained in:
parent
3c98963f72
commit
80a662564e
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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, ' | ');
|
||||
}
|
||||
)
|
||||
));
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user