Passed
Push — main ( e5a85d...619edc )
by Michiel
07:04
created

Base   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 15
eloc 23
dl 0
loc 117
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 7 2
A getSecret() 0 7 2
A __isset() 0 3 1
A __get() 0 11 3
A setSecret() 0 7 3
A setKey() 0 7 3
A __set() 0 3 1
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Task\Ext\Amazon;
22
23
use Phing\Exception\BuildException;
24
use Phing\Task;
25
26
/**
27
 * Abstract Service_Amazon class.
28
 *
29
 * Implements common methods & properties used by all Amazon services
30
 *
31
 * @extends  Task
32
 * @version  $ID$
33
 * @package  phing.tasks.ext
34
 * @author   Andrei Serdeliuc <[email protected]>
35
 * @abstract
36
 */
37
abstract class Base extends Task
38
{
39
    /**
40
     * Collection of set options
41
     *
42
     * We set these magically so we can also load then from the environment
43
     *
44
     * (default value: array())
45
     *
46
     * @var array
47
     */
48
    protected $options = [];
49
50
    /**
51
     * @var string
52
     */
53
    protected $key;
54
55
    /**
56
     * @var string
57
     */
58
    protected $secret;
59
60
    /**
61
     * @param string $var
62
     * @param mixed $val
63
     */
64
    public function __set($var, $val)
65
    {
66
        $this->options[$var] = $val;
67
    }
68
69
    /**
70
     * Property getter
71
     *
72
     * If the property hasn't been previously set (through the task call normally),
73
     * it will try to load it from the project
74
     *
75
     * This way, we can define global properties for the "Amazon" service, like key and secret
76
     *
77
     * @param  mixed $var
78
     * @return mixed
79
     */
80
    public function __get($var)
81
    {
82
        if (!isset($this->$var)) {
83
            if (!($val = $this->getProject()->getProperty('amazon.' . strtolower($var)))) {
84
                return false;
85
            }
86
87
            return $val;
88
        }
89
90
        return $this->options[$var];
91
    }
92
93
    /**
94
     * @param string $var
95
     * @return bool
96
     */
97
    public function __isset($var)
98
    {
99
        return array_key_exists($var, $this->options);
100
    }
101
102
    /**
103
     * @param string $key
104
     * @throws BuildException if $key is an empty string
105
     */
106
    public function setKey($key)
107
    {
108
        if (empty($key) || !is_string($key)) {
109
            throw new BuildException('Key must be a non empty string');
110
        }
111
112
        $this->key = $key;
113
    }
114
115
    /**
116
     * @return string
117
     *
118
     * @throws BuildException if key is not set
119
     */
120
    public function getKey()
121
    {
122
        if (!($key = $this->key)) {
123
            throw new BuildException('Key is not set');
124
        }
125
126
        return $key;
127
    }
128
129
    /**
130
     * @param string $secret
131
     * @throws BuildException if $secret is a empty string
132
     */
133
    public function setSecret($secret)
134
    {
135
        if (empty($secret) || !is_string($secret)) {
136
            throw new BuildException('Secret must be a non empty string');
137
        }
138
139
        $this->secret = $secret;
140
    }
141
142
    /**
143
     * @return string
144
     *
145
     * @throws BuildException if secret is not set
146
     */
147
    public function getSecret()
148
    {
149
        if (!($secret = $this->secret)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $secret is dead and can be removed.
Loading history...
150
            throw new BuildException('Secret is not set');
151
        }
152
153
        return $this->secret;
154
    }
155
}
156