Passed
Push — master ( 383648...c60c96 )
by Andrey
50s queued 13s
created

DefinitionAwareTrait   A

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 12
    private function getTypeName(ReflectionClass $class, Attribute\AbstractType|null $attribute): string
14
    {
15 12
        return $attribute?->name ?? $class->getShortName();
16
    }
17
18 12
    private function getTypeDescription(ReflectionClass $class, ?Attribute\AbstractType $attribute): ?string
19
    {
20 12
        if ($attribute?->description) {
21 5
            return $attribute->description;
22
        }
23
24 7
        if ($docComment = $class->getDocComment()) {
25 6
            return DocBlockFactory::createInstance()->create($docComment)->getSummary() ?: null;
26
        }
27
28 1
        return null;
29
    }
30
}
31