AutoNameTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0
ccs 16
cts 16
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B getName() 0 24 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