Skip to content

Commit a2cf951

Browse files
authored
Merge pull request overblog#371 from mcg-web/native_function_invocation
Native function invocation
2 parents 4e4aec3 + 6ef0a59 commit a2cf951

File tree

121 files changed

+505
-503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+505
-503
lines changed

.php_cs.dist

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ return PhpCsFixer\Config::create()
1616
'phpdoc_no_alias_tag' => ['type' => 'var'],
1717
'no_mixed_echo_print' => ['use' => 'echo'],
1818
'binary_operator_spaces' => ['align_double_arrow' => false, 'align_equals' => false],
19+
'general_phpdoc_annotation_remove' => ['author', 'category', 'copyright', 'created', 'license', 'package', 'since', 'subpackage', 'version'],
20+
'native_function_invocation' => true,
1921
]
2022
)
2123
->setFinder($finder)

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@
7070
"scripts": {
7171
"test": "bin/phpunit --color=always -v --debug",
7272
"static-analysis": [
73-
"@composer req --ansi --dev phpstan/phpstan-shim",
74-
"bin/phpstan.phar analyse --ansi -l 1 -c phpstan.neon src",
75-
"@composer rem --ansi --dev phpstan/phpstan-shim"
73+
"@composer req --ansi --dev 'phpstan/phpstan:^0.10.3'",
74+
"phpstan analyse --ansi -l 1 -c phpstan.neon src",
75+
"@composer rem --ansi --dev phpstan/phpstan"
7676
],
7777
"bench": [
7878
"test -f phpbench.phar || wget https://phpbench.github.io/phpbench/phpbench.phar https://phpbench.github.io/phpbench/phpbench.phar.pubkey",
@@ -81,11 +81,11 @@
8181
"install-cs": "test -f php-cs-fixer.phar || wget https://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer.phar",
8282
"fix-cs": [
8383
"@install-cs",
84-
"@php php-cs-fixer.phar fix --diff -v --ansi"
84+
"@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi"
8585
],
8686
"check-cs": [
8787
"@install-cs",
88-
"@php php-cs-fixer.phar fix --dry-run --diff -v --ansi"
88+
"@php php-cs-fixer.phar fix --dry-run --diff -v --allow-risky=yes --ansi"
8989
],
9090
"code-quality": [
9191
"rm composer.lock",

src/Command/DebugCommand.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ protected function configure()
5151
'category',
5252
null,
5353
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
54-
sprintf('filter by a category (%s).', implode(', ', self::$categories))
54+
\sprintf('filter by a category (%s).', \implode(', ', self::$categories))
5555
)
5656
->setDescription('Display current GraphQL services (types, resolvers and mutations)');
5757
}
5858

5959
protected function execute(InputInterface $input, OutputInterface $output)
6060
{
6161
$categoriesOption = $input->getOption('category');
62-
$categoriesOption = is_array($categoriesOption) ? $categoriesOption : [$categoriesOption];
63-
$notAllowed = array_diff($categoriesOption, self::$categories);
62+
$categoriesOption = \is_array($categoriesOption) ? $categoriesOption : [$categoriesOption];
63+
$notAllowed = \array_diff($categoriesOption, self::$categories);
6464
if (!empty($notAllowed)) {
65-
throw new \InvalidArgumentException(sprintf('Invalid category (%s)', implode(',', $notAllowed)));
65+
throw new \InvalidArgumentException(\sprintf('Invalid category (%s)', \implode(',', $notAllowed)));
6666
}
6767

6868
$categories = empty($categoriesOption) ? self::$categories : $categoriesOption;
@@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7171
$tableHeaders = ['solution id', 'aliases'];
7272

7373
foreach ($categories as $category) {
74-
$io->title(sprintf('GraphQL %ss Services', ucfirst($category)));
74+
$io->title(\sprintf('GraphQL %ss Services', \ucfirst($category)));
7575

7676
/** @var FluentResolverInterface $resolver */
7777
$resolver = $this->{$category.'Resolver'};
@@ -87,22 +87,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787
private function renderTable(FluentResolverInterface $resolver, array $tableHeaders, SymfonyStyle $io)
8888
{
8989
$tableRows = [];
90-
$solutionIDs = array_keys($resolver->getSolutions());
91-
sort($solutionIDs);
90+
$solutionIDs = \array_keys($resolver->getSolutions());
91+
\sort($solutionIDs);
9292
foreach ($solutionIDs as $solutionID) {
9393
$aliases = $resolver->getSolutionAliases($solutionID);
9494
$tableRows[$solutionID] = [$solutionID, self::serializeAliases($aliases)];
9595
}
96-
ksort($tableRows);
96+
\ksort($tableRows);
9797
$io->table($tableHeaders, $tableRows);
9898
$io->write("\n\n");
9999
}
100100

101101
private static function serializeAliases(array $aliases)
102102
{
103-
ksort($aliases);
103+
\ksort($aliases);
104104

105-
return implode("\n", $aliases);
105+
return \implode("\n", $aliases);
106106
}
107107

108108
public static function getCategories()

src/Command/GraphQLDumpSchemaCommand.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
{
6868
$io = new SymfonyStyle($input, $output);
6969
$file = $this->createFile($input);
70-
$io->success(sprintf('GraphQL schema "%s" was successfully dumped.', realpath($file)));
70+
$io->success(\sprintf('GraphQL schema "%s" was successfully dumped.', \realpath($file)));
7171
}
7272

7373
private function createFile(InputInterface $input)
7474
{
75-
$format = strtolower($input->getOption('format'));
75+
$format = \strtolower($input->getOption('format'));
7676
$schemaName = $input->getOption('schema');
7777

78-
$file = $input->getOption('file') ?: $this->baseExportPath.sprintf('/../var/schema%s.%s', $schemaName ? '.'.$schemaName : '', $format);
78+
$file = $input->getOption('file') ?: $this->baseExportPath.\sprintf('/../var/schema%s.%s', $schemaName ? '.'.$schemaName : '', $format);
7979

8080
switch ($format) {
8181
case 'json':
@@ -92,18 +92,18 @@ private function createFile(InputInterface $input)
9292
->execute($schemaName, $request)
9393
->toArray();
9494

95-
$content = json_encode($modern ? $result : $result['data'], \JSON_PRETTY_PRINT);
95+
$content = \json_encode($modern ? $result : $result['data'], \JSON_PRETTY_PRINT);
9696
break;
9797

9898
case 'graphql':
9999
$content = SchemaPrinter::doPrint($this->getRequestExecutor()->getSchema($schemaName));
100100
break;
101101

102102
default:
103-
throw new \InvalidArgumentException(sprintf('Unknown format %s.', json_encode($format)));
103+
throw new \InvalidArgumentException(\sprintf('Unknown format %s.', \json_encode($format)));
104104
}
105105

106-
file_put_contents($file, $content);
106+
\file_put_contents($file, $content);
107107

108108
return $file;
109109
}

src/Command/RequestExecutorLazyLoaderTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function setRequestExecutorFactory(array $requestExecutorFactory)
2323
protected function getRequestExecutor()
2424
{
2525
if (null === $this->requestExecutor && null !== $this->requestExecutorFactory) {
26-
$this->requestExecutor = call_user_func_array(...$this->requestExecutorFactory);
26+
$this->requestExecutor = \call_user_func_array(...$this->requestExecutorFactory);
2727
}
2828

2929
return $this->requestExecutor;

src/Config/EnumTypeDefinition.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ public function getDefinition()
1818
->useAttributeAsKey('name')
1919
->beforeNormalization()
2020
->ifTrue(function ($v) {
21-
return is_array($v);
21+
return \is_array($v);
2222
})
2323
->then(function ($v) {
2424
foreach ($v as $name => &$options) {
2525
// short syntax NAME: VALUE
26-
if (!is_null($options) && !is_array($options)) {
26+
if (!\is_null($options) && !\is_array($options)) {
2727
$options = ['value' => $options];
2828
}
2929

3030
// use name as value if no value given
31-
if (!array_key_exists('value', $options)) {
31+
if (!\array_key_exists('value', $options)) {
3232
$options['value'] = $name;
3333
}
3434
}

src/Config/ObjectTypeDefinition.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ private function treatFieldsDefaultAccess(ArrayNodeDefinition $node)
4545
{
4646
$node->validate()
4747
->ifTrue(function ($v) {
48-
return array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess'];
48+
return \array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess'];
4949
})
5050
->then(function ($v) {
5151
foreach ($v['fields'] as &$field) {
52-
if (array_key_exists('access', $field) && null !== $field['access']) {
52+
if (\array_key_exists('access', $field) && null !== $field['access']) {
5353
continue;
5454
}
5555

@@ -70,11 +70,11 @@ private function treatFieldsDefaultPublic(ArrayNodeDefinition $node)
7070
{
7171
$node->validate()
7272
->ifTrue(function ($v) {
73-
return array_key_exists('fieldsDefaultPublic', $v) && null !== $v['fieldsDefaultPublic'];
73+
return \array_key_exists('fieldsDefaultPublic', $v) && null !== $v['fieldsDefaultPublic'];
7474
})
7575
->then(function ($v) {
7676
foreach ($v['fields'] as &$field) {
77-
if (array_key_exists('public', $field) && null !== $field['public']) {
77+
if (\array_key_exists('public', $field) && null !== $field['public']) {
7878
continue;
7979
}
8080

src/Config/Parser/GraphQLParser.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class GraphQLParser implements ParserInterface
3535
public static function parse(\SplFileInfo $file, ContainerBuilder $container)
3636
{
3737
$container->addResource(new FileResource($file->getRealPath()));
38-
$content = trim(file_get_contents($file->getPathname()));
38+
$content = \trim(\file_get_contents($file->getPathname()));
3939
$typesConfig = [];
4040

4141
// allow empty files
@@ -48,7 +48,7 @@ public static function parse(\SplFileInfo $file, ContainerBuilder $container)
4848
try {
4949
$ast = Parser::parse($content);
5050
} catch (\Exception $e) {
51-
throw new InvalidArgumentException(sprintf('An error occurred while parsing the file "%s".', $file), $e->getCode(), $e);
51+
throw new InvalidArgumentException(\sprintf('An error occurred while parsing the file "%s".', $file), $e->getCode(), $e);
5252
}
5353

5454
foreach ($ast->definitions as $typeDef) {
@@ -114,11 +114,11 @@ protected function typeDefinitionToConfig(DefinitionNode $typeDef)
114114

115115
private static function throwUnsupportedDefinitionNode(DefinitionNode $typeDef)
116116
{
117-
$path = explode('\\', get_class($typeDef));
117+
$path = \explode('\\', \get_class($typeDef));
118118
throw new InvalidArgumentException(
119-
sprintf(
119+
\sprintf(
120120
'%s definition is not supported right now.',
121-
preg_replace('@DefinitionNode$@', '', array_pop($path))
121+
\preg_replace('@DefinitionNode$@', '', \array_pop($path))
122122
)
123123
);
124124
}
@@ -294,10 +294,10 @@ private function astValueNodeToConfig(ValueNode $valueNode)
294294

295295
private function cleanAstDescription($description)
296296
{
297-
if (property_exists($description, 'value')) {
297+
if (\property_exists($description, 'value')) {
298298
$description = $description->value;
299299
}
300-
$description = trim($description);
300+
$description = \trim($description);
301301

302302
return empty($description) ? null : $description;
303303
}

src/Config/Parser/XmlParser.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public static function parse(\SplFileInfo $file, ContainerBuilder $container)
2323
continue;
2424
}
2525
$values = XmlUtils::convertDomElementToArray($node);
26-
if (is_array($values)) {
27-
$typesConfig = array_merge($typesConfig, $values);
26+
if (\is_array($values)) {
27+
$typesConfig = \array_merge($typesConfig, $values);
2828
}
2929
}
3030
} catch (\InvalidArgumentException $e) {
31-
throw new InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
31+
throw new InvalidArgumentException(\sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
3232
}
3333

3434
return $typesConfig;

src/Config/Parser/YamlParser.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public static function parse(\SplFileInfo $file, ContainerBuilder $container)
2424
$container->addResource(new FileResource($file->getRealPath()));
2525

2626
try {
27-
$typesConfig = self::$yamlParser->parse(file_get_contents($file->getPathname()));
27+
$typesConfig = self::$yamlParser->parse(\file_get_contents($file->getPathname()));
2828
} catch (ParseException $e) {
29-
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
29+
throw new InvalidArgumentException(\sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
3030
}
3131

32-
return is_array($typesConfig) ? $typesConfig : [];
32+
return \is_array($typesConfig) ? $typesConfig : [];
3333
}
3434
}

src/Config/Processor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function process(array $configs, $type = self::NORMALIZATION)
2828
{
2929
/** @var ProcessorInterface $processor */
3030
foreach (static::PROCESSORS[$type] as $processor) {
31-
$configs = call_user_func([$processor, 'process'], $configs);
31+
$configs = \call_user_func([$processor, 'process'], $configs);
3232
}
3333

3434
return $configs;

src/Config/Processor/BuilderProcessor.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class BuilderProcessor implements ProcessorInterface
4343
public static function process(array $configs)
4444
{
4545
foreach ($configs as &$config) {
46-
if (isset($config['config']['fields']) && is_array($config['config']['fields'])) {
46+
if (isset($config['config']['fields']) && \is_array($config['config']['fields'])) {
4747
$config['config']['fields'] = self::processFieldBuilders($config['config']['fields']);
4848
}
4949
}
@@ -65,23 +65,23 @@ private static function checkBuilderClass($builderClass, $type)
6565
{
6666
$interface = MappingInterface::class;
6767

68-
if (!is_string($builderClass)) {
68+
if (!\is_string($builderClass)) {
6969
throw new \InvalidArgumentException(
70-
sprintf('%s builder class should be string, but %s given.', ucfirst($type), gettype($builderClass))
70+
\sprintf('%s builder class should be string, but %s given.', \ucfirst($type), \gettype($builderClass))
7171
);
7272
}
7373

74-
if (!class_exists($builderClass)) {
74+
if (!\class_exists($builderClass)) {
7575
throw new \InvalidArgumentException(
76-
sprintf('%s builder class "%s" not found.', ucfirst($type), $builderClass)
76+
\sprintf('%s builder class "%s" not found.', \ucfirst($type), $builderClass)
7777
);
7878
}
7979

80-
if (!is_subclass_of($builderClass, $interface)) {
80+
if (!\is_subclass_of($builderClass, $interface)) {
8181
throw new \InvalidArgumentException(
82-
sprintf(
82+
\sprintf(
8383
'%s builder class should implement "%s", but "%s" given.',
84-
ucfirst($type),
84+
\ucfirst($type),
8585
$interface,
8686
$builderClass
8787
)
@@ -94,11 +94,11 @@ private static function processFieldBuilders(array $fields)
9494
foreach ($fields as &$field) {
9595
$fieldBuilderName = null;
9696

97-
if (isset($field['builder']) && is_string($field['builder'])) {
97+
if (isset($field['builder']) && \is_string($field['builder'])) {
9898
$fieldBuilderName = $field['builder'];
9999
unset($field['builder']);
100-
} elseif (is_string($field)) {
101-
@trigger_error(
100+
} elseif (\is_string($field)) {
101+
@\trigger_error(
102102
'The builder short syntax (Field: Builder => Field: {builder: Builder}) is deprecated as of 0.7 and will be removed in 0.12. '.
103103
'It will be replaced by the field type short syntax (Field: Type => Field: {type: Type})',
104104
E_USER_DEPRECATED
@@ -108,15 +108,15 @@ private static function processFieldBuilders(array $fields)
108108

109109
$builderConfig = [];
110110
if (isset($field['builderConfig'])) {
111-
if (is_array($field['builderConfig'])) {
111+
if (\is_array($field['builderConfig'])) {
112112
$builderConfig = $field['builderConfig'];
113113
}
114114
unset($field['builderConfig']);
115115
}
116116

117117
if ($fieldBuilderName) {
118118
$buildField = self::getBuilder($fieldBuilderName, self::BUILDER_FIELD_TYPE)->toMappingDefinition($builderConfig);
119-
$field = is_array($field) ? array_merge($buildField, $field) : $buildField;
119+
$field = \is_array($field) ? \array_merge($buildField, $field) : $buildField;
120120
}
121121
if (isset($field['argsBuilder'])) {
122122
$field = self::processFieldArgumentsBuilders($field);
@@ -147,37 +147,37 @@ private static function getBuilder($name, $type)
147147
return $builders[$type][$name] = new $builderClassMap[$name]();
148148
}
149149
// deprecated relay builder name ?
150-
$newName = 'Relay::'.rtrim($name, 'Args');
150+
$newName = 'Relay::'.\rtrim($name, 'Args');
151151
if (isset($builderClassMap[$newName])) {
152-
@trigger_error(
153-
sprintf('The "%s" %s builder is deprecated as of 0.7 and will be removed in 0.12. Use "%s" instead.', $name, $type, $newName),
152+
@\trigger_error(
153+
\sprintf('The "%s" %s builder is deprecated as of 0.7 and will be removed in 0.12. Use "%s" instead.', $name, $type, $newName),
154154
E_USER_DEPRECATED
155155
);
156156

157157
return $builders[$type][$newName] = new $builderClassMap[$newName]();
158158
}
159159

160-
throw new InvalidConfigurationException(sprintf('%s builder "%s" not found.', ucfirst($type), $name));
160+
throw new InvalidConfigurationException(\sprintf('%s builder "%s" not found.', \ucfirst($type), $name));
161161
}
162162

163163
private static function processFieldArgumentsBuilders(array $field)
164164
{
165165
$argsBuilderName = null;
166166

167-
if (is_string($field['argsBuilder'])) {
167+
if (\is_string($field['argsBuilder'])) {
168168
$argsBuilderName = $field['argsBuilder'];
169-
} elseif (isset($field['argsBuilder']['builder']) && is_string($field['argsBuilder']['builder'])) {
169+
} elseif (isset($field['argsBuilder']['builder']) && \is_string($field['argsBuilder']['builder'])) {
170170
$argsBuilderName = $field['argsBuilder']['builder'];
171171
}
172172

173173
$builderConfig = [];
174-
if (isset($field['argsBuilder']['config']) && is_array($field['argsBuilder']['config'])) {
174+
if (isset($field['argsBuilder']['config']) && \is_array($field['argsBuilder']['config'])) {
175175
$builderConfig = $field['argsBuilder']['config'];
176176
}
177177

178178
if ($argsBuilderName) {
179179
$args = self::getBuilder($argsBuilderName, self::BUILDER_ARGS_TYPE)->toMappingDefinition($builderConfig);
180-
$field['args'] = isset($field['args']) && is_array($field['args']) ? array_merge($args, $field['args']) : $args;
180+
$field['args'] = isset($field['args']) && \is_array($field['args']) ? \array_merge($args, $field['args']) : $args;
181181
}
182182

183183
unset($field['argsBuilder']);

0 commit comments

Comments
 (0)