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

ArrayyMeta   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 26.23 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 16
loc 61
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 4 1
B getMetaObject() 16 38 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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