Failed Conditions
Pull Request — master (#10)
by Adrien
02:34
created

Utils::getTypeName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Doctrine;
6
7
use GraphQL\Type\Definition\EnumType;
8
use GraphQL\Type\Definition\LeafType;
9
use GraphQL\Type\Definition\ScalarType;
10
11
/**
12
 * A few utils
13
 */
14
abstract class Utils
15
{
16
    /**
17
     * Get the GraphQL type name for an output type from the PHP class
18
     *
19
     * @param string $className
20
     *
21
     * @return string
22
     */
23 65
    public static function getTypeName(string $className): string
24
    {
25 65
        $parts = explode('\\', $className);
26
27 65
        return end($parts);
28
    }
29
30
    /**
31
     * Get the GraphQL type name for a Filter type from the PHP class
32
     *
33
     * @param string $className
34
     * @param EnumType|ScalarType $type
35
     *
36
     * @return string
37
     */
38 30
    public static function getOperatorTypeName(string $className, LeafType $type): string
39
    {
40 30
        return preg_replace('~Type$~', '', self::getTypeName($className)) . ucfirst($type->name);
1 ignored issue
show
Bug introduced by
Accessing name on the interface GraphQL\Type\Definition\LeafType suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
41
    }
42
}
43