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

Utils   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 27
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOperatorTypeName() 0 3 1
A getTypeName() 0 5 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