DefinitionAwareTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeName() 0 3 1
A getTypeDescription() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Common;
6
7
use Andi\GraphQL\Attribute;
8
use phpDocumentor\Reflection\DocBlockFactory;
9
use ReflectionClass;
10
11
trait DefinitionAwareTrait
12
{
13 13
    private function getTypeName(ReflectionClass $class, Attribute\AbstractType|null $attribute): string
14
    {
15 13
        return $attribute?->name ?? $class->getShortName();
16
    }
17
18 13
    private function getTypeDescription(ReflectionClass $class, ?Attribute\AbstractType $attribute): ?string
19
    {
20 13
        if ($attribute?->description) {
21 5
            return $attribute->description;
22
        }
23
24 8
        if ($docComment = $class->getDocComment()) {
25 7
            return DocBlockFactory::createInstance()->create($docComment)->getSummary() ?: null;
26
        }
27
28 1
        return null;
29
    }
30
}
31