Passed
Push — master ( 800fb3...1ce7d0 )
by Tom
04:22
created

LabelsBuilder::setPrefix()   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 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
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 string
21
     */
22
    private $prefix;
23
24
    /**
25
     * @var string
26
     */
27
    private $project;
28
29
    /**
30
     * @var string
31
     */
32
    private $projectDirectory;
33
34
    /**
35
     * @var string
36
     */
37
    private $role;
38
39
    /**
40
     * @return self
41
     */
42 2
    public static function createFromRunner(Runner $runner)
43
    {
44 2
        $builder = new self();
45
46
        $builder
47 2
            ->setPrefix($runner->getPrefix())
48 2
            ->setProject($runner->getProject())
49 2
            ->setProjectDirectory($runner->getProjectDirectory());
50
51 2
        return $builder;
52
    }
53
54
    /**
55
     * LabelsBuilder constructor.
56
     */
57 7
    public function __construct()
58
    {
59 7
    }
60
61
    /**
62
     * @param string $role
63
     *
64
     * @return LabelsBuilder
65
     */
66 2
    public function setRole($role)
67
    {
68 2
        $this->role = Role::verify($role);
69
70 2
        return $this;
71
    }
72
73
    /**
74
     * @return string[]
75
     */
76 1
    public function toArray()
77
    {
78 1
        $labels = array();
79
80 1
        $labels['pipelines.prefix'] = $this->prefix;
81 1
        $labels['pipelines.role'] = $this->role;
82 1
        $labels['pipelines.project.name'] = $this->project;
83 1
        $labels['pipelines.project.path'] = $this->projectDirectory;
84
85 1
        return $labels;
86
    }
87
88
    /**
89
     * @param string $prefix
90
     *
91
     * @return LabelsBuilder
92
     */
93 3
    public function setPrefix($prefix)
94
    {
95 3
        $this->prefix = Prefix::verify($prefix);
96
97 3
        return $this;
98
    }
99
100
    /**
101
     * @param string $project
102
     *
103
     * @return LabelsBuilder
104
     */
105 3
    public function setProject($project)
106
    {
107 3
        $this->project = $project;
108
109 3
        return $this;
110
    }
111
112
    /**
113
     * @param string $projectDirectory
114
     *
115
     * @return LabelsBuilder
116
     */
117 3
    public function setProjectDirectory($projectDirectory)
118
    {
119 3
        $this->projectDirectory = $projectDirectory;
120
121 3
        return $this;
122
    }
123
}
124