@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | public static function createWithAttributes(array $attributes) : Parameter |
| 65 | 65 | { |
| 66 | 66 | // Force VariableParameters to use a constant name |
| 67 | - if(array_key_exists('name', $attributes)) |
|
| 67 | + if (array_key_exists('name', $attributes)) |
|
| 68 | 68 | { |
| 69 | 69 | $attributes['name'] = Parameter::ARGH_NAME_VARIABLE; |
| 70 | 70 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function setValue($value) |
| 101 | 101 | { |
| 102 | - if(is_array($value)) |
|
| 102 | + if (is_array($value)) |
|
| 103 | 103 | { |
| 104 | 104 | $this->value = $value; |
| 105 | 105 | } |
@@ -122,14 +122,14 @@ discard block |
||
| 122 | 122 | public function addValue($value) |
| 123 | 123 | { |
| 124 | 124 | // Check if this Parameter has a previously set value |
| 125 | - if($this->value === null) |
|
| 125 | + if ($this->value === null) |
|
| 126 | 126 | { |
| 127 | 127 | // Initialize this Parameters value to a new array |
| 128 | 128 | $this->value = array(); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Check if the new value is an array |
| 132 | - if(!is_array($value)) |
|
| 132 | + if (!is_array($value)) |
|
| 133 | 133 | { |
| 134 | 134 | // Append new single value to this Parameters value array |
| 135 | 135 | $this->value[] = $value; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | else |
| 138 | 138 | { |
| 139 | 139 | // Append every new value to this Parameters value array |
| 140 | - foreach($value as $v) $this->value[] = $v; |
|
| 140 | + foreach ($value as $v) $this->value[] = $v; |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
@@ -254,7 +254,7 @@ |
||
| 254 | 254 | // Create an array of Rules |
| 255 | 255 | $this->rules = array(); |
| 256 | 256 | } |
| 257 | - catch(\Exception $e) |
|
| 257 | + catch (\Exception $e) |
|
| 258 | 258 | { |
| 259 | 259 | throw($e); |
| 260 | 260 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | const ARGH_SYNTAX_LIST = '[a-z0-9_\-,\' ]+'; |
| 33 | 33 | const ARGH_SYNTAX_COMMAND = '[a-z0-9_]{2,}'; |
| 34 | 34 | const ARGH_SYNTAX_QUOTED = '[a-z0-9_\-\'\\/\. ]+'; |
| 35 | - const ARGH_SYNTAX_VARIABLE = '[a-z0-9_\.\/]*'; |
|
| 35 | + const ARGH_SYNTAX_VARIABLE = '[a-z0-9_\.\/]*'; |
|
| 36 | 36 | |
| 37 | 37 | // Semantic Contants |
| 38 | 38 | const ARGH_SEMANTICS_FLAG = 1; |
@@ -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 | } |
@@ -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; |
@@ -248,21 +248,21 @@ discard block |
||
| 248 | 248 | // Loop through $tokens and define Argument(s) based on the current rules semantics |
| 249 | 249 | $count_tokens = count($tokens); |
| 250 | 250 | |
| 251 | - for($i=1; $i<$count_tokens; $i++) |
|
| 251 | + for ($i = 1; $i<$count_tokens; $i++) |
|
| 252 | 252 | { |
| 253 | 253 | $token = $tokens[$i]; |
| 254 | 254 | $semantics = $rule->semantics()[$i-1]; |
| 255 | 255 | |
| 256 | 256 | //echo __METHOD__ . ": token: $token (" . Rule::semanticsToString($semantics) . ")\n"; |
| 257 | 257 | |
| 258 | - switch( $semantics ) |
|
| 258 | + switch ($semantics) |
|
| 259 | 259 | { |
| 260 | 260 | case ARGH_SEMANTICS_FLAG: |
| 261 | 261 | |
| 262 | - if( $this->parameterCollection->exists($token) ) |
|
| 262 | + if ($this->parameterCollection->exists($token)) |
|
| 263 | 263 | { |
| 264 | 264 | // This Rule will create a single Argument |
| 265 | - if(count($argument)==0) $argument[0] = new Argument($token); |
|
| 265 | + if (count($argument) == 0) $argument[0] = new Argument($token); |
|
| 266 | 266 | } |
| 267 | 267 | else |
| 268 | 268 | { |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | case ARGH_SEMANTICS_FLAGS: |
| 277 | 277 | |
| 278 | 278 | // Check every character of this $token for a matching parameter 'flag' |
| 279 | - for($j=0; $j<strlen($token); $j++) |
|
| 279 | + for ($j = 0; $j<strlen($token); $j++) |
|
| 280 | 280 | { |
| 281 | - if( $this->parameterCollection->exists( $token{$j} ) ) |
|
| 281 | + if ($this->parameterCollection->exists($token{$j} )) |
|
| 282 | 282 | { |
| 283 | 283 | // This Rule can only apply to ARGH_TYPE_BOOLEAN Parameters |
| 284 | - if( ARGH_TYPE_BOOLEAN == $this->parameterCollection->get($token{$j})->getParameterType() ) |
|
| 284 | + if (ARGH_TYPE_BOOLEAN == $this->parameterCollection->get($token{$j})->getParameterType()) |
|
| 285 | 285 | { |
| 286 | 286 | // Create new Argument for each flag |
| 287 | - if( !array_key_exists($j, $argument) ) $argument[$j] = new Argument($token{$j}); |
|
| 287 | + if (!array_key_exists($j, $argument)) $argument[$j] = new Argument($token{$j}); |
|
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | else |
@@ -303,10 +303,10 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | case ARGH_SEMANTICS_NAME: |
| 305 | 305 | |
| 306 | - if( $this->parameterCollection->exists($token) ) |
|
| 306 | + if ($this->parameterCollection->exists($token)) |
|
| 307 | 307 | { |
| 308 | 308 | // This Rule will create a single Argument |
| 309 | - if(count($argument)==0) $argument[0] = new Argument($token); |
|
| 309 | + if (count($argument) == 0) $argument[0] = new Argument($token); |
|
| 310 | 310 | } |
| 311 | 311 | else |
| 312 | 312 | { |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | // Usually, the Argument will have already been created by another token in this Rule |
| 323 | 323 | |
| 324 | 324 | // If no new Argument created by this Rule yet, create one now |
| 325 | - if(count($argument)==0) $argument[0] = new Argument(); |
|
| 325 | + if (count($argument) == 0) $argument[0] = new Argument(); |
|
| 326 | 326 | |
| 327 | 327 | // The new Argument's 'key' should be set by another token in this Rule |
| 328 | 328 | $argument[0]->setValue($token); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | // Usually, the Argument will have already been created by another token in this Rule |
| 335 | 335 | |
| 336 | 336 | // If no new Argument created by this Rule yet, create one now |
| 337 | - if(count($argument)==0) $argument[0] = new Argument(); |
|
| 337 | + if (count($argument) == 0) $argument[0] = new Argument(); |
|
| 338 | 338 | |
| 339 | 339 | // Trim brackets from the $token (list) |
| 340 | 340 | $token = trim($token, "[]"); |
@@ -344,28 +344,28 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | // Use the $elements array as the 'value' for all new Argument created by this Rule |
| 346 | 346 | // Usually, this will only apply to a single Argument, unless this Rule contains ARGH_SEMANTICS_FLAGS |
| 347 | - foreach($argument as &$a) $a->setValue($elements); |
|
| 347 | + foreach ($argument as &$a) $a->setValue($elements); |
|
| 348 | 348 | |
| 349 | 349 | break; |
| 350 | 350 | |
| 351 | 351 | case ARGH_SEMANTICS_COMMAND: |
| 352 | 352 | |
| 353 | 353 | // Check if ParameterCollection contains any commands |
| 354 | - if($this->parameterCollection->hasCommand()) |
|
| 354 | + if ($this->parameterCollection->hasCommand()) |
|
| 355 | 355 | { |
| 356 | 356 | // Retrieve all ARGH_TYPE_COMMAND Parameters |
| 357 | 357 | $commands = $this->parameterCollection->getCommands(); |
| 358 | 358 | |
| 359 | - foreach($commands as $p) |
|
| 359 | + foreach ($commands as $p) |
|
| 360 | 360 | { |
| 361 | - if($p->hasOptions()) |
|
| 361 | + if ($p->hasOptions()) |
|
| 362 | 362 | { |
| 363 | - if( in_array($token, $p->getOptions()) ) |
|
| 363 | + if (in_array($token, $p->getOptions())) |
|
| 364 | 364 | { |
| 365 | 365 | // $token matches an option of this ARGH_TYPE_COMMAND Parameter |
| 366 | 366 | |
| 367 | 367 | // If no new Argument created by this Rule yet, create one now |
| 368 | - if(count($argument)==0) $argument[0] = new Argument($p->getName(), $token); |
|
| 368 | + if (count($argument) == 0) $argument[0] = new Argument($p->getName(), $token); |
|
| 369 | 369 | |
| 370 | 370 | // Stop searching this Parameters options |
| 371 | 371 | break; |