Passed
Pull Request — master (#36)
by Andrey
02:58
created

DefinitionAwareTrait::getTypeName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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