Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#360)
by Jérémiah
13:10
created

AnnotationParser::formatRelay()   B

Complexity

Conditions 8
Paths 24

Size

Total Lines 46

Duplication

Lines 6
Ratio 13.04 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 6
loc 46
c 0
b 0
f 0
ccs 0
cts 39
cp 0
rs 7.9337
cc 8
nc 24
nop 4
crap 72
1
<?php
2
3
namespace Overblog\GraphQLBundle\Config\Parser;
4
5
use Overblog\GraphQLBundle\Config\Parser\ParserInterface;
6
use Symfony\Component\Config\Resource\FileResource;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
9
use Zend\Code\Reflection\PropertyReflection;
10
11
class AnnotationParser implements ParserInterface
12
{
13
    public static function getAnnotationReader()
14
    {
15
        if (!class_exists('\\Doctrine\\Common\\Annotations\\AnnotationReader') ||
16
            !class_exists('\\Doctrine\\Common\\Annotations\\AnnotationRegistry')
17
        ) {
18
            throw new \Exception('In order to use annotation, you need to require doctrine ORM');
19
        }
20
21
        $loader = require __DIR__ . '/../../../../autoload.php';
22
23
        \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Annotati...istry::registerLoader() has been deprecated with message: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists')

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
24
        \Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../../Annotation/GraphQLAnnotation.php');
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Annotati...egistry::registerFile() has been deprecated with message: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists')

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
25
        $reader = new \Doctrine\Common\Annotations\AnnotationReader();
26
27
        return $reader;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     *
33
     * @throws \ReflectionException
34
     * @throws InvalidArgumentException
35
     */
36
    public static function parse(\SplFileInfo $file, ContainerBuilder $container)
37
    {
38
        $reader = self::getAnnotationReader();
39
        $container->addResource(new FileResource($file->getRealPath()));
40
        try {
41
            $fileContent = file_get_contents($file->getRealPath());
42
43
            $entityName = substr($file->getFilename(), 0, -4);
44
            if (preg_match('#namespace (.+);#', $fileContent, $namespace)) {
45
                $className = $namespace[1] . '\\' . $entityName;
46
            } else {
47
                $className = $entityName;
48
            }
49
50
            $reflexionEntity = new \ReflectionClass($className);
51
52
            $annotations = $reader->getClassAnnotations($reflexionEntity);
53
            $annotations = self::parseAnnotation($annotations);
54
55
            $alias = self::getGraphQLAlias($annotations) ?: $entityName;
56
            $type = self::getGraphQLType($annotations);
57
58
            switch ($type) {
59
                case 'relay-connection':
60
                    return self::formatRelay($type, $alias, $annotations, $reflexionEntity->getProperties());
0 ignored issues
show
Documentation introduced by
$reflexionEntity->getProperties() is of type array<integer,object<ReflectionProperty>>, but the function expects a array<integer,object<Zen...on\PropertyReflection>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
                case 'enum':
62
                    return self::formatEnumType($alias, $entityName, $reflexionEntity->getProperties());
63
                case 'custom-scalar':
64
                    return self::formatCustomScalarType($alias, $type, $className, $annotations);
65
                default:
66
                    return self::formatScalarType($alias, $type, $entityName, $reflexionEntity->getProperties());
67
            }
68
        } catch (\InvalidArgumentException $e) {
69
            throw new InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
70
        }
71
    }
72
73
    /**
74
     * Get the graphQL alias
75
     *
76
     * @param $annotation
77
     *
78
     * @return string|null
79
     */
80
    protected static function getGraphQLAlias($annotation)
81
    {
82
        if (array_key_exists('GraphQLAlias', $annotation) && !empty($annotation['GraphQLAlias']['name'])) {
83
            return $annotation['GraphQLAlias']['name'];
84
        }
85
86
        return null;
87
    }
88
89
    /**
90
     * Get the graphQL type
91
     *
92
     * @param $annotation
93
     *
94
     * @return string
95
     */
96
    protected static function getGraphQLType($annotation)
97
    {
98
        if (array_key_exists('GraphQLType', $annotation) && !empty($annotation['GraphQLType']['type'])) {
99
            return $annotation['GraphQLType']['type'];
100
        }
101
102
        if (array_key_exists('GraphQLScalarType', $annotation) && !empty($annotation['GraphQLScalarType']['type'])) {
103
            return 'custom-scalar';
104
        }
105
106
        return 'object';
107
    }
108
109
    /**
110
     * @param string               $type
111
     * @param string               $alias
112
     * @param array                $classAnnotations
113
     * @param PropertyReflection[] $properties
114
     *
115
     * @return array
116
     *
117
     * @throws \Exception
118
     */
119
    protected static function formatRelay($type, $alias, $classAnnotations, $properties)
120
    {
121
        $reader = self::getAnnotationReader();
122
123
        $typesConfig = [
124
            $alias => [
125
                'type' => $type,
126
                'config' => [],
127
            ]
128
        ];
129
130
        if (!empty($classAnnotations['GraphQLNode'])) {
131
            $typesConfig[$alias]['config']['nodeType'] = $classAnnotations['GraphQLNode']['type'];
132
            $typesConfig[$alias]['config']['resolveNode'] = $classAnnotations['GraphQLNode']['resolve'];
133
        }
134
135
        foreach ($properties as $property) {
136
            $propertyName = $property->getName();
137
            $propertyAnnotation = $reader->getPropertyAnnotations($property);
138
            $propertyAnnotation = self::parseAnnotation($propertyAnnotation);
139
140
            if (!empty($propertyAnnotation['GraphQLEdgeFields'])) {
141 View Code Duplication
                if (empty($typesConfig[$alias]['config']['edgeFields'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
                    $typesConfig[$alias]['config']['edgeFields'] = [];
143
                }
144
145
                $typesConfig[$alias]['config']['edgeFields'][$propertyName] = [
146
                    'type' => $propertyAnnotation['GraphQLEdgeFields']['type'],
147
                    'resolve' => $propertyAnnotation['GraphQLEdgeFields']['resolve'],
148
                ];
149
            } elseif (!empty($propertyAnnotation['GraphQLConnectionFields'])) {
150 View Code Duplication
                if (empty($typesConfig[$alias]['config']['connectionFields'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
151
                    $typesConfig[$alias]['config']['connectionFields'] = [];
152
                }
153
154
                $typesConfig[$alias]['config']['connectionFields'][$propertyName] = [
155
                    'type' => $propertyAnnotation['GraphQLConnectionFields']['type'],
156
                    'resolve' => $propertyAnnotation['GraphQLConnectionFields']['resolve'],
157
                ];
158
            }
159
        }
160
161
        return empty($typesConfig[$alias]['config'])
162
            ? []
163
            : $typesConfig;
164
    }
165
166
    /**
167
     * Format enum type
168
     *
169
     * @param string                     $alias
170
     * @param string                     $entityName
171
     * @param \ReflectionProperty[]      $properties
172
     *
173
     * @return array
174
     */
175
    protected static function formatEnumType($alias, $entityName, $properties)
176
    {
177
        $reader = self::getAnnotationReader();
178
179
        $typesConfig = [
180
            $alias => [
181
                'type' => 'enum',
182
                'config' => [
183
                    'description' => $entityName . ' type',
184
                ],
185
            ]
186
        ];
187
188
        $values = [];
189
        /** @var \ReflectionProperty $property */
190
        foreach ($properties as $property) {
191
            $propertyName = $property->getName();
192
193
            $propertyAnnotation = $reader->getPropertyAnnotations($property);
194
            $propertyAnnotation = self::parseAnnotation($propertyAnnotation);
195
196
            $values[$propertyName] = [
197
                'value' => $propertyAnnotation,
198
            ];
199
200
            if (array_key_exists('GraphQLDescription', $propertyAnnotation) && !empty($test['GraphQLDescription']['description'])) {
201
                $values[$propertyName]['description'] = $test['GraphQLDescription']['description'];
202
            }
203
        }
204
205
        $typesConfig[$alias]['config']['values'] = $values;
206
207
        return $typesConfig;
208
    }
209
210
    /**
211
     * Format custom scalar type
212
     *
213
     * @param string $alias
214
     * @param string $type
215
     * @param string $className
216
     * @param array  $annotations
217
     *
218
     * @return array
219
     */
220
    protected static function formatCustomScalarType($alias, $type, $className, $annotations)
221
    {
222
        if (array_key_exists('GraphQLScalarType', $annotations) && !empty($annotations['GraphQLScalarType']['type'])) {
223
            return [
224
                $alias => [
225
                    'type' => $type,
226
                    'config' => [
227
                        'scalarType' => $annotations['GraphQLScalarType']['type'],
228
                    ],
229
                ],
230
            ];
231
        }
232
233
        $config = [
234
            'serialize' => [$className, 'serialize'],
235
            'parseValue' => [$className, 'parseValue'],
236
            'parseLiteral' => [$className, 'parseLiteral'],
237
        ];
238
239
        return [
240
            $alias => [
241
                'type' => $type,
242
                'config' => $config,
243
            ]
244
        ];
245
    }
246
247
    /**
248
     * Format scalar type
249
     *
250
     * @param string                $alias
251
     * @param string                $type
252
     * @param string                $entityName
253
     * @param \ReflectionProperty[] $properties
254
     *
255
     * @return array
256
     */
257
    protected static function formatScalarType($alias, $type, $entityName, $properties)
258
    {
259
        $reader = self::getAnnotationReader();
260
261
        $typesConfig = [
262
            $alias => [
263
                'type' => $type,
264
                'config' => [
265
                    'description' => $entityName . ' type',
266
                    'fields' => [],
267
                ],
268
            ]
269
        ];
270
271
        foreach ($properties as $property) {
272
            $propertyName = $property->getName();
273
            $propertyAnnotation = $reader->getPropertyAnnotations($property);
274
            $propertyAnnotation = self::parseAnnotation($propertyAnnotation);
275
276
            if (!$graphQlType = self::getGraphQLFieldType($propertyName, $propertyAnnotation)) {
277
                continue;
278
            }
279
280
            if ($graphQlAccessControl = self::getGraphQLAccessControl($propertyAnnotation)) {
281
                $graphQlType['access'] = $graphQlAccessControl;
282
            }
283
284
            if ($graphQlPublicControl = self::getGraphQLPublicControl($propertyAnnotation)) {
285
                $graphQlType['public'] = $graphQlPublicControl;
286
            }
287
288
            $typesConfig[$alias]['config']['fields'][$propertyName] = $graphQlType;
289
        }
290
291
        return empty($typesConfig[$alias]['config']['fields'])
292
            ? []
293
            : $typesConfig;
294
    }
295
296
    /**
297
     * Return the graphQL type for the named field
298
     *
299
     * @param string $name
300
     * @param array  $annotation
301
     *
302
     * @return array|null
303
     */
304
    protected static function getGraphQLFieldType($name, $annotation)
305
    {
306
        if (!$type = self::getGraphQLScalarFieldType($name, $annotation)) {
307
            if (!$type = self::getGraphQLQueryField($annotation)) {
308
                if (!$type = self::getGraphQLMutationField($annotation)) {
309
                    return null;
310
                }
311
            }
312
        }
313
314
        return $type;
315
    }
316
317
    /**
318
     * Return the common field type, like ID, Int, String, and other user-created type
319
     *
320
     * @param string $name
321
     * @param array  $annotation
322
     *
323
     * @return array|null
324
     */
325
    protected static function getGraphQLScalarFieldType($name, $annotation)
326
    {
327
        // Get the current type, depending on current annotation
328
        $type = $graphQLType = null;
0 ignored issues
show
Unused Code introduced by
$graphQLType is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
329
        $nullable = $isMultiple = false;
330
        if (array_key_exists('GraphQLColumn', $annotation) && array_key_exists('type', $annotation['GraphQLColumn'])) {
331
            $annotation = $annotation['GraphQLColumn'];
332
            $type = $annotation['type'];
333 View Code Duplication
        } elseif (array_key_exists('GraphQLToMany', $annotation) && array_key_exists('target', $annotation['GraphQLToMany'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
334
            $annotation = $annotation['GraphQLToMany'];
335
            $type = $annotation['target'];
336
            $isMultiple = $nullable = true;
337
        } elseif (array_key_exists('GraphQLToOne', $annotation) && array_key_exists('target', $annotation['GraphQLToOne'])) {
338
            $annotation = $annotation['GraphQLToOne'];
339
            $type = $annotation['target'];
340
            $nullable = true;
341 View Code Duplication
        } elseif (array_key_exists('OneToMany', $annotation) && array_key_exists('targetEntity', $annotation['OneToMany'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
342
            $annotation = $annotation['OneToMany'];
343
            $type = $annotation['targetEntity'];
344
            $isMultiple = $nullable = true;
345
        } elseif (array_key_exists('OneToOne', $annotation) && array_key_exists('targetEntity', $annotation['OneToOne'])) {
346
            $annotation = $annotation['OneToOne'];
347
            $type = $annotation['targetEntity'];
348
            $nullable = true;
349 View Code Duplication
        } elseif (array_key_exists('ManyToMany', $annotation) && array_key_exists('targetEntity', $annotation['ManyToMany'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
350
            $annotation = $annotation['ManyToMany'];
351
            $type = $annotation['targetEntity'];
352
            $isMultiple = $nullable = true;
353
        } elseif (array_key_exists('ManyToOne', $annotation) && array_key_exists('targetEntity', $annotation['ManyToOne'])) {
354
            $annotation = $annotation['ManyToOne'];
355
            $type = $annotation['targetEntity'];
356
            $nullable = true;
357
        } elseif (array_key_exists('Column', $annotation) && array_key_exists('type', $annotation['Column'])) {
358
            $annotation = $annotation['Column'];
359
            $type = $annotation['type'];
360
        }
361
362
        if (!$type) {
363
            return null;
364
        }
365
366
        if (array_key_exists('nullable', $annotation)) {
367
            $nullable = $annotation['nullable'] == 'true'
368
                ? true
369
                : false;
370
        }
371
372
        $type = explode('\\', $type);
373
        $type = $type[count($type)-1];
374
375
        // Get the graphQL type representation
376
        // Specific case for ID and relation
377
        if ($name === 'id' && $type === 'integer') {
378
            $graphQLType = 'ID';
379
        } else {
380
            // Make the relation between doctrine Column type and graphQL type
381
            switch ($type) {
382
                case 'integer';
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
383
                    $graphQLType = 'Int';
384
                    break;
385
                case 'string':
386
                case 'text':
387
                    $graphQLType = 'String';
388
                    break;
389
                case 'bool':
390
                case 'boolean':
391
                    $graphQLType = 'Boolean';
392
                    break;
393
                case 'float':
394
                case 'decimal':
395
                    $graphQLType = 'Float';
396
                    break;
397
                default:
398
                    // No maching: considering is custom-scalar graphQL type
399
                    $graphQLType = $type;
400
            }
401
        }
402
403
        if ($isMultiple) {
404
            $graphQLType = '['.$graphQLType.']';
405
        }
406
407
        if (!$nullable) {
408
            $graphQLType .= '!';
409
        }
410
411
        return ['type' => $graphQLType];
412
    }
413
414
    /**
415
     * Get the graphql query formatted field
416
     *
417
     * @param array $annotation
418
     *
419
     * @return array|null
420
     */
421
    protected static function getGraphQLQueryField($annotation)
422
    {
423
        if (!array_key_exists('GraphQLQuery', $annotation)) {
424
            return null;
425
        }
426
427
        $annotationQuery = $annotation['GraphQLQuery'];
428
429
        $ret = [
430
            'type' => $annotationQuery['type'],
431
        ];
432
433
        $method = $annotationQuery['method'];
434
        $args = $queryArgs = [];
435
        if (!empty($annotationQuery['input'])) {
436
            $annotationArgs = $annotationQuery['input'];
437
            if (!array_key_exists(0, $annotationArgs)) {
438
                $annotationArgs = [$annotationArgs];
439
            }
440
441
            foreach ($annotationArgs as $arg) {
442
                if (!empty($arg['target'])) {
443
                    if (!empty($arg['name']) && !empty($arg['type'])) {
444
                        $args[$arg['name']] = [
445
                            'type' => $arg['type'],
446
                        ];
447
448
                        if (!empty($arg['description'])) {
449
                            $args[$arg['name']]['description'] = $arg['description'];
450
                        }
451
                    }
452
453
                    $queryArgs[] = $arg['target'];
454
                } else {
455
                    $queryArgs[] = $arg;
456
                }
457
            }
458
459
            if (!empty($args)) {
460
                $ret['args'] = $args;
461
            }
462
        }
463
464
        if (!empty($queryArgs)) {
465
            $query = "'".$method."', [".implode(', ', $queryArgs)."]";
466
        } else {
467
            $query = "'".$method."'";
468
        }
469
470
        $ret['resolve'] = "@=resolver(".$query.")";
471
472
        if (!empty($annotationQuery['argsBuilder'])) {
473
            $ret['argsBuilder'] = $annotationQuery['argsBuilder'];
474
475
        }
476
477
        return $ret;
478
    }
479
480
    /**
481
     * Get the formatted graphQL mutation field
482
     *
483
     * @param array $annotation
484
     *
485
     * @return array
486
     */
487
    protected static function getGraphQLMutationField($annotation)
488
    {
489
        if (!array_key_exists('GraphQLMutation', $annotation)) {
490
            return self::getGraphQLRelayMutationField($annotation);
491
        }
492
493
        $annotation = $annotation['GraphQLMutation'];
494 View Code Duplication
        if (array_key_exists('args', $annotation)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
495
            $mutate = "@=mutation('".$annotation['method']."', [".implode(', ', $annotation['args'])."])";
496
        } else {
497
            $mutate = "'".$annotation['method']."'";
498
        }
499
500
        return [
501
            "type" => $annotation['payload'],
502
            "resolve" => $mutate,
503
            "args" => $annotation['input'],
504
        ];
505
    }
506
507
    /**
508
     * Get the formatted graphQL relay mutation field
509
     *
510
     * @param array $annotation
511
     *
512
     * @return array|null
513
     */
514
    protected static function getGraphQLRelayMutationField($annotation)
515
    {
516
        if (!array_key_exists('GraphQLRelayMutation', $annotation)) {
517
            return null;
518
        }
519
520
        $annotation = $annotation['GraphQLRelayMutation'];
521 View Code Duplication
        if (array_key_exists('args', $annotation)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
522
            $mutate = "'".$annotation['method']."', [".implode(', ', $annotation['args'])."]";
523
        } else {
524
            $mutate = "'".$annotation['method']."'";
525
        }
526
527
        return [
528
            "builder" => "Relay::Mutation",
529
            "builderConfig" => [
530
                "inputType" => $annotation['input'][0],
531
                "payloadType" => $annotation['payload'],
532
                "mutateAndGetPayload" => "@=mutation(".$mutate.")",
533
            ],
534
        ];
535
    }
536
537
    /**
538
     * Get graphql access control annotation
539
     *
540
     * @param $annotation
541
     *
542
     * @return null|string
543
     */
544 View Code Duplication
    protected static function getGraphQLAccessControl($annotation)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
545
    {
546
        if (array_key_exists('GraphQLAccessControl', $annotation) && array_key_exists('method', $annotation['GraphQLAccessControl'])) {
547
            return '@='.$annotation['GraphQLAccessControl']['method'];
548
        }
549
550
        return null;
551
    }
552
553
    /**
554
     * Get graphql public control
555
     *
556
     * @param $annotation
557
     *
558
     * @return null|string
559
     */
560 View Code Duplication
    protected static function getGraphQLPublicControl($annotation)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
561
    {
562
        if (array_key_exists('GraphQLPublicControl', $annotation) && array_key_exists('method', $annotation['GraphQLPublicControl'])) {
563
            return '@='.$annotation['GraphQLPublicControl']['method'];
564
        }
565
566
        return null;
567
    }
568
569
    /**
570
     * Parse annotation
571
     *
572
     * @param mixed $annotation
0 ignored issues
show
Documentation introduced by
There is no parameter named $annotation. Did you maybe mean $annotations?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
573
     *
574
     * @return array
575
     */
576
    protected static function parseAnnotation($annotations)
577
    {
578
        $returnAnnotation = [];
579
        foreach ($annotations as $index => $annotation) {
580
            if (!is_array($annotation)) {
581
                $index = explode('\\', get_class($annotation));
582
                $index = $index[count($index) - 1];
583
            }
584
585
            $returnAnnotation[$index] = [];
586
587
            foreach ($annotation as $indexAnnotation => $value) {
588
                $returnAnnotation[$index][$indexAnnotation] = $value;
589
            }
590
        }
591
592
        return $returnAnnotation;
593
    }
594
}
595