Completed
Push — master ( 679ccf...e6ba9d )
by Lars
02:10
created

ArrayyMeta::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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