Completed
Push — master ( 328402...1cd18c )
by Julien
587:13 queued 584:54
created

Environments::getTestEnvironments()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\Aent\Event\Service\Model;
4
5
use TheAentMachine\Aent\Context\Context;
6
7
final class Environments
8
{
9
    /** @var Context[] */
10
    private $environments;
11
12
    /**
13
     * Environnments constructor.
14
     */
15
    public function __construct()
16
    {
17
        $this->environments = [];
18
    }
19
20
    /**
21
     * @param Context $context
22
     * @return void
23
     */
24
    public function add(Context $context): void
25
    {
26
        $this->environments[] = $context;
27
    }
28
29
    /**
30
     * @return bool
31
     */
32
    public function hasDevelopmentEnvironments(): bool
33
    {
34
        foreach ($this->environments as $environment) {
35
            if ($environment->isDevelopment()) {
36
                return true;
37
            }
38
        }
39
        return false;
40
    }
41
42
    /**
43
     * @return bool
44
     */
45
    public function hasTestEnvironments(): bool
46
    {
47
        foreach ($this->environments as $environment) {
48
            if ($environment->isTest()) {
49
                return true;
50
            }
51
        }
52
        return false;
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    public function hasProductionEnvironments(): bool
59
    {
60
        foreach ($this->environments as $environment) {
61
            if ($environment->isProduction()) {
62
                return true;
63
            }
64
        }
65
        return false;
66
    }
67
68
    /**
69
     * @return Context[]
70
     */
71
    public function getDevelopmentEnvironments(): array
72
    {
73
        $environments = [];
74
        foreach ($this->environments as $environment) {
75
            if ($environment->isDevelopment()) {
76
                $environments[] = $environment;
77
            }
78
        }
79
        return $environments;
80
    }
81
82
    /**
83
     * @return Context[]
84
     */
85
    public function getTestEnvironments(): array
86
    {
87
        $environments = [];
88
        foreach ($this->environments as $environment) {
89
            if ($environment->isTest()) {
90
                $environments[] = $environment;
91
            }
92
        }
93
        return $environments;
94
    }
95
96
    /**
97
     * @return Context[]
98
     */
99
    public function getProductionEnvironments(): array
100
    {
101
        $environments = [];
102
        foreach ($this->environments as $environment) {
103
            if ($environment->isProduction()) {
104
                $environments[] = $environment;
105
            }
106
        }
107
        return $environments;
108
    }
109
110
    /**
111
     * @return bool
112
     */
113
    public function isEmpty(): bool
114
    {
115
        return empty($this->environments);
116
    }
117
}
118