Completed
Push — master ( 1d4eca...2da837 )
by Lars
01:50
created

ArrayyMeta   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 4 1
A getMetaObject() 0 25 4
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