Completed
Push — master ( d52ee7...e7842c )
by Alexandr
03:54
created

AutoNameTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 3 Features 0
Metric Value
wmc 5
c 4
b 3
f 0
lcom 1
cbo 0
dl 0
loc 26
rs 10
ccs 13
cts 13
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B getName() 0 21 5
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
11
/**
12
 * Class AutoNameTrait
13
 * @package Youshido\GraphQL\Type\Traits
14
 */
15
trait AutoNameTrait
16
{
17
18 55
    public function getName()
19
    {
20 55
        if (!empty($this->config)) {
21 46
            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...
22
        }
23
24 37
        $className = get_called_class();
25
26 37
        if ($prevPos = strrpos($className, '\\')) {
27 37
            $className = substr($className, $prevPos + 1);
28 37
        }
29
30 37
        if (substr($className, -5) == 'Field') {
31 3
            $className = lcfirst(substr($className, 0, -5));
32 37
        } elseif (substr($className, -4) == 'Type') {
33 34
            $className = substr($className, 0, -4);
34 34
        }
35
36
37 37
        return $className;
38
    }
39
40
}
41