Completed
Push — master ( 1d4eca...2da837 )
by Lars
01:50
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
final class ArrayyMeta
8
{
9
10
    /** @noinspection MagicMethodsValidityInspection */
11
12
    /**
13
     * @param string $name
14
     *
15
     * @return string
16
     */
17
    public function __get($name): string
18
    {
19
        return '';
20
    }
21
22
    /**
23
     * @param string $obj
24
     *
25
     * @return $this
26
     */
27 14
    public function getMetaObject(string $obj): self
28
    {
29 14
        static $STATIC_CACHE = [];
30
31 14
        $cacheKey = $obj;
32 14
        if (!empty($STATIC_CACHE[$cacheKey])) {
33 13
            return $STATIC_CACHE[$cacheKey];
34
        }
35
36 2
        $reflector = new \ReflectionClass($obj);
37 2
        $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
38 2
        $docComment = $reflector->getDocComment();
39 2
        if ($docComment) {
40 2
            $docblock = $factory->create($docComment);
41 2
            foreach ($docblock->getTagsByName('property') as $tag) {
42
                /** @var \phpDocumentor\Reflection\DocBlock\Tags\Property $tag */
43 2
                $PropertyName = $tag->getVariableName();
44 2
                $this->{$PropertyName} = $PropertyName;
45
            }
46
        }
47
48 2
        $STATIC_CACHE[$cacheKey] = $this;
49
50 2
        return $this;
51
    }
52
}
53