Passed
Push — test ( 17441c...241ea8 )
by Tom
02:37
created

LabelsBuilder::setProjectDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Runner\Containers;
6
7
use Ktomk\Pipelines\Runner\Runner;
8
use Ktomk\Pipelines\Value\Prefix;
9
10
/**
11
 * Class LabelsBuilder
12
 *
13
 * Build labels for containers
14
 *
15
 * @package Ktomk\Pipelines\Runner\Containers
16
 */
17
class LabelsBuilder
18
{
19
    /**
20
     * @var Runner
21
     */
22
    private $runner;
0 ignored issues
show
introduced by
The private property $runner is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @var string
26
     */
27
    private $prefix;
28
29
    /**
30
     * @var string
31
     */
32
    private $project;
33
34
    /**
35
     * @var string
36
     */
37
    private $projectDirectory;
38
39
    /**
40
     * @var string
41
     */
42
    private $role;
43
44
    /**
45
     * @return self
46
     */
47 2
    public static function createFromRunner(Runner $runner)
48
    {
49 2
        $builder = new self();
50
51
        $builder
52 2
            ->setPrefix($runner->getPrefix())
53 2
            ->setProject($runner->getProject())
54 2
            ->setProjectDirectory($runner->getProjectDirectory());
55
56 2
        return $builder;
57
    }
58
59
    /**
60
     * LabelsBuilder constructor.
61
     */
62 7
    public function __construct()
63
    {
64 7
    }
65
66
    /**
67
     * @param string $role
68
     *
69
     * @return LabelsBuilder
70
     */
71 2
    public function setRole($role)
72
    {
73 2
        $this->role = Role::verify($role);
74
75 2
        return $this;
76
    }
77
78
    /**
79
     * @return string[]
80
     */
81 1
    public function toArray()
82
    {
83 1
        $labels = array();
84
85 1
        $labels['pipelines.prefix'] = $this->prefix;
86 1
        $labels['pipelines.role'] = $this->role;
87 1
        $labels['pipelines.project.name'] = $this->project;
88 1
        $labels['pipelines.project.path'] = $this->projectDirectory;
89
90 1
        return $labels;
91
    }
92
93
    /**
94
     * @param string $prefix
95
     *
96
     * @return LabelsBuilder
97
     */
98 3
    public function setPrefix($prefix)
99
    {
100 3
        $this->prefix = Prefix::verify($prefix);
101
102 3
        return $this;
103
    }
104
105
    /**
106
     * @param string $project
107
     *
108
     * @return LabelsBuilder
109
     */
110 3
    public function setProject($project)
111
    {
112 3
        $this->project = $project;
113
114 3
        return $this;
115
    }
116
117
    /**
118
     * @param string $projectDirectory
119
     *
120
     * @return LabelsBuilder
121
     */
122 3
    public function setProjectDirectory($projectDirectory)
123
    {
124 3
        $this->projectDirectory = $projectDirectory;
125
126 3
        return $this;
127
    }
128
}
129