Job   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 175
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
lcom 2
cbo 0
dl 0
loc 175
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A getName() 0 4 1
A getRepository() 0 4 1
A getTag() 0 4 1
A addService() 0 4 1
A getServices() 0 4 1
A getDirectory() 0 4 1
A getDescription() 0 4 1
A getStrategy() 0 4 1
A getUniq() 0 4 1
A getParameters() 0 4 1
A getCreated() 0 4 1
A __toString() 0 4 1
1
<?php
2
/*
3
 * This file is part of JoliCi.
4
*
5
* (c) Joel Wurtz <[email protected]>
6
*
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
9
*/
10
11
namespace Joli\JoliCi;
12
13
class Job
14
{
15
    const BASE_NAME = 'jolici';
16
17
    /**
18
     * @var string Name of job
19
     */
20
    protected $project;
21
22
    /**
23
     * @var string Strategy associated with this job
24
     */
25
    protected $strategy;
26
27
    /**
28
     * @var string Uniq key for this "kind" of job
29
     *
30
     * This key is not a identifier (the name is the identifier in a job), it's more like a category,
31
     * job with same parameters MUST have the same uniq key, this key is use to track the history
32
     * of a job over time (for cleaning, reports, etc ....)
33
     */
34
    protected $uniq;
35
36
    /**
37
     * @var array Parameters of this job
38
     *
39
     * It mainly depend on the strategy, ie for TravisCi strategy this will include the language used, version used, etc ...
40
     */
41
    protected $parameters;
42
43
    /**
44
     * @var string Description of this job (generally a nice name for end user)
45
     */
46
    protected $description;
47
48
    /**
49
     * @var \DateTime Date of creation of the job
50
     */
51
    protected $created;
52
53
    /**
54
     * @var Service[] Services linked to this job
55
     */
56
    private $services = array();
57
58
    /**
59
     * @param string    $project     Project of the job
60
     * @param string    $strategy    Strategy of the job
61
     * @param string    $uniq        A uniq identifier for this kind of job
62
     * @param array     $parameters  Parameters of the job (mainly depend on the strategy)
63
     * @param string    $description Description of this job (generally a nice name for end user)
64
     * @param \DateTime $created     Date of creation of the job
65
     * @param array $services Services linked to the job
66
     */
67
    public function __construct($project, $strategy, $uniq, $parameters = array(), $description = "", $created = null, $services = array())
68
    {
69
        $this->project     = $project;
70
        $this->description = $description;
71
        $this->strategy    = $strategy;
72
        $this->parameters  = $parameters;
73
        $this->uniq        = $uniq;
74
75
        if (null === $created) {
76
            $created = new \DateTime();
77
        }
78
79
        $this->created = $created;
80
        $this->services = $services;
81
    }
82
83
    /**
84
     * Get name of this job
85
     *
86
     * @return string
87
     */
88
    public function getName()
89
    {
90
        return sprintf('%s:%s', $this->getRepository(), $this->getTag());
91
    }
92
93
    /**
94
     * Get repository name for docker images job with this strategy
95
     *
96
     * @return string
97
     */
98
    public function getRepository()
99
    {
100
        return sprintf('%s_%s/%s', static::BASE_NAME, strtolower($this->strategy), $this->project);
101
    }
102
103
    /**
104
     * Generate the tag name for a docker image
105
     *
106
     * @return string
107
     */
108
    public function getTag()
109
    {
110
        return sprintf('%s-%s', $this->uniq, $this->created->format('U'));
111
    }
112
113
    /**
114
     * Add a service to the job
115
     *
116
     * @param Service $service
117
     */
118
    public function addService(Service $service)
119
    {
120
        $this->services[] = $service;
121
    }
122
123
    /**
124
     * Return all services linked to this job
125
     *
126
     * @return Service[]
127
     */
128
    public function getServices()
129
    {
130
        return $this->services;
131
    }
132
133
    /**
134
     * Return directory of job
135
     *
136
     * @return string
137
     */
138
    public function getDirectory()
139
    {
140
        return $this->getName();
141
    }
142
143
    /**
144
     * @return string
145
     */
146
    public function getDescription()
147
    {
148
        return $this->description;
149
    }
150
151
    /**
152
     * @return string
153
     */
154
    public function getStrategy()
155
    {
156
        return $this->strategy;
157
    }
158
159
    /**
160
     * @return string
161
     */
162
    public function getUniq()
163
    {
164
        return $this->uniq;
165
    }
166
167
    /**
168
     * @return array
169
     */
170
    public function getParameters()
171
    {
172
        return $this->parameters;
173
    }
174
175
    /**
176
     * @return \DateTime
177
     */
178
    public function getCreated()
179
    {
180
        return $this->created;
181
    }
182
183
    public function __toString()
184
    {
185
        return $this->getName();
186
    }
187
}
188