ReflectionService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPropertyTagsValues() 0 10 2
A getPropertyTagValues() 0 10 2
A handleArrayAnnotation() 0 14 4
1
<?php
2
/*
3
 * 2018 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 Configuration Object project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\ConfigurationObject\Reflection;
15
16
use Romm\ConfigurationObject\Core\Core;
17
18
/**
19
 * This class is used to handle the common array annotation: `\Some\Class[]`.
20
 *
21
 * Indeed, TYPO3 does only support annotations like: `\ArrayObject<\Some\Class>`
22
 * but this is not well supported by IDEs.
23
 */
24
class ReflectionService extends \Romm\ConfigurationObject\Legacy\Reflection\ReflectionService
25
{
26
    /**
27
     * @inheritdoc
28
     */
29
    public function getPropertyTagsValues($className, $propertyName)
30
    {
31
        $result = parent::getPropertyTagsValues($className, $propertyName);
32
33
        if (isset($result['var'])) {
34
            $result['var'] = $this->handleArrayAnnotation($result['var']);
35
        }
36
37
        return $result;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function getPropertyTagValues($className, $propertyName, $tag)
44
    {
45
        $result = parent::getPropertyTagValues($className, $propertyName, $tag);
46
47
        if ($tag === 'var') {
48
            $result = $this->handleArrayAnnotation($result);
49
        }
50
51
        return $result;
52
    }
53
54
    /**
55
     * Will transform the annotation:
56
     * `\Some\Class[]` -> `\ArrayObject<\Some\Class>
57
     *
58
     * The last one is supported by TYPO3. See class description for more
59
     * information.
60
     *
61
     * @param array $varTags
62
     * @return array
63
     */
64
    protected function handleArrayAnnotation(array $varTags)
65
    {
66
        foreach ($varTags as $key => $tag) {
67
            if ('[]' === substr($tag, -2)) {
68
                $class = substr($tag, 0, -2);
69
70
                if (Core::get()->classExists($class)) {
71
                    $varTags[$key] = "\\ArrayObject<$class>";
72
                }
73
            }
74
        }
75
76
        return $varTags;
77
    }
78
}
79