Completed
Push — master ( e19d42...40ae98 )
by Lars
01:42
created

ArrayyMeta::getMetaObject()   B

Complexity

Conditions 7
Paths 10

Size

Total Lines 38

Duplication

Lines 16
Ratio 42.11 %

Code Coverage

Tests 22
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
nc 10
nop 1
dl 16
loc 38
ccs 22
cts 22
cp 1
crap 7
rs 8.3786
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 $className
24
     *
25
     * @return $this
26
     *
27
     * @psalm-param class-string<\Arrayy\Arrayy<int|string,mixed>> $className
28
     */
29 17
    public function getMetaObject(string $className): self
30
    {
31 17
        static $STATIC_CACHE = [];
32
33 17
        $cacheKey = $className;
34 17
        if (!empty($STATIC_CACHE[$cacheKey])) {
35 15
            return $STATIC_CACHE[$cacheKey];
36
        }
37
38 3
        $reflector = new \ReflectionClass($className);
39 3
        $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
40 3
        $docComment = $reflector->getDocComment();
41 3 View Code Duplication
        if ($docComment) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42 3
            $docblock = $factory->create($docComment);
43
            /** @var \phpDocumentor\Reflection\DocBlock\Tags\Property $tag */
44 3
            foreach ($docblock->getTagsByName('property') as $tag) {
45 3
                $PropertyName = $tag->getVariableName();
46 3
                $this->{$PropertyName} = $PropertyName;
47
            }
48
        }
49
50
        /** @noinspection PhpAssignmentInConditionInspection */
51 3
        while ($reflector = $reflector->getParentClass()) {
52 3
            $docComment = $reflector->getDocComment();
53 3 View Code Duplication
            if ($docComment) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54 3
                $docblock = $factory->create($docComment);
55
                /** @var \phpDocumentor\Reflection\DocBlock\Tags\Property $tag */
56 3
                foreach ($docblock->getTagsByName('property') as $tag) {
57 1
                    $PropertyName = $tag->getVariableName();
58 1
                    $this->{$PropertyName} = $PropertyName;
59
                }
60
            }
61
        }
62
63 3
        $STATIC_CACHE[$cacheKey] = $this;
64
65 3
        return $this;
66
    }
67
}
68