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

HasName::renameTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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