Completed
Push — master ( e6ba9d...11092d )
by Lars
02:14
created

ArrayyMeta::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arrayy;
6
7
class ArrayyMeta
8
{
9
10
    /** @noinspection MagicMethodsValidityInspection */
11
12
    /**
13
     * @param string $name
14
     *
15
     * @return string
16
     */
17
    public function __get($name)
18
    {
19
        return '';
20
    }
21
22
    /**
23
     * @param string $obj
24
     *
25
     * @return $this
26
     */
27 8
    public function getMetaObject(string $obj): self
28
    {
29 8
        static $STATIC_CACHE = [];
30
31 8
        $cacheKey = $obj;
32 8
        if (!empty($STATIC_CACHE[$cacheKey])) {
33 7
            return $STATIC_CACHE[$cacheKey];
34
        }
35
36 2
        $reflector = new \ReflectionClass($obj);
37 2
        $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
38 2
        $docblock = $factory->create($reflector->getDocComment());
39 2
        foreach ($docblock->getTagsByName('property') as $tag) {
40
            /** @var \phpDocumentor\Reflection\DocBlock\Tags\Property $tag */
41 2
            $PropertyName = $tag->getVariableName();
42 2
            $this->{$PropertyName} = $PropertyName;
43
        }
44
45 2
        $STATIC_CACHE[$cacheKey] = $this;
46
47 2
        return $this;
48
    }
49
}
50