AutoNameTrait::getName()   B
last analyzed

Complexity

Conditions 6
Paths 13

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 16
cts 16
cp 1
rs 8.9137
c 0
b 0
f 0
cc 6
nc 13
nop 0
crap 6
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 5/4/16 9:18 PM
7
*/
8
9
namespace Youshido\GraphQL\Type\Traits;
10
use Youshido\GraphQL\Field\FieldInterface;
11
12
/**
13
 * Class AutoNameTrait
14
 * @package Youshido\GraphQL\Type\Traits
15
 */
16
trait AutoNameTrait
17
{
18
19 107
    public function getName()
20
    {
21 107
        if (!empty($this->config)) {
22 95
            return $this->config->getName();
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
        }
24
25 49
        $className = get_called_class();
26
27 49
        if ($prevPos = strrpos($className, '\\')) {
28 49
            $className = substr($className, $prevPos + 1);
29 49
        }
30 49
        if (substr($className, -5) == 'Field') {
31 4
            $className = lcfirst(substr($className, 0, -5));
32 49
        } elseif (substr($className, -4) == 'Type') {
33 46
            $className = substr($className, 0, -4);
34 46
        }
35
36 49
        if ($this instanceof FieldInterface) {
37 3
            $className = lcfirst($className);
38 3
        }
39
40
41 49
        return $className;
42
    }
43
44
}
45