ChainBuildStrategy::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Joli\JoliCi\BuildStrategy;
4
5
use Joli\JoliCi\Job;
6
7
class ChainBuildStrategy implements BuildStrategyInterface
8
{
9
    /**
10
     * @var BuildStrategyInterface[] A list of strategy to use for this builder
11
     */
12
    private $strategies = array();
13
14
    /**
15
     * Add a build strategy to builder
16
     *
17
     * @param BuildStrategyInterface $strategy Strategy to add
18
     */
19
    public function pushStrategy(BuildStrategyInterface $strategy)
20
    {
21
        $this->strategies[$strategy->getName()] = $strategy;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getJobs($directory)
28
    {
29
        $builds = array();
30
31
        foreach ($this->strategies as $strategy) {
32
            if ($strategy->supportProject($directory)) {
33
                $builds += $strategy->getJobs($directory);
34
            }
35
        }
36
37
        return $builds;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function prepareJob(Job $job)
44
    {
45
        $this->strategies[$job->getStrategy()]->prepareJob($job);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getName()
52
    {
53
        return 'Chain';
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function supportProject($directory)
60
    {
61
        foreach ($this->strategies as $strategy) {
62
            if ($strategy->supportProject($directory)) {
63
                return true;
64
            }
65
        }
66
67
        return false;
68
    }
69
}
70