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

EntityReflectionEntry::getTruncateAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
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