Name::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Spiral Framework. Cycle ProxyFactory
5
 *
6
 * @license MIT
7
 * @author  Valentin V (Vvval)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\ORM\Promise\ConflictResolver;
13
14
final class Name
15
{
16
    /** @var string */
17
    public $name;
18
19
    /** @var int */
20
    public $sequence = 0;
21
22
    /**
23
     * Name constructor.
24
     */
25
    protected function __construct()
26
    {
27
    }
28
29
    /**
30
     * @param string $name
31
     * @param int    $sequence
32
     * @return Name
33
     */
34
    public static function createWithSequence(string $name, int $sequence): Name
35
    {
36
        $self = new self();
37
        $self->name = $name;
38
        $self->sequence = $sequence;
39
40
        return $self;
41
    }
42
43
    /**
44
     * @param string $name
45
     * @return Name
46
     */
47
    public static function create(string $name): Name
48
    {
49
        $self = new self();
50
        $self->name = $name;
51
52
        return $self;
53
    }
54
55
    /**
56
     * @param string|null $delimiter
57
     * @return string
58
     */
59
    public function fullName(string $delimiter = null): string
60
    {
61
        $name = $this->name;
62
        if ($this->sequence > 0) {
63
            if ($delimiter !== null) {
64
                return $name . $delimiter . $this->sequence;
65
            }
66
67
            return $name . $this->sequence;
68
        }
69
70
        return $name;
71
    }
72
}
73