@@ -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 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | // Init an array of Arguments |
69 | 69 | $arguments = array(); |
70 | 70 | |
71 | - if(count($args) == 0) |
|
71 | + if (count($args) == 0) |
|
72 | 72 | { |
73 | 73 | // Nothing to parse |
74 | 74 | return $arguments; |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | // Get all Parameters from ParameterCollection |
81 | 81 | $params = $this->parameterCollection->all(); |
82 | 82 | |
83 | - if( count($rules) == 0 ) |
|
83 | + if (count($rules) == 0) |
|
84 | 84 | { |
85 | 85 | throw new ArghException(__CLASS__ . ': Language needs at least one rule to parse arguments.'); |
86 | 86 | } |
87 | 87 | |
88 | - if( count($params) == 0 ) |
|
88 | + if (count($params) == 0) |
|
89 | 89 | { |
90 | 90 | throw new ArghException(__CLASS__ . ': ParameterCollection needs at least one parameter to parse arguments.'); |
91 | 91 | } |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | // END DEBUG |
145 | 145 | // |
146 | 146 | |
147 | - foreach($rules as $rule) |
|
147 | + foreach ($rules as $rule) |
|
148 | 148 | { |
149 | 149 | //echo "DEBUG: Checking for match with rule: " . $rule->name() . " (" . $rule->syntax() . ")" . "\n"; |
150 | 150 | |
151 | 151 | $tokens = array(); // init array to capture matching tokens from Rule->match() |
152 | 152 | |
153 | - if( $rule->match($argsS, $tokens) ) |
|
153 | + if ($rule->match($argsS, $tokens)) |
|
154 | 154 | { |
155 | 155 | // Count the number of arguments that were matched |
156 | 156 | $count = count($argsL); |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | //echo "* MATCHED $count \$argv elements *\n"; |
159 | 159 | |
160 | 160 | // Empty $argsL; prevent this inner foreach loop from continuing |
161 | - for($i=0; $i<$count; $i++) array_shift($argsL); |
|
161 | + for ($i = 0; $i<$count; $i++) array_shift($argsL); |
|
162 | 162 | |
163 | 163 | // Remove (shift) matching elements from $args |
164 | 164 | // These arguments have been consumed by the parser and are no longer needed |
165 | - for($i=0; $i<$count; $i++) array_shift($args); |
|
165 | + for ($i = 0; $i<$count; $i++) array_shift($args); |
|
166 | 166 | |
167 | 167 | // |
168 | 168 | // Try yielding Arguments from this Rule |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | |
172 | 172 | $yield = $this->yieldArgumentsFromRule($rule, $tokens); |
173 | 173 | |
174 | - if( count($yield) > 0 ) |
|
174 | + if (count($yield)>0) |
|
175 | 175 | { |
176 | 176 | //? TODO: Validate Arguments before adding them to the Arguments array? |
177 | 177 | |
178 | 178 | // Add the new Arguments yielded from this Rule |
179 | - foreach($yield as $y) $arguments[] = $y; |
|
179 | + foreach ($yield as $y) $arguments[] = $y; |
|
180 | 180 | |
181 | 181 | // !IMPORTANT! Stop checking Rules |
182 | 182 | break; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | } // END: foreach($rules as $rule) |
193 | 193 | |
194 | - if( count($tokens) == 0 ) |
|
194 | + if (count($tokens) == 0) |
|
195 | 195 | { |
196 | 196 | // $argsS did NOT match any rules |
197 | 197 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | // Prepend popped elemented to beginning of $argsR |
202 | 202 | array_unshift($argsR, $arg); |
203 | 203 | |
204 | - if( count($argsL) == 0 ) |
|
204 | + if (count($argsL) == 0) |
|
205 | 205 | { |
206 | 206 | // There was no match, and there are no arguments left to pop from $argsL |
207 | 207 | throw new ArghException(__METHOD__ . ': Syntax Error: ' . $argsS); |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | } // END: if( count($tokens) == 0 ) |
211 | 211 | |
212 | 212 | } // END do |
213 | - while( count($argsL) > 0 ); |
|
213 | + while (count($argsL)>0); |
|
214 | 214 | |
215 | 215 | } // END: do |
216 | - while( count($args) > 0 ); |
|
216 | + while (count($args)>0); |
|
217 | 217 | |
218 | 218 | // Return Arguments array |
219 | 219 | return $arguments; |
@@ -246,21 +246,21 @@ discard block |
||
246 | 246 | $argument = array(); |
247 | 247 | |
248 | 248 | // Loop through $tokens and define Argument(s) based on the current rules semantics |
249 | - for($i=1; $i<count($tokens); $i++) |
|
249 | + for ($i = 1; $i<count($tokens); $i++) |
|
250 | 250 | { |
251 | 251 | $token = $tokens[$i]; |
252 | 252 | $semantics = $rule->semantics()[$i-1]; |
253 | 253 | |
254 | 254 | //echo __METHOD__ . ": token: $token (" . Rule::semanticsToString($semantics) . ")\n"; |
255 | 255 | |
256 | - switch( $semantics ) |
|
256 | + switch ($semantics) |
|
257 | 257 | { |
258 | 258 | case ARGH_SEMANTICS_FLAG: |
259 | 259 | |
260 | - if( $this->parameterCollection->exists($token) ) |
|
260 | + if ($this->parameterCollection->exists($token)) |
|
261 | 261 | { |
262 | 262 | // This Rule will create a single Argument |
263 | - if(count($argument)==0) $argument[0] = new Argument($token); |
|
263 | + if (count($argument) == 0) $argument[0] = new Argument($token); |
|
264 | 264 | } |
265 | 265 | else |
266 | 266 | { |
@@ -274,15 +274,15 @@ discard block |
||
274 | 274 | case ARGH_SEMANTICS_FLAGS: |
275 | 275 | |
276 | 276 | // Check every character of this $token for a matching parameter 'flag' |
277 | - for($j=0; $j<strlen($token); $j++) |
|
277 | + for ($j = 0; $j<strlen($token); $j++) |
|
278 | 278 | { |
279 | - if( $this->parameterCollection->exists( $token{$j} ) ) |
|
279 | + if ($this->parameterCollection->exists($token{$j} )) |
|
280 | 280 | { |
281 | 281 | // This Rule can only apply to ARGH_TYPE_BOOLEAN Parameters |
282 | - if( ARGH_TYPE_BOOLEAN == $this->parameterCollection->get($token{$j})->getParameterType() ) |
|
282 | + if (ARGH_TYPE_BOOLEAN == $this->parameterCollection->get($token{$j})->getParameterType()) |
|
283 | 283 | { |
284 | 284 | // Create new Argument for each flag |
285 | - if( !array_key_exists($j, $argument) ) $argument[$j] = new Argument($token{$j}); |
|
285 | + if (!array_key_exists($j, $argument)) $argument[$j] = new Argument($token{$j}); |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | else |
@@ -301,10 +301,10 @@ discard block |
||
301 | 301 | |
302 | 302 | case ARGH_SEMANTICS_NAME: |
303 | 303 | |
304 | - if( $this->parameterCollection->exists($token) ) |
|
304 | + if ($this->parameterCollection->exists($token)) |
|
305 | 305 | { |
306 | 306 | // This Rule will create a single Argument |
307 | - if(count($argument)==0) $argument[0] = new Argument($token); |
|
307 | + if (count($argument) == 0) $argument[0] = new Argument($token); |
|
308 | 308 | } |
309 | 309 | else |
310 | 310 | { |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | // Usually, the Argument will have already been created by another token in this Rule |
321 | 321 | |
322 | 322 | // If no new Argument created by this Rule yet, create one now |
323 | - if(count($argument)==0) $argument[0] = new Argument(); |
|
323 | + if (count($argument) == 0) $argument[0] = new Argument(); |
|
324 | 324 | |
325 | 325 | // The new Argument's 'key' should be set by another token in this Rule |
326 | 326 | $argument[0]->setValue($token); |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | // Usually, the Argument will have already been created by another token in this Rule |
333 | 333 | |
334 | 334 | // If no new Argument created by this Rule yet, create one now |
335 | - if(count($argument)==0) $argument[0] = new Argument(); |
|
335 | + if (count($argument) == 0) $argument[0] = new Argument(); |
|
336 | 336 | |
337 | 337 | // Trim brackets from the $token (list) |
338 | 338 | $token = trim($token, "[]"); |
@@ -342,28 +342,28 @@ discard block |
||
342 | 342 | |
343 | 343 | // Use the $elements array as the 'value' for all new Argument created by this Rule |
344 | 344 | // Usually, this will only apply to a single Argument, unless this Rule contains ARGH_SEMANTICS_FLAGS |
345 | - foreach($argument as &$a) $a->setValue($elements); |
|
345 | + foreach ($argument as &$a) $a->setValue($elements); |
|
346 | 346 | |
347 | 347 | break; |
348 | 348 | |
349 | 349 | case ARGH_SEMANTICS_COMMAND: |
350 | 350 | |
351 | 351 | // Check if ParameterCollection contains any commands |
352 | - if($this->parameterCollection->hasCommand()) |
|
352 | + if ($this->parameterCollection->hasCommand()) |
|
353 | 353 | { |
354 | 354 | // Retrieve all ARGH_TYPE_COMMAND Parameters |
355 | 355 | $commands = $this->parameterCollection->getCommands(); |
356 | 356 | |
357 | - foreach($commands as $p) |
|
357 | + foreach ($commands as $p) |
|
358 | 358 | { |
359 | - if($p->hasOptions()) |
|
359 | + if ($p->hasOptions()) |
|
360 | 360 | { |
361 | - if( in_array($token, $p->getOptions()) ) |
|
361 | + if (in_array($token, $p->getOptions())) |
|
362 | 362 | { |
363 | 363 | // $token matches an option of this ARGH_TYPE_COMMAND Parameter |
364 | 364 | |
365 | 365 | // If no new Argument created by this Rule yet, create one now |
366 | - if(count($argument)==0) $argument[0] = new Argument($p->getName(), $token); |
|
366 | + if (count($argument) == 0) $argument[0] = new Argument($p->getName(), $token); |
|
367 | 367 | |
368 | 368 | // Stop searching this Parameters options |
369 | 369 | break; |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | const ARGH_SEMANTICS_NAME = 3; |
41 | 41 | const ARGH_SEMANTICS_VALUE = 4; |
42 | 42 | const ARGH_SEMANTICS_LIST = 5; |
43 | - const ARGH_SEMANTICS_COMMAND = 6; |
|
44 | - const ARGH_SEMANTICS_VARIABLE = 7; |
|
43 | + const ARGH_SEMANTICS_COMMAND = 6; |
|
44 | + const ARGH_SEMANTICS_VARIABLE = 7; |
|
45 | 45 | |
46 | 46 | // |
47 | 47 | // PUBLIC PROPERTIES |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | $syntax = null; |
81 | 81 | $semantics = null; |
82 | 82 | |
83 | - if( array_key_exists('name', $attributes) ) $name = $attributes['name']; |
|
84 | - if( array_key_exists('example', $attributes) ) $example = $attributes['example']; |
|
85 | - if( array_key_exists('syntax', $attributes) ) $syntax = $attributes['syntax']; |
|
86 | - if( array_key_exists('semantics', $attributes) ) $semantics = $attributes['semantics']; |
|
83 | + if (array_key_exists('name', $attributes)) $name = $attributes['name']; |
|
84 | + if (array_key_exists('example', $attributes)) $example = $attributes['example']; |
|
85 | + if (array_key_exists('syntax', $attributes)) $syntax = $attributes['syntax']; |
|
86 | + if (array_key_exists('semantics', $attributes)) $semantics = $attributes['semantics']; |
|
87 | 87 | |
88 | 88 | return new self($name, $example, $syntax, $semantics); |
89 | 89 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public static function semanticsToString(int $semantics) |
102 | 102 | { |
103 | - switch($semantics) |
|
103 | + switch ($semantics) |
|
104 | 104 | { |
105 | 105 | case self::ARGH_SEMANTICS_FLAG: return 'FLAG'; |
106 | 106 | case self::ARGH_SEMANTICS_FLAGS: return 'FLAGS'; |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | |
137 | 137 | // Validate the syntax regular expression |
138 | 138 | // Suppress error messages |
139 | - if( @preg_match($syntax, '') === FALSE ) |
|
139 | + if (@preg_match($syntax, '') === FALSE) |
|
140 | 140 | { |
141 | - throw new ArghException('Rule \'' . $name . '\' syntax \'' . $syntax . '\' is not a valid regular expression'); |
|
141 | + throw new ArghException('Rule \'' . $name . '\' syntax \'' . $syntax . '\' is not a valid regular expression'); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | // Confirm count(semantics) matches number of parenthesized subpatterns defined by the syntax regular expression |
145 | - if( substr_count($syntax, '(') != count($semantics) ) |
|
145 | + if (substr_count($syntax, '(') != count($semantics)) |
|
146 | 146 | { |
147 | 147 | throw new ArghException('Rule \'' . $name . '\' syntax defines ' . substr_count($syntax, '(') . ' sub-patterns, but semantics defines ' . count($semantics)); |
148 | 148 | } |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return bool |
204 | 204 | */ |
205 | - public function match($string, &$tokens=array()): bool |
|
205 | + public function match($string, &$tokens = array()): bool |
|
206 | 206 | { |
207 | - if( preg_match($this->syntax(), $string, $tokens) ) |
|
207 | + if (preg_match($this->syntax(), $string, $tokens)) |
|
208 | 208 | { |
209 | 209 | return TRUE; |
210 | 210 | } |
@@ -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 |