Test Failed
Push — master ( 4bdf7b...97fe68 )
by Kirill
02:15
created

HasName   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 30
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 8 2
A renameTo() 0 6 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Reflection\Definition\Behaviour;
11
12
use Railt\Reflection\Contracts\Definition\Behaviour\Nameable;
13
14
/**
15
 * Trait HasName
16
 */
17
trait HasName
18
{
19
    /**
20
     * @var string|null
21
     */
22
    protected $name;
23
24
    /**
25
     * @return string
26
     */
27 25
    public function getName(): string
28
    {
29 25
        if ($this->name === null) {
30
            return \spl_object_hash($this) . '@anonymous';
31
        }
32
33 25
        return $this->name;
34
    }
35
36
    /**
37
     * @param string|null $name
38
     * @return Nameable|$this
39
     */
40 17
    public function renameTo(?string $name): Nameable
41
    {
42 17
        $this->name = $name;
43
44 17
        return $this;
45
    }
46
}
47