Completed
Push — master ( faecaf...e43139 )
by Siad
15:28
created

Environment   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 57
ccs 15
cts 15
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addVariable() 0 3 1
A getVariables() 0 10 2
A getVariablesObject() 0 3 1
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
/**
21
 * Wrapper for environment variables.
22
 *
23
 * @author  Siad Ardroumli <[email protected]>
24
 * @package phing.types
25
 */
26
class Environment
27
{
28
    /**
29
     * a vector of type Environment.Variable
30
     *
31
     * @see Variable
32
     */
33
    protected $variables;
34
35
    /**
36
     * constructor
37
     */
38 89
    public function __construct()
39
    {
40 89
        $this->variables = new ArrayObject();
41 89
    }
42
43
    /**
44
     * add a variable.
45
     * Validity checking is <i>not</i> performed at this point. Duplicates
46
     * are not caught either.
47
     *
48
     * @param EnvVariable $var new variable.
49
     */
50 1
    public function addVariable(EnvVariable $var)
51
    {
52 1
        $this->variables->append($var);
53 1
    }
54
55
    /**
56
     * get the variable list as an array
57
     *
58
     * @return array of key=value assignment strings
59
     * @throws BuildException if any variable is misconfigured
60
     */
61 2
    public function getVariables()
62
    {
63 2
        if ($this->variables->count() === 0) {
64 1
            return null;
65
        }
66 1
        return array_map(
67
            function ($env) {
68 1
                return $env->getContent();
69 1
            },
70 1
            $this->variables->getArrayCopy()
71
        );
72
    }
73
74
    /**
75
     * Get the raw vector of variables. This is not a clone.
76
     *
77
     * @return ArrayObject a potentially empty (but never null) vector of elements of type
78
     * Variable
79
     */
80 1
    public function getVariablesObject(): \ArrayObject
81
    {
82 1
        return $this->variables;
83
    }
84
}
85