Passed
Push — master ( 8387eb...5a11dc )
by Janko
07:59
created

EntityReflectionEntry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getClassName() 0 3 1
A getTruncateAttribute() 0 5 2
A __construct() 0 4 1
A hasTruncationAttribute() 0 3 1
A getPriority() 0 3 1
A getShortName() 0 3 1
1
<?php
2
3
namespace Stu\Component\Admin\Reset;
4
5
use ReflectionAttribute;
6
use ReflectionClass;
7
use Stu\Orm\Attribute\TruncateOnGameReset;
8
9
class EntityReflectionEntry
10
{
11
    /**
12
     * @param ReflectionClass<object> $reflectionClass
13
     */
14 1
    public function __construct(
15
        private readonly string $className,
16
        private readonly ReflectionClass $reflectionClass
17 1
    ) {}
18
19 1
    public function getClassName(): string
20
    {
21 1
        return $this->className;
22
    }
23
24 1
    public function getShortName(): string
25
    {
26 1
        return $this->reflectionClass->getShortName();
27
    }
28
29 1
    public function hasTruncationAttribute(): bool
30
    {
31 1
        return $this->getTruncateAttribute() !== null;
32
    }
33
34 1
    public function getPriority(): int
35
    {
36 1
        return $this->getTruncateAttribute()?->newInstance()->priority ?? 0;
37
    }
38
39
    /** @return ReflectionAttribute<TruncateOnGameReset> */
40 1
    private function getTruncateAttribute(): ?ReflectionAttribute
41
    {
42 1
        $attribute = current($this->reflectionClass->getAttributes(TruncateOnGameReset::class));
43
44 1
        return $attribute === false ? null : $attribute;
45
    }
46
}
47