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

AutoNameTrait::getName()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 4
Bugs 3 Features 0
Metric Value
c 4
b 3
f 0
dl 0
loc 21
rs 8.7624
ccs 13
cts 13
cp 1
cc 5
eloc 11
nc 7
nop 0
crap 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