Completed
Push — master ( 9d7f2b...8fe48d )
by Lars
24:45
created

ArrayyMeta::getMetaObject()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 21
ccs 13
cts 13
cp 1
crap 3
rs 9.584
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
     * @param string $obj
11
     *
12
     * @return $this
13
     */
14 7
    public function getMetaObject(string $obj) {
15 7
        static $STATIC_CACHE = array();
16
17 7
        $cacheKey = $obj;
18 7
        if (!empty($STATIC_CACHE[$cacheKey])) {
19 6
            return $STATIC_CACHE[$cacheKey];
20
        }
21
22 2
        $reflector = new \ReflectionClass($obj);
23 2
        $factory  = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
24 2
        $docblock = $factory->create($reflector->getDocComment());
25 2
        foreach ($docblock->getTagsByName('property') as $tag) {
26
          /* @var $tag \phpDocumentor\Reflection\DocBlock\Tags\Property */
27 2
          $PropertyName = $tag->getVariableName();
28 2
          $this->{$PropertyName} = $PropertyName;
29
        }
30
31 2
        $STATIC_CACHE[$cacheKey] = $this;
32
33 2
        return $this;
34
    }
35
}
36