Passed
Push — master ( 26e86a...9b47e1 )
by Tom
03:10
created

LabelsBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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