Completed
Pull Request — master (#601)
by
unknown
02:29
created

DocumentGenerateCommand   B

Complexity

Total Complexity 47

Size/Duplication

Total Lines 604
Duplicated Lines 11.09 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 47
c 2
b 0
f 1
lcom 1
cbo 11
dl 67
loc 604
rs 7.9553

21 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 6 2
D interact() 0 171 13
A askForPropertyName() 8 8 1
A askForPropertyOptions() 13 13 1
A askForPropertyClass() 13 13 1
A getDocumentClasses() 0 15 3
A parseShortcutNotation() 0 13 2
A validatePropertyClass() 0 11 2
A validateDocumentName() 0 11 2
A validateFieldName() 0 15 4
A validatePropertyType() 11 11 2
A validateDocumentAnnotation() 11 11 2
A validatePropertyAnnotation() 11 11 2
A getQuestion() 0 13 2
A getOptionsLabel() 0 10 2
A getException() 0 6 1
A getPropertyTypes() 0 10 1
A getPropertyAnnotations() 0 4 1
A getDocumentAnnotations() 0 4 1
A getReservedKeywords() 0 71 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like DocumentGenerateCommand often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use DocumentGenerateCommand, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Command;
13
14
use ONGR\ElasticsearchBundle\Mapping\MetadataCollector;
15
use Symfony\Component\Console\Helper\FormatterHelper;
16
use Symfony\Component\Console\Helper\QuestionHelper;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Console\Question\ConfirmationQuestion;
20
use Symfony\Component\Console\Question\Question;
21
use Symfony\Component\HttpKernel\Kernel;
22
23
class DocumentGenerateCommand extends AbstractManagerAwareCommand
24
{
25
    /**
26
     * @var QuestionHelper
27
     */
28
    private $questionHelper;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function configure()
34
    {
35
        parent::configure();
36
37
        $this
38
            ->setName('ongr:es:document:generate')
39
            ->setDescription('Generates a new Elasticsearch document inside a bundle');
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        if ($input->hasParameterOption(['--no-interaction', '-n'])) {
48
            throw $this->getException('No interaction mode is not allowed!');
49
        }
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function interact(InputInterface $input, OutputInterface $output)
56
    {
57
        /** @var FormatterHelper $formatter */
58
        $formatter = $this->getHelperSet()->get('formatter');
59
        $this->questionHelper = new QuestionHelper();
60
61
        $output->writeln(
62
            [
63
                '',
64
                $formatter->formatBlock('Welcome to the ONGRElasticsearchBundle document generator', 'bg=blue', true),
65
                '',
66
                'This command helps you generate ONGRElasticsearchBundle documents.',
67
                '',
68
                'First, you need to give the document name you want to generate.',
69
                'You must use the shortcut notation like <comment>AcmeDemoBundle:Post</comment>.',
70
                '',
71
            ]
72
        );
73
74
        /** @var Kernel $kernel */
75
        $kernel = $this->getContainer()->get('kernel');
76
        $bundleNames = array_keys($kernel->getBundles());
77
78
        while (true) {
79
            $document = $this->questionHelper->ask(
80
                $input,
81
                $output,
82
                $this->getQuestion('The Document shortcut name', null, [$this, 'validateDocumentName'], $bundleNames)
83
            );
84
85
            list($bundle, $document) = $this->parseShortcutNotation($document);
86
87
            if (in_array(strtolower($document), $this->getReservedKeywords())) {
88
                $output->writeln(
89
                    $formatter->formatBlock(sprintf('"%s" is a reserved word.', $document), 'bg=red', true)
90
                );
91
                continue;
92
            }
93
94
            try {
95
                if (!file_exists(
96
                    $kernel->getBundle($bundle)->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php'
97
                )) {
98
                    break;
99
                }
100
101
                $output->writeln(
102
                    $formatter->formatBlock(
103
                        sprintf('Document "%s:%s" already exists.', $bundle, $document),
104
                        'bg=red',
105
                        true
106
                    )
107
                );
108
            } catch (\Exception $e) {
109
                $output->writeln(
110
                    $formatter->formatBlock(sprintf('Bundle "%s" does not exist.', $bundle), 'bg=red', true)
111
                );
112
            }
113
        }
114
115
        $output->writeln($this->getOptionsLabel($this->getDocumentAnnotations(), 'Available types'));
116
        $annotation = $this->questionHelper->ask(
117
            $input,
118
            $output,
119
            $this->getQuestion(
120
                'Document type',
121
                'Document',
122
                [$this, 'validateDocumentAnnotation'],
123
                $this->getDocumentAnnotations()
124
            )
125
        );
126
127
        $documentType = lcfirst($document);
0 ignored issues
show
Bug introduced by
The variable $document does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
128
        if ($annotation == 'Document') {
129
            $documentType = $this->questionHelper->ask(
130
                $input,
131
                $output,
132
                $this->getQuestion(
133
                    "\n" . 'Elasticsearch Document name',
134
                    lcfirst($document),
135
                    [$this, 'validateFieldName']
136
                )
137
            );
138
        }
139
140
        $properties = [];
141
        $output->writeln(['', $formatter->formatBlock('New Document Property', 'bg=blue;fg=white', true)]);
142
143
        while (true) {
144
            $question = $this->getQuestion(
145
                'Property name [<comment>press <info><return></info> to stop</comment>]',
146
                false
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a null|string.

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...
147
            );
148
149
            if (!$field = $this->questionHelper->ask($input, $output, $question)) {
150
                break;
151
            }
152
153
            try {
154
                $this->validateFieldName($field);
155
            } catch (\InvalidArgumentException $e) {
156
                $output->writeln($e->getMessage());
157
                continue;
158
            }
159
160
            $output->writeln($this->getOptionsLabel($this->getPropertyAnnotations(), 'Available annotations'));
161
            $property['annotation'] = $this->questionHelper->ask(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$property was never initialized. Although not strictly required by PHP, it is generally a good practice to add $property = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
162
                $input,
163
                $output,
164
                $this->getQuestion(
165
                    'Property annotation',
166
                    'Property',
167
                    [$this, 'validatePropertyAnnotation'],
168
                    $this->getPropertyAnnotations()
169
                )
170
            );
171
172
            $property['field_name'] = $property['property_name'] = $field;
173
174
            switch ($property['annotation']) {
175
                case 'Embedded':
176
                    $property['property_name'] = $this->askForPropertyName($input, $output, $property['field_name']);
177
                    $property['property_class'] = $this->askForPropertyClass($input, $output);
178
179
                    $question = new ConfirmationQuestion("\n<info>Multiple</info> [<comment>no</comment>]: ", false);
180
                    $question->setAutocompleterValues(['yes', 'no']);
181
                    $property['property_multiple'] = $this->questionHelper->ask($input, $output, $question);
182
183
                    $property['property_options'] = $this->askForPropertyOptions($input, $output);
184
                    break;
185
                case 'ParentDocument':
186
                    $property['property_class'] = $this->askForPropertyClass($input, $output);
187
                    break;
188
                case 'Property':
189
                    $property['property_name'] = $this->askForPropertyName($input, $output, $property['field_name']);
190
191
                    $output->writeln($this->getOptionsLabel($this->getPropertyTypes(), 'Available types'));
192
                    $property['property_type'] = $this->questionHelper->ask(
193
                        $input,
194
                        $output,
195
                        $this->getQuestion(
196
                            'Property type',
197
                            'string',
198
                            [$this, 'validatePropertyType'],
199
                            $this->getPropertyTypes()
200
                        )
201
                    );
202
203
                    $property['property_options'] = $this->askForPropertyOptions($input, $output);
204
                    break;
205
                case 'Ttl':
206
                    $property['property_default'] = $this->questionHelper->ask(
207
                        $input,
208
                        $output,
209
                        $this->getQuestion("\n" . 'Default time to live')
210
                    );
211
                    break;
212
            }
213
214
            $properties[] = $property;
215
            $output->writeln(['', $formatter->formatBlock('New Document Property', 'bg=blue;fg=white', true)]);
216
        }
217
218
        $this->getContainer()->get('es.generate')->generate(
219
            $this->getContainer()->get('kernel')->getBundle($bundle),
0 ignored issues
show
Bug introduced by
The variable $bundle does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
220
            $document,
221
            $annotation,
222
            $documentType,
223
            $properties
224
        );
225
    }
226
227
    /**
228
     * Asks for property name
229
     *
230
     * @param InputInterface  $input
231
     * @param OutputInterface $output
232
     * @param mixed           $default
233
     *
234
     * @return string
235
     */
236 View Code Duplication
    private function askForPropertyName(InputInterface $input, OutputInterface $output, $default = null)
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...
237
    {
238
        return $this->questionHelper->ask(
239
            $input,
240
            $output,
241
            $this->getQuestion("\n" . 'Property name in Elasticsearch', $default, [$this, 'validateFieldName'])
242
        );
243
    }
244
245
    /**
246
     * Asks for property options
247
     *
248
     * @param InputInterface  $input
249
     * @param OutputInterface $output
250
     *
251
     * @return string
252
     */
253 View Code Duplication
    private function askForPropertyOptions(InputInterface $input, OutputInterface $output)
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...
254
    {
255
        return $this->questionHelper->ask(
256
            $input,
257
            $output,
258
            $this->getQuestion(
259
                "\n" . 'Property options [<comment>press <info><return></info> to stop</comment>]',
260
                false,
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a null|string.

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...
261
                null,
262
                ['"index"="not_analyzed"', '"analyzer"="standard"']
263
            )
264
        );
265
    }
266
267
    /**
268
     * Asks for property class
269
     *
270
     * @param InputInterface  $input
271
     * @param OutputInterface $output
272
     *
273
     * @return string
274
     */
275 View Code Duplication
    private function askForPropertyClass(InputInterface $input, OutputInterface $output)
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...
276
    {
277
        return $this->questionHelper->ask(
278
            $input,
279
            $output,
280
            $this->getQuestion(
281
                "\n" . 'Property class',
282
                null,
283
                [$this, 'validatePropertyClass'],
284
                $this->getDocumentClasses()
285
            )
286
        );
287
    }
288
289
    /**
290
     * Returns available document classes
291
     *
292
     * @return array
293
     */
294
    private function getDocumentClasses()
295
    {
296
        /** @var MetadataCollector $metadataCollector */
297
        $metadataCollector = $this->getContainer()->get('es.metadata_collector');
298
        $classes = [];
299
300
        foreach ($this->getContainer()->getParameter('es.managers') as $manager) {
301
            $documents = $metadataCollector->getMappings($manager['mappings']);
302
            foreach ($documents as $document) {
303
                $classes[] = sprintf('%s:%s', $document['bundle'], $document['class']);
304
            }
305
        }
306
307
        return $classes;
308
    }
309
310
    /**
311
     * Parses shortcut notation
312
     *
313
     * @param string $shortcut
314
     *
315
     * @return array
316
     * @throws \InvalidArgumentException
317
     */
318
    private function parseShortcutNotation($shortcut)
319
    {
320
        $shortcut = str_replace('/', '\\', $shortcut);
321
322
        if (false === $pos = strpos($shortcut, ':')) {
323
            throw $this->getException(
324
                'The document name isn\'t valid ("%s" given, expecting something like AcmeBundle:Post)',
325
                [$shortcut]
326
            );
327
        }
328
329
        return [substr($shortcut, 0, $pos), substr($shortcut, $pos + 1)];
330
    }
331
332
    /**
333
     * Validates property class
334
     *
335
     * @param string $class
336
     *
337
     * @return string
338
     * @throws \InvalidArgumentException
339
     */
340
    public function validatePropertyClass($class)
341
    {
342
        if (!in_array($class, $this->getDocumentClasses())) {
343
            throw $this->getException(
344
                'The document isn\'t available ("%s" given, expecting one of following: %s)',
345
                [$class, $this->getDocumentClasses()]
346
            );
347
        }
348
349
        return $class;
350
    }
351
352
    /**
353
     * Performs basic checks in document name
354
     *
355
     * @param string $document
356
     *
357
     * @return string
358
     * @throws \InvalidArgumentException
359
     */
360
    public function validateDocumentName($document)
361
    {
362
        if (!preg_match('{^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*:[a-zA-Z0-9_\x7f-\xff\\\/]+$}', $document)) {
363
            throw $this->getException(
364
                'The document name isn\'t valid ("%s" given, expecting something like AcmeBundle:Post)',
365
                [$document]
366
            );
367
        }
368
369
        return $document;
370
    }
371
372
    /**
373
     * Validates field name
374
     *
375
     * @param string $field
376
     *
377
     * @return string
378
     * @throws \InvalidArgumentException
379
     */
380
    public function validateFieldName($field)
381
    {
382
        if (!$field || $field != lcfirst(preg_replace('/[^a-zA-Z]+/', '', $field))) {
383
            throw $this->getException(
384
                'The parameter isn\'t valid ("%s" given, expecting camelcase separated words)',
385
                [$field]
386
            );
387
        }
388
389
        if (in_array(strtolower($field), $this->getReservedKeywords())) {
390
            throw $this->getException('"%s" is a reserved word.', [$field]);
391
        }
392
393
        return $field;
394
    }
395
396
    /**
397
     * Validates property type
398
     *
399
     * @param string $type
400
     *
401
     * @return string
402
     * @throws \InvalidArgumentException
403
     */
404 View Code Duplication
    public function validatePropertyType($type)
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...
405
    {
406
        if (!in_array($type, $this->getPropertyTypes())) {
407
            throw $this->getException(
408
                'The property type isn\'t valid ("%s" given, expecting one of following: %s)',
409
                [$type, implode(', ', $this->getPropertyTypes())]
410
            );
411
        }
412
413
        return $type;
414
    }
415
416
    /**
417
     * Validates document annotation
418
     *
419
     * @param string $annotation
420
     *
421
     * @return string
422
     * @throws \InvalidArgumentException
423
     */
424 View Code Duplication
    public function validateDocumentAnnotation($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...
425
    {
426
        if (!in_array($annotation, $this->getDocumentAnnotations())) {
427
            throw $this->getException(
428
                'The document annotation isn\'t valid ("%s" given, expecting one of following: %s)',
429
                [$annotation, implode(', ', $this->getDocumentAnnotations())]
430
            );
431
        }
432
433
        return $annotation;
434
    }
435
436
    /**
437
     * Validates property annotation
438
     *
439
     * @param string $annotation
440
     *
441
     * @return string
442
     * @throws \InvalidArgumentException
443
     */
444 View Code Duplication
    public function validatePropertyAnnotation($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...
445
    {
446
        if (!in_array($annotation, $this->getPropertyAnnotations())) {
447
            throw $this->getException(
448
                'The property annotation isn\'t valid ("%s" given, expecting one of following: %s)',
449
                [$annotation, implode(', ', $this->getPropertyAnnotations())]
450
            );
451
        }
452
453
        return $annotation;
454
    }
455
456
    /**
457
     * Returns formatted question
458
     *
459
     * @param string        $question
460
     * @param null|string   $default
461
     * @param callable|null $validator
462
     * @param array|null    $values
463
     *
464
     * @return Question
465
     */
466
    private function getQuestion($question, $default = null, callable $validator = null, array $values = null)
467
    {
468
        $question = new Question(
469
            sprintf('<info>%s</info>%s: ', $question, $default ? sprintf(' [<comment>%s</comment>]', $default) : ''),
470
            $default
471
        );
472
473
        $question
474
            ->setValidator($validator)
475
            ->setAutocompleterValues($values);
476
477
        return $question;
478
    }
479
480
    /**
481
     * Returns options label
482
     *
483
     * @param array  $options
484
     * @param string $suffix
485
     *
486
     * @return array
487
     */
488
    private function getOptionsLabel(array $options, $suffix)
489
    {
490
        $label = sprintf('<info>%s:</info> ', $suffix);
491
492
        foreach ($options as &$option) {
493
            $option = sprintf('<comment>%s</comment>', $option);
494
        }
495
496
        return ['', $label . implode(', ', $options) . '.'];
497
    }
498
499
    /**
500
     * Returns formatted exception
501
     *
502
     * @param string $format
503
     * @param array  $args
504
     *
505
     * @return \InvalidArgumentException
506
     */
507
    private function getException($format, $args = [])
508
    {
509
        /** @var FormatterHelper $formatter */
510
        $formatter = $this->getHelperSet()->get('formatter');
511
        return new \InvalidArgumentException($formatter->formatBlock(vsprintf($format, $args), 'bg=red', true));
512
    }
513
514
    /**
515
     * Returns available property types
516
     *
517
     * @return array
518
     */
519
    private function getPropertyTypes()
520
    {
521
        $reflection = new \ReflectionClass('ONGR\ElasticsearchBundle\Annotation\Property');
522
523
        return $this
524
            ->getContainer()
525
            ->get('annotations.cached_reader')
526
            ->getPropertyAnnotation($reflection->getProperty('type'), 'Doctrine\Common\Annotations\Annotation\Enum')
527
            ->value;
528
    }
529
530
    /**
531
     * Returns property annotations
532
     *
533
     * @return array
534
     */
535
    private function getPropertyAnnotations()
536
    {
537
        return ['Embedded', 'Id', 'ParentDocument', 'Property', 'Ttl'];
538
    }
539
540
    /**
541
     * Returns document annotations
542
     *
543
     * @return array
544
     */
545
    private function getDocumentAnnotations()
546
    {
547
        return ['Document', 'Nested', 'Object'];
548
    }
549
550
    /**
551
     * Returns reserved keywords
552
     *
553
     * @return array
554
     */
555
    private function getReservedKeywords()
556
    {
557
        return [
558
            'abstract',
559
            'and',
560
            'array',
561
            'as',
562
            'break',
563
            'callable',
564
            'case',
565
            'catch',
566
            'class',
567
            'clone',
568
            'const',
569
            'continue',
570
            'declare',
571
            'default',
572
            'do',
573
            'else',
574
            'elseif',
575
            'enddeclare',
576
            'endfor',
577
            'endforeach',
578
            'endif',
579
            'endswitch',
580
            'endwhile',
581
            'extends',
582
            'final',
583
            'finally',
584
            'for',
585
            'foreach',
586
            'function',
587
            'global',
588
            'goto',
589
            'if',
590
            'implements',
591
            'interface',
592
            'instanceof',
593
            'insteadof',
594
            'namespace',
595
            'new',
596
            'or',
597
            'private',
598
            'protected',
599
            'public',
600
            'static',
601
            'switch',
602
            'throw',
603
            'trait',
604
            'try',
605
            'use',
606
            'var',
607
            'while',
608
            'xor',
609
            'yield',
610
            'die',
611
            'echo',
612
            'empty',
613
            'exit',
614
            'eval',
615
            'include',
616
            'include_once',
617
            'isset',
618
            'list',
619
            'require',
620
            'require_once',
621
            'return',
622
            'print',
623
            'unset',
624
        ];
625
    }
626
}
627