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
15:29
created

AnnotationParser::getGraphQLRelayMutationField()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22

Duplication

Lines 5
Ratio 22.73 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 5
loc 22
c 0
b 0
f 0
ccs 0
cts 20
cp 0
rs 9.568
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Overblog\GraphQLBundle\Config\Parser;
4
5
use Symfony\Component\Config\Resource\FileResource;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
8
9
class AnnotationParser implements ParserInterface
10
{
11
    public static function getAnnotationReader()
12
    {
13
        if (!class_exists('\\Doctrine\\Common\\Annotations\\AnnotationReader') ||
14
            !class_exists('\\Doctrine\\Common\\Annotations\\AnnotationRegistry')
15
        ) {
16
            throw new \Exception('In order to use annotation, you need to require doctrine ORM');
17
        }
18
19
        $loader = require __DIR__.'/../../../../autoload.php';
20
21
        \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...
22
        \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...
23
        $reader = new \Doctrine\Common\Annotations\AnnotationReader();
24
25
        return $reader;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * @throws \ReflectionException
32
     * @throws InvalidArgumentException
33
     */
34
    public static function parse(\SplFileInfo $file, ContainerBuilder $container)
35
    {
36
        $reader = self::getAnnotationReader();
37
        $container->addResource(new FileResource($file->getRealPath()));
38
        try {
39
            $fileContent = file_get_contents($file->getRealPath());
40
41
            $entityName = substr($file->getFilename(), 0, -4);
42
            if (preg_match('#namespace (.+);#', $fileContent, $namespace)) {
43
                $className = $namespace[1].'\\'.$entityName;
44
            } else {
45
                $className = $entityName;
46
            }
47
48
            $reflexionEntity = new \ReflectionClass($className);
49
50
            $annotations = $reader->getClassAnnotations($reflexionEntity);
51
            $annotations = self::parseAnnotation($annotations);
52
53
            $alias = self::getGraphQLAlias($annotations) ?: $entityName;
54
            $type = self::getGraphQLType($annotations);
55
56
            switch ($type) {
57
                case 'relay-connection':
58
                    return self::formatRelay($type, $alias, $annotations, $reflexionEntity->getProperties());
59
                case 'enum':
60
                    return self::formatEnumType($alias, $entityName, $reflexionEntity->getProperties());
61
                case 'custom-scalar':
62
                    return self::formatCustomScalarType($alias, $type, $className, $annotations);
63
                default:
64
                    return self::formatScalarType($alias, $type, $entityName, $reflexionEntity->getProperties());
65
            }
66
        } catch (\InvalidArgumentException $e) {
67
            throw new InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
68
        }
69
    }
70
71
    /**
72
     * Get the graphQL alias.
73
     *
74
     * @param $annotation
75
     *
76
     * @return string|null
77
     */
78
    protected static function getGraphQLAlias($annotation)
79
    {
80
        if (array_key_exists('GraphQLAlias', $annotation) && !empty($annotation['GraphQLAlias']['name'])) {
81
            return $annotation['GraphQLAlias']['name'];
82
        }
83
84
        return null;
85
    }
86
87
    /**
88
     * Get the graphQL type.
89
     *
90
     * @param $annotation
91
     *
92
     * @return string
93
     */
94
    protected static function getGraphQLType($annotation)
95
    {
96
        if (array_key_exists('GraphQLType', $annotation) && !empty($annotation['GraphQLType']['type'])) {
97
            return $annotation['GraphQLType']['type'];
98
        }
99
100
        if (array_key_exists('GraphQLScalarType', $annotation) && !empty($annotation['GraphQLScalarType']['type'])) {
101
            return 'custom-scalar';
102
        }
103
104
        return 'object';
105
    }
106
107
    /**
108
     * @param string                $type
109
     * @param string                $alias
110
     * @param array                 $classAnnotations
111
     * @param \ReflectionProperty[] $properties
112
     *
113
     * @return array
114
     *
115
     * @throws \Exception
116
     */
117
    protected static function formatRelay($type, $alias, $classAnnotations, $properties)
118
    {
119
        $reader = self::getAnnotationReader();
120
121
        $typesConfig = [
122
            $alias => [
123
                'type' => $type,
124
                'config' => [],
125
            ],
126
        ];
127
128
        if (!empty($classAnnotations['GraphQLNode'])) {
129
            $typesConfig[$alias]['config']['nodeType'] = $classAnnotations['GraphQLNode']['type'];
130
            $typesConfig[$alias]['config']['resolveNode'] = $classAnnotations['GraphQLNode']['resolve'];
131
        }
132
133
        foreach ($properties as $property) {
134
            $propertyName = $property->getName();
135
            $propertyAnnotation = $reader->getPropertyAnnotations($property);
136
            $propertyAnnotation = self::parseAnnotation($propertyAnnotation);
137
138
            if (!empty($propertyAnnotation['GraphQLEdgeFields'])) {
139 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...
140
                    $typesConfig[$alias]['config']['edgeFields'] = [];
141
                }
142
143
                $typesConfig[$alias]['config']['edgeFields'][$propertyName] = [
144
                    'type' => $propertyAnnotation['GraphQLEdgeFields']['type'],
145
                    'resolve' => $propertyAnnotation['GraphQLEdgeFields']['resolve'],
146
                ];
147
            } elseif (!empty($propertyAnnotation['GraphQLConnectionFields'])) {
148 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...
149
                    $typesConfig[$alias]['config']['connectionFields'] = [];
150
                }
151
152
                $typesConfig[$alias]['config']['connectionFields'][$propertyName] = [
153
                    'type' => $propertyAnnotation['GraphQLConnectionFields']['type'],
154
                    'resolve' => $propertyAnnotation['GraphQLConnectionFields']['resolve'],
155
                ];
156
            }
157
        }
158
159
        return empty($typesConfig[$alias]['config'])
160
            ? []
161
            : $typesConfig;
162
    }
163
164
    /**
165
     * Format enum type.
166
     *
167
     * @param string                $alias
168
     * @param string                $entityName
169
     * @param \ReflectionProperty[] $properties
170
     *
171
     * @return array
172
     */
173
    protected static function formatEnumType($alias, $entityName, $properties)
174
    {
175
        $reader = self::getAnnotationReader();
176
177
        $typesConfig = [
178
            $alias => [
179
                'type' => 'enum',
180
                'config' => [
181
                    'description' => $entityName.' type',
182
                ],
183
            ],
184
        ];
185
186
        $values = [];
187
        /** @var \ReflectionProperty $property */
188
        foreach ($properties as $property) {
189
            $propertyName = $property->getName();
190
191
            $propertyAnnotation = $reader->getPropertyAnnotations($property);
192
            $propertyAnnotation = self::parseAnnotation($propertyAnnotation);
193
194
            $values[$propertyName] = [
195
                'value' => $propertyAnnotation,
196
            ];
197
198
            if (array_key_exists('GraphQLDescription', $propertyAnnotation) && !empty($test['GraphQLDescription']['description'])) {
199
                $values[$propertyName]['description'] = $test['GraphQLDescription']['description'];
200
            }
201
        }
202
203
        $typesConfig[$alias]['config']['values'] = $values;
204
205
        return $typesConfig;
206
    }
207
208
    /**
209
     * Format custom scalar type.
210
     *
211
     * @param string $alias
212
     * @param string $type
213
     * @param string $className
214
     * @param array  $annotations
215
     *
216
     * @return array
217
     */
218
    protected static function formatCustomScalarType($alias, $type, $className, $annotations)
219
    {
220
        if (array_key_exists('GraphQLScalarType', $annotations) && !empty($annotations['GraphQLScalarType']['type'])) {
221
            return [
222
                $alias => [
223
                    'type' => $type,
224
                    'config' => [
225
                        'scalarType' => $annotations['GraphQLScalarType']['type'],
226
                    ],
227
                ],
228
            ];
229
        }
230
231
        $config = [
232
            'serialize' => [$className, 'serialize'],
233
            'parseValue' => [$className, 'parseValue'],
234
            'parseLiteral' => [$className, 'parseLiteral'],
235
        ];
236
237
        return [
238
            $alias => [
239
                'type' => $type,
240
                'config' => $config,
241
            ],
242
        ];
243
    }
244
245
    /**
246
     * Format scalar type.
247
     *
248
     * @param string                $alias
249
     * @param string                $type
250
     * @param string                $entityName
251
     * @param \ReflectionProperty[] $properties
252
     *
253
     * @return array
254
     */
255
    protected static function formatScalarType($alias, $type, $entityName, $properties)
256
    {
257
        $reader = self::getAnnotationReader();
258
259
        $typesConfig = [
260
            $alias => [
261
                'type' => $type,
262
                'config' => [
263
                    'description' => $entityName.' type',
264
                    'fields' => [],
265
                ],
266
            ],
267
        ];
268
269
        foreach ($properties as $property) {
270
            $propertyName = $property->getName();
271
            $propertyAnnotation = $reader->getPropertyAnnotations($property);
272
            $propertyAnnotation = self::parseAnnotation($propertyAnnotation);
273
274
            if (!$graphQlType = self::getGraphQLFieldType($propertyName, $propertyAnnotation)) {
275
                continue;
276
            }
277
278
            if ($graphQlAccessControl = self::getGraphQLAccessControl($propertyAnnotation)) {
279
                $graphQlType['access'] = $graphQlAccessControl;
280
            }
281
282
            if ($graphQlPublicControl = self::getGraphQLPublicControl($propertyAnnotation)) {
283
                $graphQlType['public'] = $graphQlPublicControl;
284
            }
285
286
            $typesConfig[$alias]['config']['fields'][$propertyName] = $graphQlType;
287
        }
288
289
        return empty($typesConfig[$alias]['config']['fields'])
290
            ? []
291
            : $typesConfig;
292
    }
293
294
    /**
295
     * Return the graphQL type for the named field.
296
     *
297
     * @param string $name
298
     * @param array  $annotation
299
     *
300
     * @return array|null
301
     */
302
    protected static function getGraphQLFieldType($name, $annotation)
303
    {
304
        if (!$type = self::getGraphQLScalarFieldType($name, $annotation)) {
305
            if (!$type = self::getGraphQLQueryField($annotation)) {
306
                if (!$type = self::getGraphQLMutationField($annotation)) {
307
                    return null;
308
                }
309
            }
310
        }
311
312
        return $type;
313
    }
314
315
    /**
316
     * Return the common field type, like ID, Int, String, and other user-created type.
317
     *
318
     * @param string $name
319
     * @param array  $annotation
320
     *
321
     * @return array|null
322
     */
323
    protected static function getGraphQLScalarFieldType($name, $annotation)
324
    {
325
        // Get the current type, depending on current annotation
326
        $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...
327
        $nullable = $isMultiple = false;
328
        if (array_key_exists('GraphQLColumn', $annotation) && array_key_exists('type', $annotation['GraphQLColumn'])) {
329
            $annotation = $annotation['GraphQLColumn'];
330
            $type = $annotation['type'];
331 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...
332
            $annotation = $annotation['GraphQLToMany'];
333
            $type = $annotation['target'];
334
            $isMultiple = $nullable = true;
335
        } elseif (array_key_exists('GraphQLToOne', $annotation) && array_key_exists('target', $annotation['GraphQLToOne'])) {
336
            $annotation = $annotation['GraphQLToOne'];
337
            $type = $annotation['target'];
338
            $nullable = true;
339 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...
340
            $annotation = $annotation['OneToMany'];
341
            $type = $annotation['targetEntity'];
342
            $isMultiple = $nullable = true;
343
        } elseif (array_key_exists('OneToOne', $annotation) && array_key_exists('targetEntity', $annotation['OneToOne'])) {
344
            $annotation = $annotation['OneToOne'];
345
            $type = $annotation['targetEntity'];
346
            $nullable = true;
347 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...
348
            $annotation = $annotation['ManyToMany'];
349
            $type = $annotation['targetEntity'];
350
            $isMultiple = $nullable = true;
351
        } elseif (array_key_exists('ManyToOne', $annotation) && array_key_exists('targetEntity', $annotation['ManyToOne'])) {
352
            $annotation = $annotation['ManyToOne'];
353
            $type = $annotation['targetEntity'];
354
            $nullable = true;
355
        } elseif (array_key_exists('Column', $annotation) && array_key_exists('type', $annotation['Column'])) {
356
            $annotation = $annotation['Column'];
357
            $type = $annotation['type'];
358
        }
359
360
        if (!$type) {
361
            return null;
362
        }
363
364
        if (array_key_exists('nullable', $annotation)) {
365
            $nullable = 'true' == $annotation['nullable']
366
                ? true
367
                : false;
368
        }
369
370
        $type = explode('\\', $type);
371
        $type = $type[count($type) - 1];
372
373
        // Get the graphQL type representation
374
        // Specific case for ID and relation
375
        if ('id' === $name && 'integer' === $type) {
376
            $graphQLType = 'ID';
377
        } else {
378
            // Make the relation between doctrine Column type and graphQL type
379
            switch ($type) {
380
                case 'integer':
381
                    $graphQLType = 'Int';
382
                    break;
383
                case 'string':
384
                case 'text':
385
                    $graphQLType = 'String';
386
                    break;
387
                case 'bool':
388
                case 'boolean':
389
                    $graphQLType = 'Boolean';
390
                    break;
391
                case 'float':
392
                case 'decimal':
393
                    $graphQLType = 'Float';
394
                    break;
395
                default:
396
                    // No maching: considering is custom-scalar graphQL type
397
                    $graphQLType = $type;
398
            }
399
        }
400
401
        if ($isMultiple) {
402
            $graphQLType = '['.$graphQLType.']';
403
        }
404
405
        if (!$nullable) {
406
            $graphQLType .= '!';
407
        }
408
409
        return ['type' => $graphQLType];
410
    }
411
412
    /**
413
     * Get the graphql query formatted field.
414
     *
415
     * @param array $annotation
416
     *
417
     * @return array|null
418
     */
419
    protected static function getGraphQLQueryField($annotation)
420
    {
421
        if (!array_key_exists('GraphQLQuery', $annotation)) {
422
            return null;
423
        }
424
425
        $annotationQuery = $annotation['GraphQLQuery'];
426
427
        $ret = [
428
            'type' => $annotationQuery['type'],
429
        ];
430
431
        $method = $annotationQuery['method'];
432
        $args = $queryArgs = [];
433
        if (!empty($annotationQuery['input'])) {
434
            $annotationArgs = $annotationQuery['input'];
435
            if (!array_key_exists(0, $annotationArgs)) {
436
                $annotationArgs = [$annotationArgs];
437
            }
438
439
            foreach ($annotationArgs as $arg) {
440
                if (!empty($arg['target'])) {
441
                    if (!empty($arg['name']) && !empty($arg['type'])) {
442
                        $args[$arg['name']] = [
443
                            'type' => $arg['type'],
444
                        ];
445
446
                        if (!empty($arg['description'])) {
447
                            $args[$arg['name']]['description'] = $arg['description'];
448
                        }
449
                    }
450
451
                    $queryArgs[] = $arg['target'];
452
                } else {
453
                    $queryArgs[] = $arg;
454
                }
455
            }
456
457
            if (!empty($args)) {
458
                $ret['args'] = $args;
459
            }
460
        }
461
462
        if (!empty($queryArgs)) {
463
            $query = "'".$method."', [".implode(', ', $queryArgs).']';
464
        } else {
465
            $query = "'".$method."'";
466
        }
467
468
        $ret['resolve'] = '@=resolver('.$query.')';
469
470
        if (!empty($annotationQuery['argsBuilder'])) {
471
            $ret['argsBuilder'] = $annotationQuery['argsBuilder'];
472
        }
473
474
        return $ret;
475
    }
476
477
    /**
478
     * Get the formatted graphQL mutation field.
479
     *
480
     * @param array $annotation
481
     *
482
     * @return array
483
     */
484
    protected static function getGraphQLMutationField($annotation)
485
    {
486
        if (!array_key_exists('GraphQLMutation', $annotation)) {
487
            return self::getGraphQLRelayMutationField($annotation);
488
        }
489
490
        $annotation = $annotation['GraphQLMutation'];
491 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...
492
            $mutate = "@=mutation('".$annotation['method']."', [".implode(', ', $annotation['args']).'])';
493
        } else {
494
            $mutate = "'".$annotation['method']."'";
495
        }
496
497
        return [
498
            'type' => $annotation['payload'],
499
            'resolve' => $mutate,
500
            'args' => $annotation['input'],
501
        ];
502
    }
503
504
    /**
505
     * Get the formatted graphQL relay mutation field.
506
     *
507
     * @param array $annotation
508
     *
509
     * @return array|null
510
     */
511
    protected static function getGraphQLRelayMutationField($annotation)
512
    {
513
        if (!array_key_exists('GraphQLRelayMutation', $annotation)) {
514
            return null;
515
        }
516
517
        $annotation = $annotation['GraphQLRelayMutation'];
518 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...
519
            $mutate = "'".$annotation['method']."', [".implode(', ', $annotation['args']).']';
520
        } else {
521
            $mutate = "'".$annotation['method']."'";
522
        }
523
524
        return [
525
            'builder' => 'Relay::Mutation',
526
            'builderConfig' => [
527
                'inputType' => $annotation['input'][0],
528
                'payloadType' => $annotation['payload'],
529
                'mutateAndGetPayload' => '@=mutation('.$mutate.')',
530
            ],
531
        ];
532
    }
533
534
    /**
535
     * Get graphql access control annotation.
536
     *
537
     * @param $annotation
538
     *
539
     * @return null|string
540
     */
541 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...
542
    {
543
        if (array_key_exists('GraphQLAccessControl', $annotation) && array_key_exists('method', $annotation['GraphQLAccessControl'])) {
544
            return '@='.$annotation['GraphQLAccessControl']['method'];
545
        }
546
547
        return null;
548
    }
549
550
    /**
551
     * Get graphql public control.
552
     *
553
     * @param $annotation
554
     *
555
     * @return null|string
556
     */
557 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...
558
    {
559
        if (array_key_exists('GraphQLPublicControl', $annotation) && array_key_exists('method', $annotation['GraphQLPublicControl'])) {
560
            return '@='.$annotation['GraphQLPublicControl']['method'];
561
        }
562
563
        return null;
564
    }
565
566
    /**
567
     * Parse annotation.
568
     *
569
     * @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...
570
     *
571
     * @return array
572
     */
573
    protected static function parseAnnotation($annotations)
574
    {
575
        $returnAnnotation = [];
576
        foreach ($annotations as $index => $annotation) {
577
            if (!is_array($annotation)) {
578
                $index = explode('\\', get_class($annotation));
579
                $index = $index[count($index) - 1];
580
            }
581
582
            $returnAnnotation[$index] = [];
583
584
            foreach ($annotation as $indexAnnotation => $value) {
585
                $returnAnnotation[$index][$indexAnnotation] = $value;
586
            }
587
        }
588
589
        return $returnAnnotation;
590
    }
591
}
592