HasName::getName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace ByTIC\Models\SmartProperties\Definitions\Definition;
4
5
/**
6
 * Trait HasName
7
 * @package ByTIC\Models\SmartProperties\Definitions\Traits
8
 */
9
trait HasName
10
{
11
12
    /**
13
     * @var string
14
     */
15
    protected $name = null;
16
17
18
    /**
19
     * @return mixed
20
     */
21
    public function getName(): ?string
22
    {
23
        if ($this->name === null) {
24
            $this->initName();
25
        }
26
27
        return $this->name;
28
    }
29
30
    /**
31
     * @param mixed $name
32
     */
33
    public function setName($name)
34
    {
35
        $this->name = $name;
36
    }
37
38
    protected function initName()
39
    {
40
        $name = $this->getField();
0 ignored issues
show
Bug introduced by
It seems like getField() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        /** @scrutinizer ignore-call */ 
41
        $name = $this->getField();
Loading history...
41
        if (empty($name)) {
42
            return;
43
        }
44
        $name = inflector()->classify($this->getField());
45
        $this->setName($name);
46
    }
47
48
}