@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | * @param array $options |
50 | 50 | */ |
51 | 51 | |
52 | - public function __construct(string $name, string $flag=null, bool $required=FALSE, $default=null, string $description=null, array $options=array()) |
|
52 | + public function __construct(string $name, string $flag = null, bool $required = FALSE, $default = null, string $description = null, array $options = array()) |
|
53 | 53 | { |
54 | 54 | |
55 | 55 | // Required a non-empty 'options' |
56 | - if( count($options) < 1 ) |
|
56 | + if (count($options)<1) |
|
57 | 57 | { |
58 | 58 | throw(new ArghException('CommandParameter must have options')); |
59 | 59 | } |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function setValue($value) |
89 | 89 | { |
90 | - if(is_array($value)) |
|
90 | + if (is_array($value)) |
|
91 | 91 | { |
92 | 92 | throw(new ArghException('Command value cannot be set to an array')); |
93 | 93 | } |
94 | 94 | |
95 | - if( ($this->hasOptions()) && (!$this->isOption($value)) ) |
|
95 | + if (($this->hasOptions()) && (!$this->isOption($value))) |
|
96 | 96 | { |
97 | 97 | throw(new ArghException('Not a valid option for \'' . $this->getName() . '\'')); |
98 | 98 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | */ |
58 | 58 | public function setValue($value) |
59 | 59 | { |
60 | - if(is_array($value)) |
|
60 | + if (is_array($value)) |
|
61 | 61 | { |
62 | 62 | throw(new ArghException('StringParameter values cannot be set to an array')); |
63 | 63 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public static function process(array $argv) |
36 | 36 | { |
37 | - if(count($argv) < 1) |
|
37 | + if (count($argv)<1) |
|
38 | 38 | { |
39 | 39 | throw(new ArghException(__CLASS__ . ': $argv is empty')); |
40 | 40 | } |
@@ -49,32 +49,32 @@ discard block |
||
49 | 49 | // Lists |
50 | 50 | // |
51 | 51 | |
52 | - for($i=0; $i<count($args); $i++) |
|
52 | + for ($i = 0; $i<count($args); $i++) |
|
53 | 53 | { |
54 | 54 | // Lists begin with an opening bracket '[' |
55 | - if( strpos($args[$i], '[') !== FALSE ) |
|
55 | + if (strpos($args[$i], '[') !== FALSE) |
|
56 | 56 | { |
57 | 57 | // Found the beginning of a list at $i |
58 | 58 | //echo "DEBUG: Found beginning of a list at $i\n"; |
59 | 59 | |
60 | 60 | // Search for the end of the list; starting at the current element |
61 | - for($j=$i; $j<count($args); $j++) |
|
61 | + for ($j = $i; $j<count($args); $j++) |
|
62 | 62 | { |
63 | - if( strpos($args[$j], ']') !== FALSE ) |
|
63 | + if (strpos($args[$j], ']') !== FALSE) |
|
64 | 64 | { |
65 | 65 | // Found the end of a list at $j |
66 | 66 | //echo "DEBUG: Found end of a list at $j\n"; |
67 | 67 | |
68 | - if($j != $i) |
|
68 | + if ($j != $i) |
|
69 | 69 | { |
70 | 70 | // List does NOT open and close in the same element; elements must be re-combined |
71 | 71 | |
72 | 72 | // List closing bracket should always be the last character of the element |
73 | - if( strpos($args[$j], ']') == (strlen($args[$j])-1) ) |
|
73 | + if (strpos($args[$j], ']') == (strlen($args[$j])-1)) |
|
74 | 74 | { |
75 | 75 | // Create a new string for $args $i thru $j |
76 | 76 | $list = ""; |
77 | - for($k=$i; $k<=$j; $k++) $list .= $args[$k]; |
|
77 | + for ($k = $i; $k<=$j; $k++) $list .= $args[$k]; |
|
78 | 78 | |
79 | 79 | //echo "DEBUG: Replace elements $i thru $j with: $list\n"; |
80 | 80 | |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | // |
109 | 109 | |
110 | 110 | // Check for arguments with spaces, these were originally quoted on the command line |
111 | - for($i=0; $i<count($args); $i++) |
|
111 | + for ($i = 0; $i<count($args); $i++) |
|
112 | 112 | { |
113 | - if( strpos($args[$i], ' ') !== FALSE ) |
|
113 | + if (strpos($args[$i], ' ') !== FALSE) |
|
114 | 114 | { |
115 | 115 | |
116 | 116 | // Check if argument is a list |
117 | - if( strpos($args[$i], '[') !== FALSE ) |
|
117 | + if (strpos($args[$i], '[') !== FALSE) |
|
118 | 118 | { |
119 | 119 | |
120 | 120 | // |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | //!TODO: handle --msg="Hello World"; We don't want "--msg=Hello World" |
129 | 129 | //! TODO: FIX. THIS IS BROKEN |
130 | 130 | |
131 | - if( strpos($args[$i], '=') === FALSE ) |
|
131 | + if (strpos($args[$i], '=') === FALSE) |
|
132 | 132 | { |
133 | 133 | // Wrap (space containing) argument in quotes |
134 | 134 | $args[$i] = "'" . $args[$i] . "'"; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function exists(string $key): bool |
85 | 85 | { |
86 | - if( array_key_exists($key, $this->map) ) |
|
86 | + if (array_key_exists($key, $this->map)) |
|
87 | 87 | { |
88 | 88 | return true; |
89 | 89 | } |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function hasCommand(): bool |
102 | 102 | { |
103 | - foreach($this->parameters as $p) |
|
103 | + foreach ($this->parameters as $p) |
|
104 | 104 | { |
105 | - if( Parameter::ARGH_TYPE_COMMAND == $p->getParameterType() ) |
|
105 | + if (Parameter::ARGH_TYPE_COMMAND == $p->getParameterType()) |
|
106 | 106 | { |
107 | 107 | return true; |
108 | 108 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function hasVariable(): bool |
121 | 121 | { |
122 | - foreach($this->parameters as $p) |
|
122 | + foreach ($this->parameters as $p) |
|
123 | 123 | { |
124 | - if( Parameter::ARGH_TYPE_VARIABLE == $p->getParameterType() ) |
|
124 | + if (Parameter::ARGH_TYPE_VARIABLE == $p->getParameterType()) |
|
125 | 125 | { |
126 | 126 | return true; |
127 | 127 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function get(string $key): Parameter |
143 | 143 | { |
144 | - if($this->exists($key)) |
|
144 | + if ($this->exists($key)) |
|
145 | 145 | { |
146 | 146 | $index = $this->map[$key]; |
147 | 147 | |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | { |
168 | 168 | $commands = array(); |
169 | 169 | |
170 | - foreach($this->parameters as $p) |
|
170 | + foreach ($this->parameters as $p) |
|
171 | 171 | { |
172 | - if( Parameter::ARGH_TYPE_COMMAND == $p->getParameterType() ) |
|
172 | + if (Parameter::ARGH_TYPE_COMMAND == $p->getParameterType()) |
|
173 | 173 | { |
174 | 174 | $commands[] = $p; |
175 | 175 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function addParameter(Parameter $param) |
191 | 191 | { |
192 | - if( !$this->exists($param->getName()) ) |
|
192 | + if (!$this->exists($param->getName())) |
|
193 | 193 | { |
194 | 194 | // Add $param to $parameters array |
195 | 195 | $this->parameters[] = $param; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $this->map[$param->getName()] = count($this->parameters)-1; |
199 | 199 | |
200 | 200 | // Map the new parameter's 'flag' to its corresponding index in the $parameters array |
201 | - if(!empty($param->getFlag())) $this->map[$param->getFlag()] = count($this->parameters)-1; |
|
201 | + if (!empty($param->getFlag())) $this->map[$param->getFlag()] = count($this->parameters)-1; |
|
202 | 202 | } |
203 | 203 | else |
204 | 204 | { |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | public function mergeArguments(array $arguments): void |
220 | 220 | { |
221 | 221 | |
222 | - foreach($arguments as $a) |
|
222 | + foreach ($arguments as $a) |
|
223 | 223 | { |
224 | 224 | // Check for a Parameter with this Arguments key |
225 | - if( $this->exists($a->getKey()) ) |
|
225 | + if ($this->exists($a->getKey())) |
|
226 | 226 | { |
227 | 227 | // Enforce limitations of Parameters |
228 | 228 | // 1. Do NOT allow value to be redefined |
229 | 229 | // 2. ARGH_TYPE_VARIABLE (VariableParameter) can have values appended |
230 | 230 | |
231 | - if( Parameter::ARGH_TYPE_VARIABLE == $this->parameters[$this->map[$a->getKey()]]->getParameterType() ) |
|
231 | + if (Parameter::ARGH_TYPE_VARIABLE == $this->parameters[$this->map[$a->getKey()]]->getParameterType()) |
|
232 | 232 | { |
233 | 233 | // Call VariableParameters::addValue() method |
234 | 234 | $this->parameters[$this->map[$a->getKey()]]->addValue($a->getValue()); |
235 | 235 | } |
236 | - else if( null !== $this->parameters[$this->map[$a->getKey()]]->getValue() ) |
|
236 | + else if (null !== $this->parameters[$this->map[$a->getKey()]]->getValue()) |
|
237 | 237 | { |
238 | 238 | // |
239 | 239 | // Do NOT allow a Parameter's value to be redefined |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | } // END: foreach($arguments as $a) |
256 | 256 | |
257 | 257 | // Check for REQUIRED Parameters without any value |
258 | - foreach($this->parameters as $p) |
|
258 | + foreach ($this->parameters as $p) |
|
259 | 259 | { |
260 | - if( ($p->isRequired() ) && (null == $p->getValue()) ) |
|
260 | + if (($p->isRequired()) && (null == $p->getValue())) |
|
261 | 261 | { |
262 | - throw(new ArghException(__CLASS__ . ': Missing required parameter \'' . $p->getName() . '\'.')); |
|
262 | + throw(new ArghException(__CLASS__ . ': Missing required parameter \'' . $p->getName() . '\'.')); |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | // Parameter Data Types |
32 | 32 | const ARGH_TYPE_BOOLEAN = 1; |
33 | 33 | const ARGH_TYPE_INT = 2; |
34 | - const ARGH_TYPE_STRING = 3; |
|
34 | + const ARGH_TYPE_STRING = 3; |
|
35 | 35 | const ARGH_TYPE_LIST = 4; |
36 | 36 | const ARGH_TYPE_COMMAND = 5; |
37 | 37 | const ARGH_TYPE_VARIABLE = 6; |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | $options = array(); |
98 | 98 | |
99 | 99 | // Extract parameter attributes from array |
100 | - if( array_key_exists('name', $attributes) ) $name = $attributes['name']; |
|
101 | - if( array_key_exists('flag', $attributes) ) $flag = $attributes['flag']; |
|
102 | - if( array_key_exists('required', $attributes) ) $required = $attributes['required']; |
|
103 | - if( array_key_exists('default', $attributes) ) $default = $attributes['default']; |
|
104 | - if( array_key_exists('description', $attributes) ) $description = $attributes['description']; |
|
105 | - if( array_key_exists('options', $attributes) ) $options = $attributes['options']; |
|
100 | + if (array_key_exists('name', $attributes)) $name = $attributes['name']; |
|
101 | + if (array_key_exists('flag', $attributes)) $flag = $attributes['flag']; |
|
102 | + if (array_key_exists('required', $attributes)) $required = $attributes['required']; |
|
103 | + if (array_key_exists('default', $attributes)) $default = $attributes['default']; |
|
104 | + if (array_key_exists('description', $attributes)) $description = $attributes['description']; |
|
105 | + if (array_key_exists('options', $attributes)) $options = $attributes['options']; |
|
106 | 106 | |
107 | 107 | // Construct a new Parameter instance |
108 | 108 | // Late static binding results in new instance of (calling) subclass |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | * @return Parameter |
135 | 135 | * @throws ArghException |
136 | 136 | */ |
137 | - public function __construct(string $name, string $flag=null, bool $required=FALSE, $default=null, string $description=null, array $options=array()) |
|
137 | + public function __construct(string $name, string $flag = null, bool $required = FALSE, $default = null, string $description = null, array $options = array()) |
|
138 | 138 | { |
139 | 139 | // Required a non-empty 'name' |
140 | - if(empty($name)) |
|
140 | + if (empty($name)) |
|
141 | 141 | { |
142 | 142 | throw(new ArghException('Parameter must have a name')); |
143 | 143 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public function hasOptions(): bool |
223 | 223 | { |
224 | - if(count($this->options) > 0) |
|
224 | + if (count($this->options)>0) |
|
225 | 225 | { |
226 | 226 | return TRUE; |
227 | 227 | } |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | */ |
243 | 243 | public function isOption($value): bool |
244 | 244 | { |
245 | - if( in_array($value, $this->options) ) |
|
245 | + if (in_array($value, $this->options)) |
|
246 | 246 | { |
247 | 247 | return TRUE; |
248 | 248 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | { |
46 | 46 | // Interpret any non-empty value as TRUE |
47 | 47 | // Note that FALSE is considered to be empty() |
48 | - if( !empty( parent::getDefault() ) ) |
|
48 | + if (!empty(parent::getDefault())) |
|
49 | 49 | { |
50 | 50 | return TRUE; |
51 | 51 | } |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | public function setValue($value) |
80 | 80 | { |
81 | 81 | |
82 | - if( null === $value ) |
|
82 | + if (null === $value) |
|
83 | 83 | { |
84 | 84 | // null (no value) considered TRUE (this is how flags work; e.g. the presence of a boolean flag -x without value means TRUE) |
85 | 85 | $this->value = TRUE; |
86 | 86 | } |
87 | - else if( FALSE == $value ) |
|
87 | + else if (FALSE == $value) |
|
88 | 88 | { |
89 | 89 | // 'Falsey' (boolean) FALSE, (int) 0, (float 0.0), (string) '0', (string) '', NULL |
90 | 90 | $this->value = FALSE; |
91 | 91 | } |
92 | - else if( in_array($value, array('0', 'false', 'False', 'FALSE', 'off', 'Off', 'OFF')) ) |
|
92 | + else if (in_array($value, array('0', 'false', 'False', 'FALSE', 'off', 'Off', 'OFF'))) |
|
93 | 93 | { |
94 | 94 | // Certain character values should be considered to mean FALSE |
95 | 95 | $this->value = FALSE; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function setValue($value) |
57 | 57 | { |
58 | - if(is_array($value)) |
|
58 | + if (is_array($value)) |
|
59 | 59 | { |
60 | 60 | $this->value = $value; |
61 | 61 | } |
@@ -77,14 +77,14 @@ discard block |
||
77 | 77 | public function addValue($value) |
78 | 78 | { |
79 | 79 | // Check if this Parameter has a previously set value |
80 | - if($this->value === null) |
|
80 | + if ($this->value === null) |
|
81 | 81 | { |
82 | 82 | // Initialize this Parameters value to a new array |
83 | 83 | $this->value = array(); |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Check if the new value is an array |
87 | - if(!is_array($value)) |
|
87 | + if (!is_array($value)) |
|
88 | 88 | { |
89 | 89 | // Append new single value to this Parameters value array |
90 | 90 | $this->value[] = $value; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | else |
93 | 93 | { |
94 | 94 | // Append every new value to this Parameters value array |
95 | - foreach($value as $v) $this->value[] = $v; |
|
95 | + foreach ($value as $v) $this->value[] = $v; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @since 1.0.0 |
42 | 42 | */ |
43 | - public function __construct($key=null, $value=null) |
|
43 | + public function __construct($key = null, $value = null) |
|
44 | 44 | { |
45 | 45 | $this->key = $key; |
46 | 46 | $this->value = $value; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function isArray() |
107 | 107 | { |
108 | - if( is_array($this->value) ) |
|
108 | + if (is_array($this->value)) |
|
109 | 109 | { |
110 | 110 | return TRUE; |
111 | 111 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | */ |
56 | 56 | public function setValue($value) |
57 | 57 | { |
58 | - if(!is_numeric($value)) |
|
58 | + if (!is_numeric($value)) |
|
59 | 59 | { |
60 | 60 | throw(new ArghException('IntegerParameter values must be numeric')); |
61 | 61 | } |