@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * VariableParameter.php |
|
| 5 | - */ |
|
| 4 | + * VariableParameter.php |
|
| 5 | + */ |
|
| 6 | 6 | |
| 7 | 7 | namespace netfocusinc\argh; |
| 8 | 8 | |
@@ -10,18 +10,18 @@ discard block |
||
| 10 | 10 | use netfocusinc\argh\Parameter; |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Variable parameter. |
|
| 14 | - * |
|
| 15 | - * Subtype of Parameter that represents an (unmarked) variable. |
|
| 16 | - * Variable Parameters are used to save unmakred input (naked variables) |
|
| 17 | - * Their value always consists of an array. |
|
| 18 | - * |
|
| 19 | - * @api |
|
| 20 | - * |
|
| 21 | - * @author Benjamin Hough |
|
| 22 | - * |
|
| 23 | - * @since 1.0.0 |
|
| 24 | - */ |
|
| 13 | + * Variable parameter. |
|
| 14 | + * |
|
| 15 | + * Subtype of Parameter that represents an (unmarked) variable. |
|
| 16 | + * Variable Parameters are used to save unmakred input (naked variables) |
|
| 17 | + * Their value always consists of an array. |
|
| 18 | + * |
|
| 19 | + * @api |
|
| 20 | + * |
|
| 21 | + * @author Benjamin Hough |
|
| 22 | + * |
|
| 23 | + * @since 1.0.0 |
|
| 24 | + */ |
|
| 25 | 25 | class VariableParameter extends Parameter |
| 26 | 26 | { |
| 27 | 27 | |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | // |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | - * Returns an instance of VariableParameter |
|
| 34 | - * |
|
| 35 | - * VariableParameters are always named with the ARGH_NAME_VARIABLE constant |
|
| 36 | - * |
|
| 37 | - * @since 1.0.1 |
|
| 38 | - * |
|
| 39 | - * @return Parameter |
|
| 40 | - */ |
|
| 33 | + * Returns an instance of VariableParameter |
|
| 34 | + * |
|
| 35 | + * VariableParameters are always named with the ARGH_NAME_VARIABLE constant |
|
| 36 | + * |
|
| 37 | + * @since 1.0.1 |
|
| 38 | + * |
|
| 39 | + * @return Parameter |
|
| 40 | + */ |
|
| 41 | 41 | public static function create() : Parameter |
| 42 | 42 | { |
| 43 | 43 | return parent::createWithAttributes( |
@@ -50,17 +50,17 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * Returns an instance of VariableParameter |
|
| 54 | - * |
|
| 55 | - * Overriding Parameter::createWithAttribute() here prevents this from being called with a custom 'name' attribute |
|
| 56 | - * VariableParameters need to be named with ARGH_NAME_VARIABLE constant; Argh uses this 'name' to find variables |
|
| 57 | - * |
|
| 58 | - * @since 1.0.2 |
|
| 59 | - * |
|
| 60 | - * @param array $attributes |
|
| 61 | - * |
|
| 62 | - * @return Parameter |
|
| 63 | - */ |
|
| 53 | + * Returns an instance of VariableParameter |
|
| 54 | + * |
|
| 55 | + * Overriding Parameter::createWithAttribute() here prevents this from being called with a custom 'name' attribute |
|
| 56 | + * VariableParameters need to be named with ARGH_NAME_VARIABLE constant; Argh uses this 'name' to find variables |
|
| 57 | + * |
|
| 58 | + * @since 1.0.2 |
|
| 59 | + * |
|
| 60 | + * @param array $attributes |
|
| 61 | + * |
|
| 62 | + * @return Parameter |
|
| 63 | + */ |
|
| 64 | 64 | public static function createWithAttributes(array $attributes) : Parameter |
| 65 | 65 | { |
| 66 | 66 | // Force VariableParameters to use a constant name |
@@ -77,26 +77,26 @@ discard block |
||
| 77 | 77 | // |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | - * Returns ARGH_TYPE_VARIABLE |
|
| 81 | - * |
|
| 82 | - * @since 1.0.0 |
|
| 83 | - * |
|
| 84 | - * @return int |
|
| 85 | - */ |
|
| 80 | + * Returns ARGH_TYPE_VARIABLE |
|
| 81 | + * |
|
| 82 | + * @since 1.0.0 |
|
| 83 | + * |
|
| 84 | + * @return int |
|
| 85 | + */ |
|
| 86 | 86 | public function getParameterType(): int |
| 87 | 87 | { |
| 88 | 88 | return Parameter::ARGH_TYPE_VARIABLE; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Sets the array value of this Parameter. |
|
| 93 | - * |
|
| 94 | - * Forces all values into an array |
|
| 95 | - * |
|
| 96 | - * @since 1.0.0 |
|
| 97 | - * |
|
| 98 | - * @param mixed $value |
|
| 99 | - */ |
|
| 92 | + * Sets the array value of this Parameter. |
|
| 93 | + * |
|
| 94 | + * Forces all values into an array |
|
| 95 | + * |
|
| 96 | + * @since 1.0.0 |
|
| 97 | + * |
|
| 98 | + * @param mixed $value |
|
| 99 | + */ |
|
| 100 | 100 | public function setValue($value) |
| 101 | 101 | { |
| 102 | 102 | if(is_array($value)) |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | - * Adds an element to the value of this Parameter |
|
| 114 | - * |
|
| 115 | - * Forces all values into an array |
|
| 116 | - * |
|
| 117 | - * @since 1.0.0 |
|
| 118 | - * |
|
| 119 | - * @param mixed $value |
|
| 120 | - * |
|
| 121 | - */ |
|
| 113 | + * Adds an element to the value of this Parameter |
|
| 114 | + * |
|
| 115 | + * Forces all values into an array |
|
| 116 | + * |
|
| 117 | + * @since 1.0.0 |
|
| 118 | + * |
|
| 119 | + * @param mixed $value |
|
| 120 | + * |
|
| 121 | + */ |
|
| 122 | 122 | public function addValue($value) |
| 123 | 123 | { |
| 124 | 124 | // Check if this Parameter has a previously set value |
@@ -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 | |
@@ -146,8 +146,7 @@ discard block |
||
| 146 | 146 | $index = $this->map[$key]; |
| 147 | 147 | |
| 148 | 148 | return $this->parameters[$index]; |
| 149 | - } |
|
| 150 | - else |
|
| 149 | + } else |
|
| 151 | 150 | { |
| 152 | 151 | throw new ArghException('Parameter \'' . $key . '\' not in collection'); |
| 153 | 152 | } |
@@ -198,9 +197,10 @@ discard block |
||
| 198 | 197 | $this->map[$param->getName()] = count($this->parameters)-1; |
| 199 | 198 | |
| 200 | 199 | // 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; |
|
| 202 | - } |
|
| 203 | - else |
|
| 200 | + if(!empty($param->getFlag())) { |
|
| 201 | + $this->map[$param->getFlag()] = count($this->parameters)-1; |
|
| 202 | + } |
|
| 203 | + } else |
|
| 204 | 204 | { |
| 205 | 205 | throw(new ArghException(__CLASS__ . ': Parameter \'' . $param->getName() . '\' cannot be redefined.')); |
| 206 | 206 | } |
@@ -232,22 +232,19 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | // Call VariableParameters::addValue() method |
| 234 | 234 | $this->parameters[$this->map[$a->getKey()]]->addValue($a->getValue()); |
| 235 | - } |
|
| 236 | - else if( null !== $this->parameters[$this->map[$a->getKey()]]->getValue() ) |
|
| 235 | + } else if( null !== $this->parameters[$this->map[$a->getKey()]]->getValue() ) |
|
| 237 | 236 | { |
| 238 | 237 | // |
| 239 | 238 | // Do NOT allow a Parameter's value to be redefined |
| 240 | 239 | // |
| 241 | 240 | |
| 242 | 241 | throw(new ArghException(__CLASS__ . ': Parameter \'' . $a->getKey() . '\' value cannot be redefined.')); |
| 243 | - } |
|
| 244 | - else |
|
| 242 | + } else |
|
| 245 | 243 | { |
| 246 | 244 | // Set Parameter value |
| 247 | 245 | $this->parameters[$this->map[$a->getKey()]]->setValue($a->getValue()); |
| 248 | 246 | } |
| 249 | - } |
|
| 250 | - else |
|
| 247 | + } else |
|
| 251 | 248 | { |
| 252 | 249 | throw(new ArghException(__CLASS__ . ': Cannot merge Argument \'' . $a->getKey() . '\'. Parameter not defined.')); |
| 253 | 250 | } |
@@ -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 | } |
@@ -253,8 +253,7 @@ |
||
| 253 | 253 | { |
| 254 | 254 | // Create an array of Rules |
| 255 | 255 | $this->rules = array(); |
| 256 | - } |
|
| 257 | - catch(\Exception $e) |
|
| 256 | + } catch(\Exception $e) |
|
| 258 | 257 | { |
| 259 | 258 | throw($e); |
| 260 | 259 | } |
@@ -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; |
@@ -1,51 +1,51 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * ArghException.php |
|
| 5 | - */ |
|
| 4 | + * ArghException.php |
|
| 5 | + */ |
|
| 6 | 6 | |
| 7 | 7 | namespace netfocusinc\argh; |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | - * An exception that is thrown by Argh |
|
| 11 | - * |
|
| 12 | - * A subclass of Exception that is thrown by Argh. |
|
| 13 | - * |
|
| 14 | - * @author Benjamin Hough |
|
| 15 | - * |
|
| 16 | - * @since 1.0.0 |
|
| 17 | - * |
|
| 18 | - */ |
|
| 10 | + * An exception that is thrown by Argh |
|
| 11 | + * |
|
| 12 | + * A subclass of Exception that is thrown by Argh. |
|
| 13 | + * |
|
| 14 | + * @author Benjamin Hough |
|
| 15 | + * |
|
| 16 | + * @since 1.0.0 |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | 19 | class ArghException extends \Exception |
| 20 | 20 | { |
| 21 | 21 | /** |
| 22 | - * Contruct a new ArghException with a required message |
|
| 23 | - * |
|
| 24 | - * @since 1.0.0 |
|
| 25 | - * |
|
| 26 | - * @param string $message Custom message describing this Exception |
|
| 27 | - * @param int $code Custom error code |
|
| 28 | - * @param Exception $previous The previous Exception to occurr |
|
| 29 | - * |
|
| 30 | - */ |
|
| 31 | - public function __construct($message, $code = 0, \Exception $previous = null) { |
|
| 32 | - // some code |
|
| 22 | + * Contruct a new ArghException with a required message |
|
| 23 | + * |
|
| 24 | + * @since 1.0.0 |
|
| 25 | + * |
|
| 26 | + * @param string $message Custom message describing this Exception |
|
| 27 | + * @param int $code Custom error code |
|
| 28 | + * @param Exception $previous The previous Exception to occurr |
|
| 29 | + * |
|
| 30 | + */ |
|
| 31 | + public function __construct($message, $code = 0, \Exception $previous = null) { |
|
| 32 | + // some code |
|
| 33 | 33 | |
| 34 | - // make sure everything is assigned properly |
|
| 35 | - parent::__construct($message, $code, $previous); |
|
| 36 | - } |
|
| 34 | + // make sure everything is assigned properly |
|
| 35 | + parent::__construct($message, $code, $previous); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | - * Returns a descriptive string indentifying this Exception |
|
| 41 | - * |
|
| 42 | - * @since 1.0.0 |
|
| 43 | - * |
|
| 44 | - * @return string |
|
| 45 | - * |
|
| 46 | - */ |
|
| 47 | - public function __toString() { |
|
| 48 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 49 | - } |
|
| 40 | + * Returns a descriptive string indentifying this Exception |
|
| 41 | + * |
|
| 42 | + * @since 1.0.0 |
|
| 43 | + * |
|
| 44 | + * @return string |
|
| 45 | + * |
|
| 46 | + */ |
|
| 47 | + public function __toString() { |
|
| 48 | + return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | \ No newline at end of file |