@@ -21,7 +21,7 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function __construct(string $message, ?string $details = null, $code = null, $previous = null) |
| 23 | 23 | { |
| 24 | - if(defined('TESTS_ROOT') && !empty($details)) { |
|
| 24 | + if (defined('TESTS_ROOT') && !empty($details)) { |
|
| 25 | 25 | $message .= PHP_EOL. |
| 26 | 26 | 'Details:'.PHP_EOL. |
| 27 | 27 | $details; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | if (!$token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) { |
| 40 | 40 | $this->validationResult->makeError( |
| 41 | - t('Invalid namespace token:') . ' ' . t('Expected a string.'), |
|
| 41 | + t('Invalid namespace token:').' '.t('Expected a string.'), |
|
| 42 | 42 | NamespaceInterface::VALIDATION_NAMESPACE_WRONG_TYPE |
| 43 | 43 | ); |
| 44 | 44 | return; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $token = $this->getNamespaceToken(); |
| 63 | 63 | |
| 64 | - if($token !== null) { |
|
| 64 | + if ($token !== null) { |
|
| 65 | 65 | return $token; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | private string $paramsString; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var string[] |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var string[] |
|
| 36 | + */ |
|
| 37 | 37 | private array $names = array( |
| 38 | 38 | 'and', |
| 39 | 39 | 'or' |
| 40 | 40 | ); |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var Mailcode_Commands_LogicKeywords_Keyword[] |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var Mailcode_Commands_LogicKeywords_Keyword[] |
|
| 44 | + */ |
|
| 45 | 45 | private array $keywords = array(); |
| 46 | 46 | |
| 47 | 47 | private string $mainParams = ''; |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @return string[] |
|
| 133 | - */ |
|
| 131 | + /** |
|
| 132 | + * @return string[] |
|
| 133 | + */ |
|
| 134 | 134 | private function detectParameters() : array |
| 135 | 135 | { |
| 136 | 136 | $params = $this->paramsString; |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | return $stack; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * @param string $params |
|
| 153 | - * @param Mailcode_Commands_LogicKeywords_Keyword $keyword |
|
| 154 | - * @param string[] $stack |
|
| 155 | - * @throws Mailcode_Exception |
|
| 156 | - * @return string |
|
| 157 | - */ |
|
| 151 | + /** |
|
| 152 | + * @param string $params |
|
| 153 | + * @param Mailcode_Commands_LogicKeywords_Keyword $keyword |
|
| 154 | + * @param string[] $stack |
|
| 155 | + * @throws Mailcode_Exception |
|
| 156 | + * @return string |
|
| 157 | + */ |
|
| 158 | 158 | private function detectParamsKeyword(string $params, Mailcode_Commands_LogicKeywords_Keyword $keyword, array &$stack) : string |
| 159 | 159 | { |
| 160 | 160 | $search = $keyword->getMatchedString(); |
@@ -189,22 +189,22 @@ discard block |
||
| 189 | 189 | return $params; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Extracts the parameters string to use for the |
|
| 194 | - * original command itself, omitting all the logic |
|
| 195 | - * keywords for the sub-commands. |
|
| 196 | - * |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 192 | + /** |
|
| 193 | + * Extracts the parameters string to use for the |
|
| 194 | + * original command itself, omitting all the logic |
|
| 195 | + * keywords for the sub-commands. |
|
| 196 | + * |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | 199 | public function getMainParamsString() : string |
| 200 | 200 | { |
| 201 | 201 | return $this->mainParams; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Retrieves the detected keyword names. |
|
| 206 | - * @return string[] |
|
| 207 | - */ |
|
| 204 | + /** |
|
| 205 | + * Retrieves the detected keyword names. |
|
| 206 | + * @return string[] |
|
| 207 | + */ |
|
| 208 | 208 | public function getDetectedNames() : array |
| 209 | 209 | { |
| 210 | 210 | $names = array(); |
@@ -221,23 +221,23 @@ discard block |
||
| 221 | 221 | return $names; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Retrieves all keywords detected in the |
|
| 226 | - * command's parameter string, if any. |
|
| 227 | - * |
|
| 228 | - * @return Mailcode_Commands_LogicKeywords_Keyword[] |
|
| 229 | - */ |
|
| 224 | + /** |
|
| 225 | + * Retrieves all keywords detected in the |
|
| 226 | + * command's parameter string, if any. |
|
| 227 | + * |
|
| 228 | + * @return Mailcode_Commands_LogicKeywords_Keyword[] |
|
| 229 | + */ |
|
| 230 | 230 | public function getKeywords() : array |
| 231 | 231 | { |
| 232 | 232 | return $this->keywords; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Detects any keyword statements in the parameters by keyword name. |
|
| 237 | - * |
|
| 238 | - * @param string $name |
|
| 239 | - * @return Mailcode_Commands_LogicKeywords_Keyword[] |
|
| 240 | - */ |
|
| 235 | + /** |
|
| 236 | + * Detects any keyword statements in the parameters by keyword name. |
|
| 237 | + * |
|
| 238 | + * @param string $name |
|
| 239 | + * @return Mailcode_Commands_LogicKeywords_Keyword[] |
|
| 240 | + */ |
|
| 241 | 241 | private function detectKeywords(string $name) : array |
| 242 | 242 | { |
| 243 | 243 | $regex = sprintf('/%1$s\s+([a-z\-0-9]+):|%1$s:/x', $name); |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | private function parse() : void |
| 65 | 65 | { |
| 66 | - foreach($this->names as $name) |
|
| 66 | + foreach ($this->names as $name) |
|
| 67 | 67 | { |
| 68 | - if(stripos($this->paramsString, $name) === false) { |
|
| 68 | + if (stripos($this->paramsString, $name) === false) { |
|
| 69 | 69 | continue; |
| 70 | 70 | } |
| 71 | 71 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $names = $this->getDetectedNames(); |
| 82 | 82 | $amount = count($names); |
| 83 | 83 | |
| 84 | - if($amount > 1) |
|
| 84 | + if ($amount > 1) |
|
| 85 | 85 | { |
| 86 | 86 | $this->makeError( |
| 87 | 87 | t( |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | private function splitParams() : void |
| 103 | 103 | { |
| 104 | - if(empty($this->keywords)) |
|
| 104 | + if (empty($this->keywords)) |
|
| 105 | 105 | { |
| 106 | 106 | $this->mainParams = $this->paramsString; |
| 107 | 107 | |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $params = $this->detectParameters(); |
| 112 | 112 | |
| 113 | - foreach($this->keywords as $keyword) |
|
| 113 | + foreach ($this->keywords as $keyword) |
|
| 114 | 114 | { |
| 115 | 115 | $kParams = (string)array_shift($params); |
| 116 | 116 | |
| 117 | 117 | $keyword->setParamsString($kParams); |
| 118 | 118 | |
| 119 | - if(!$keyword->isValid()) |
|
| 119 | + if (!$keyword->isValid()) |
|
| 120 | 120 | { |
| 121 | 121 | $this->makeError( |
| 122 | 122 | t('Error #%1$s:', $keyword->getCode()).' '.$keyword->getErrorMessage(), |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $params = $this->paramsString; |
| 137 | 137 | $stack = array(); |
| 138 | 138 | |
| 139 | - foreach($this->keywords as $keyword) |
|
| 139 | + foreach ($this->keywords as $keyword) |
|
| 140 | 140 | { |
| 141 | 141 | $params = $this->detectParamsKeyword($params, $keyword, $stack); |
| 142 | 142 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $search = $keyword->getMatchedString(); |
| 161 | 161 | $pos = strpos($params, $search, 0); |
| 162 | 162 | |
| 163 | - if($pos === false) |
|
| 163 | + if ($pos === false) |
|
| 164 | 164 | { |
| 165 | 165 | throw new Mailcode_Exception( |
| 166 | 166 | 'Keyword matched string not found', |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | $store = substr($params, 0, $pos); |
| 175 | 175 | |
| 176 | - if($store === false) |
|
| 176 | + if ($store === false) |
|
| 177 | 177 | { |
| 178 | 178 | throw new Mailcode_Exception( |
| 179 | 179 | 'Keyword substring not found', |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | ); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - $params = trim(substr($params, $pos+$length)); |
|
| 185 | + $params = trim(substr($params, $pos + $length)); |
|
| 186 | 186 | |
| 187 | 187 | $stack[] = $store; |
| 188 | 188 | |
@@ -209,11 +209,11 @@ discard block |
||
| 209 | 209 | { |
| 210 | 210 | $names = array(); |
| 211 | 211 | |
| 212 | - foreach($this->keywords as $keyword) |
|
| 212 | + foreach ($this->keywords as $keyword) |
|
| 213 | 213 | { |
| 214 | 214 | $name = $keyword->getName(); |
| 215 | 215 | |
| 216 | - if(!in_array($name, $names, true)) { |
|
| 216 | + if (!in_array($name, $names, true)) { |
|
| 217 | 217 | $names[] = $name; |
| 218 | 218 | } |
| 219 | 219 | } |
@@ -245,14 +245,14 @@ discard block |
||
| 245 | 245 | $matches = array(); |
| 246 | 246 | preg_match_all($regex, $this->paramsString, $matches, PREG_PATTERN_ORDER); |
| 247 | 247 | |
| 248 | - if(empty($matches[0][0])) { |
|
| 248 | + if (empty($matches[0][0])) { |
|
| 249 | 249 | return array(); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | $amount = count($matches[0]); |
| 253 | 253 | $result = array(); |
| 254 | 254 | |
| 255 | - for($i=0; $i < $amount; $i++) |
|
| 255 | + for ($i = 0; $i < $amount; $i++) |
|
| 256 | 256 | { |
| 257 | 257 | $result[] = $this->createKeyword( |
| 258 | 258 | $name, |
@@ -269,22 +269,22 @@ discard block |
||
| 269 | 269 | return !empty($this->keywords); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - public function appendAND(string $paramsString, string $type='') : Mailcode_Commands_LogicKeywords_Keyword |
|
| 272 | + public function appendAND(string $paramsString, string $type = '') : Mailcode_Commands_LogicKeywords_Keyword |
|
| 273 | 273 | { |
| 274 | 274 | return $this->appendKeyword('and', $paramsString, $type); |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - public function appendOR(string $paramsString, string $type='') : Mailcode_Commands_LogicKeywords_Keyword |
|
| 277 | + public function appendOR(string $paramsString, string $type = '') : Mailcode_Commands_LogicKeywords_Keyword |
|
| 278 | 278 | { |
| 279 | 279 | return $this->appendKeyword('or', $paramsString, $type); |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - public function appendKeyword(string $name, string $paramsString, string $type='') : Mailcode_Commands_LogicKeywords_Keyword |
|
| 282 | + public function appendKeyword(string $name, string $paramsString, string $type = '') : Mailcode_Commands_LogicKeywords_Keyword |
|
| 283 | 283 | { |
| 284 | 284 | $keyword = $this->createKeyword($name, $type); |
| 285 | 285 | $keyword->setParamsString($paramsString); |
| 286 | 286 | |
| 287 | - if(!$keyword->isValid()) |
|
| 287 | + if (!$keyword->isValid()) |
|
| 288 | 288 | { |
| 289 | 289 | throw new Mailcode_Exception( |
| 290 | 290 | 'Cannot append invalid logic keyword', |
@@ -305,13 +305,13 @@ discard block |
||
| 305 | 305 | return $keyword; |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - private function createKeyword(string $name, string $type='', string $matchedString='') : Mailcode_Commands_LogicKeywords_Keyword |
|
| 308 | + private function createKeyword(string $name, string $type = '', string $matchedString = '') : Mailcode_Commands_LogicKeywords_Keyword |
|
| 309 | 309 | { |
| 310 | - if(empty($matchedString)) |
|
| 310 | + if (empty($matchedString)) |
|
| 311 | 311 | { |
| 312 | 312 | $matchedString = $name; |
| 313 | 313 | |
| 314 | - if(!empty($type)) |
|
| 314 | + if (!empty($type)) |
|
| 315 | 315 | { |
| 316 | 316 | $matchedString .= ' '.$type; |
| 317 | 317 | } |
@@ -23,39 +23,39 @@ discard block |
||
| 23 | 23 | public const ERROR_INVALID_CALLABLE = 65701; |
| 24 | 24 | public const ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION = 65702; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | 29 | private $subject; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var integer |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var integer |
|
| 33 | + */ |
|
| 34 | 34 | private static $listenerCounter = 0; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var callable[] |
|
| 38 | - */ |
|
| 36 | + /** |
|
| 37 | + * @var callable[] |
|
| 38 | + */ |
|
| 39 | 39 | private $listeners = array(); |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var boolean |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var boolean |
|
| 43 | + */ |
|
| 44 | 44 | private $updating = false; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var integer |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var integer |
|
| 48 | + */ |
|
| 49 | 49 | private static $idCounter = 0; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var integer |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var integer |
|
| 53 | + */ |
|
| 54 | 54 | private $id; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var integer |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var integer |
|
| 58 | + */ |
|
| 59 | 59 | private $length; |
| 60 | 60 | |
| 61 | 61 | public function __construct(string $subject) |
@@ -72,16 +72,16 @@ discard block |
||
| 72 | 72 | return $this->id; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Updates the string with the specified string. |
|
| 77 | - * Notifies all listeners of the change. |
|
| 78 | - * |
|
| 79 | - * @param string $subject |
|
| 80 | - * @throws Mailcode_Exception |
|
| 81 | - * @return bool Whether the string had modifications. |
|
| 82 | - * |
|
| 83 | - * @see Mailcode_StringContainer::ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION |
|
| 84 | - */ |
|
| 75 | + /** |
|
| 76 | + * Updates the string with the specified string. |
|
| 77 | + * Notifies all listeners of the change. |
|
| 78 | + * |
|
| 79 | + * @param string $subject |
|
| 80 | + * @throws Mailcode_Exception |
|
| 81 | + * @return bool Whether the string had modifications. |
|
| 82 | + * |
|
| 83 | + * @see Mailcode_StringContainer::ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION |
|
| 84 | + */ |
|
| 85 | 85 | public function updateString(string $subject) : bool |
| 86 | 86 | { |
| 87 | 87 | // avoid triggering an update if there are no changes in the string |
@@ -114,27 +114,27 @@ discard block |
||
| 114 | 114 | return true; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Retrieves the stored string. |
|
| 119 | - * |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 117 | + /** |
|
| 118 | + * Retrieves the stored string. |
|
| 119 | + * |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | 122 | public function getString() : string |
| 123 | 123 | { |
| 124 | 124 | return $this->subject; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Adds a listener that will be informed every time the string is modified. |
|
| 129 | - * The callback gets the string container instance as parameter. |
|
| 130 | - * |
|
| 131 | - * @param callable|mixed $callback |
|
| 132 | - * @throws Mailcode_Exception If it is not a valid callable. |
|
| 133 | - * @return int The listener number, to be able to remove it using `removeListener()`. |
|
| 134 | - * |
|
| 135 | - * @see Mailcode_StringContainer::removeListener() |
|
| 136 | - * @see Mailcode_StringContainer::ERROR_INVALID_CALLABLE |
|
| 137 | - */ |
|
| 127 | + /** |
|
| 128 | + * Adds a listener that will be informed every time the string is modified. |
|
| 129 | + * The callback gets the string container instance as parameter. |
|
| 130 | + * |
|
| 131 | + * @param callable|mixed $callback |
|
| 132 | + * @throws Mailcode_Exception If it is not a valid callable. |
|
| 133 | + * @return int The listener number, to be able to remove it using `removeListener()`. |
|
| 134 | + * |
|
| 135 | + * @see Mailcode_StringContainer::removeListener() |
|
| 136 | + * @see Mailcode_StringContainer::ERROR_INVALID_CALLABLE |
|
| 137 | + */ |
|
| 138 | 138 | public function addListener($callback) : int |
| 139 | 139 | { |
| 140 | 140 | self::$listenerCounter++; |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | return $this->length; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Removes an existing listener by its ID. |
|
| 166 | - * Has no effect if it does not exist, or has already been removed. |
|
| 167 | - * |
|
| 168 | - * @param int $listenerID |
|
| 169 | - */ |
|
| 164 | + /** |
|
| 165 | + * Removes an existing listener by its ID. |
|
| 166 | + * Has no effect if it does not exist, or has already been removed. |
|
| 167 | + * |
|
| 168 | + * @param int $listenerID |
|
| 169 | + */ |
|
| 170 | 170 | public function removeListener(int $listenerID) : void |
| 171 | 171 | { |
| 172 | 172 | if(isset($this->listeners[$listenerID])) |
@@ -175,13 +175,13 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Replaces all substrings matching needle with the replacement text. |
|
| 180 | - * |
|
| 181 | - * @param string $needle |
|
| 182 | - * @param string $replacement |
|
| 183 | - * @return bool |
|
| 184 | - */ |
|
| 178 | + /** |
|
| 179 | + * Replaces all substrings matching needle with the replacement text. |
|
| 180 | + * |
|
| 181 | + * @param string $needle |
|
| 182 | + * @param string $replacement |
|
| 183 | + * @return bool |
|
| 184 | + */ |
|
| 185 | 185 | public function replaceSubstrings(string $needle, string $replacement) : bool |
| 186 | 186 | { |
| 187 | 187 | $string = str_replace($needle, $replacement, $this->subject); |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | return $this->updateString($string); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Get the position of a substring in the string. |
|
| 194 | - * |
|
| 195 | - * @param string $needle |
|
| 196 | - * @return int|bool The zero-based position, or false if not found. |
|
| 197 | - */ |
|
| 192 | + /** |
|
| 193 | + * Get the position of a substring in the string. |
|
| 194 | + * |
|
| 195 | + * @param string $needle |
|
| 196 | + * @return int|bool The zero-based position, or false if not found. |
|
| 197 | + */ |
|
| 198 | 198 | public function getSubstrPosition(string $needle) |
| 199 | 199 | { |
| 200 | 200 | return mb_strpos($this->subject, $needle); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @return class-string[] |
| 28 | 28 | * @throws FileHelper_Exception |
| 29 | 29 | */ |
| 30 | - public static function findClassesInFolder($folder, bool $recursive=false, ?string $instanceOf=null) : array |
|
| 30 | + public static function findClassesInFolder($folder, bool $recursive = false, ?string $instanceOf = null) : array |
|
| 31 | 31 | { |
| 32 | 32 | return self::createCache() |
| 33 | 33 | ->findClassesInFolder( |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | private static function createCache() : ClassRepositoryManager |
| 44 | 44 | { |
| 45 | - if(!isset(self::$cache)) { |
|
| 45 | + if (!isset(self::$cache)) { |
|
| 46 | 46 | self::$cache = ClassRepositoryManager::create(Mailcode::getCacheFolder()); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public static function create() : Mailcode_Translator |
| 35 | 35 | { |
| 36 | - if(is_null(self::$instance)) { |
|
| 36 | + if (is_null(self::$instance)) { |
|
| 37 | 37 | self::$instance = new self(); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function __construct() |
| 44 | 44 | { |
| 45 | - foreach($this->resolveSyntaxClasses() as $class) { |
|
| 45 | + foreach ($this->resolveSyntaxClasses() as $class) { |
|
| 46 | 46 | $syntax = new $class(); |
| 47 | 47 | $this->syntaxes[$syntax->getTypeID()] = $syntax; |
| 48 | 48 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function createSyntax(string $name) : SyntaxInterface |
| 58 | 58 | { |
| 59 | - if(isset($this->syntaxes[$name])) { |
|
| 59 | + if (isset($this->syntaxes[$name])) { |
|
| 60 | 60 | return $this->syntaxes[$name]; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | { |
| 126 | 126 | $result = array(); |
| 127 | 127 | |
| 128 | - foreach($this->tokensOrdered as $token) |
|
| 128 | + foreach ($this->tokensOrdered as $token) |
|
| 129 | 129 | { |
| 130 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Unknown) |
|
| 130 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Unknown) |
|
| 131 | 131 | { |
| 132 | 132 | $result[] = $token; |
| 133 | 133 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | $unknown = $this->getUnknown(); |
| 142 | 142 | |
| 143 | - if(!empty($unknown)) |
|
| 143 | + if (!empty($unknown)) |
|
| 144 | 144 | { |
| 145 | 145 | return array_shift($unknown); |
| 146 | 146 | } |
@@ -152,16 +152,16 @@ discard block |
||
| 152 | 152 | { |
| 153 | 153 | $parts = array(); |
| 154 | 154 | |
| 155 | - foreach($this->tokensOrdered as $token) |
|
| 155 | + foreach ($this->tokensOrdered as $token) |
|
| 156 | 156 | { |
| 157 | 157 | $string = $token->getNormalized(); |
| 158 | 158 | |
| 159 | - if($string === '') { |
|
| 159 | + if ($string === '') { |
|
| 160 | 160 | continue; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Only add spaces between tokens if they require spacing |
| 164 | - if($token->hasSpacing()) { |
|
| 164 | + if ($token->hasSpacing()) { |
|
| 165 | 165 | $string .= ' '; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $statement = trim($statement); |
| 188 | 188 | $tokens = array(); |
| 189 | 189 | |
| 190 | - foreach($this->tokenClasses as $tokenClass) |
|
| 190 | + foreach ($this->tokenClasses as $tokenClass) |
|
| 191 | 191 | { |
| 192 | 192 | $processor = $this->createProcessor($tokenClass, $statement, $tokens); |
| 193 | 193 | $processor->process(); |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | { |
| 212 | 212 | $instance = new $className($this, $statement, $tokens); |
| 213 | 213 | |
| 214 | - if($instance instanceof Mailcode_Parser_Statement_Tokenizer_Process) |
|
| 214 | + if ($instance instanceof Mailcode_Parser_Statement_Tokenizer_Process) |
|
| 215 | 215 | { |
| 216 | 216 | return $instance; |
| 217 | 217 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @param mixed $subject |
| 233 | 233 | * @return Mailcode_Parser_Statement_Tokenizer_Token |
| 234 | 234 | */ |
| 235 | - public function createToken(string $type, string $matchedText, $subject=null) : Mailcode_Parser_Statement_Tokenizer_Token |
|
| 235 | + public function createToken(string $type, string $matchedText, $subject = null) : Mailcode_Parser_Statement_Tokenizer_Token |
|
| 236 | 236 | { |
| 237 | 237 | $tokenID = $this->generateID(); |
| 238 | 238 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | $token = new $class($tokenID, $matchedText, $subject, $this->getSourceCommand()); |
| 242 | 242 | |
| 243 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token) |
|
| 243 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token) |
|
| 244 | 244 | { |
| 245 | 245 | return $token; |
| 246 | 246 | } |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | $token = $this->createToken('Keyword', $name); |
| 271 | 271 | |
| 272 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Keyword) |
|
| 272 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Keyword) |
|
| 273 | 273 | { |
| 274 | 274 | return $token; |
| 275 | 275 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | { |
| 295 | 295 | $token = $this->createToken('StringLiteral', SpecialChars::encodeAll($text)); |
| 296 | 296 | |
| 297 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) |
|
| 297 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) |
|
| 298 | 298 | { |
| 299 | 299 | return $token; |
| 300 | 300 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | { |
| 311 | 311 | $token = $this->createToken('Number', $number); |
| 312 | 312 | |
| 313 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number) |
|
| 313 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number) |
|
| 314 | 314 | { |
| 315 | 315 | return $token; |
| 316 | 316 | } |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | public function removeToken(Mailcode_Parser_Statement_Tokenizer_Token $token) : Mailcode_Parser_Statement_Tokenizer |
| 353 | 353 | { |
| 354 | 354 | $name = $this->findNameToken($token); |
| 355 | - if($name !== null) { |
|
| 355 | + if ($name !== null) { |
|
| 356 | 356 | $this->removeToken($name); |
| 357 | 357 | } |
| 358 | 358 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | |
| 363 | 363 | foreach ($this->tokensOrdered as $checkToken) |
| 364 | 364 | { |
| 365 | - if($checkToken->getID() === $tokenID) |
|
| 365 | + if ($checkToken->getID() === $tokenID) |
|
| 366 | 366 | { |
| 367 | 367 | $removed = true; |
| 368 | 368 | continue; |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | $this->tokensOrdered = $keep; |
| 375 | 375 | |
| 376 | - if($removed) |
|
| 376 | + if ($removed) |
|
| 377 | 377 | { |
| 378 | 378 | $this->eventHandler->handleTokenRemoved($token); |
| 379 | 379 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | { |
| 419 | 419 | static $alphas; |
| 420 | 420 | |
| 421 | - if(!isset($alphas)) |
|
| 421 | + if (!isset($alphas)) |
|
| 422 | 422 | { |
| 423 | 423 | $alphas = range('A', 'Z'); |
| 424 | 424 | } |
@@ -427,12 +427,12 @@ discard block |
||
| 427 | 427 | |
| 428 | 428 | $result = ''; |
| 429 | 429 | |
| 430 | - for($i=0; $i < $amount; $i++) |
|
| 430 | + for ($i = 0; $i < $amount; $i++) |
|
| 431 | 431 | { |
| 432 | 432 | $result .= $alphas[array_rand($alphas)]; |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if(!in_array($result, self::$ids)) |
|
| 435 | + if (!in_array($result, self::$ids)) |
|
| 436 | 436 | { |
| 437 | 437 | self::$ids[] = $result; |
| 438 | 438 | return $result; |
@@ -468,12 +468,12 @@ discard block |
||
| 468 | 468 | { |
| 469 | 469 | $targetID = $targetToken->getID(); |
| 470 | 470 | |
| 471 | - foreach($this->tokensOrdered as $idx => $token) |
|
| 471 | + foreach ($this->tokensOrdered as $idx => $token) |
|
| 472 | 472 | { |
| 473 | - if($token->getID() === $targetID) |
|
| 473 | + if ($token->getID() === $targetID) |
|
| 474 | 474 | { |
| 475 | - $prev = $this->tokensOrdered[$idx-1] ?? null; |
|
| 476 | - if($prev instanceof Mailcode_Parser_Statement_Tokenizer_Token_ParamName) |
|
| 475 | + $prev = $this->tokensOrdered[$idx - 1] ?? null; |
|
| 476 | + if ($prev instanceof Mailcode_Parser_Statement_Tokenizer_Token_ParamName) |
|
| 477 | 477 | { |
| 478 | 478 | return $prev; |
| 479 | 479 | } |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | public function injectParamName(Mailcode_Parser_Statement_Tokenizer_Token $targetToken, string $name) : Mailcode_Parser_Statement_Tokenizer_Token_ParamName |
| 498 | 498 | { |
| 499 | 499 | $existing = $this->findNameToken($targetToken); |
| 500 | - if($existing) { |
|
| 500 | + if ($existing) { |
|
| 501 | 501 | $this->removeToken($existing); |
| 502 | 502 | } |
| 503 | 503 | |
@@ -518,9 +518,9 @@ discard block |
||
| 518 | 518 | $tokens = array(); |
| 519 | 519 | $found = false; |
| 520 | 520 | |
| 521 | - foreach($this->tokensOrdered as $token) |
|
| 521 | + foreach ($this->tokensOrdered as $token) |
|
| 522 | 522 | { |
| 523 | - if($token->getID() === $targetID) |
|
| 523 | + if ($token->getID() === $targetID) |
|
| 524 | 524 | { |
| 525 | 525 | $tokens[] = $newToken; |
| 526 | 526 | $found = true; |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | $tokens[] = $token; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - if($found) { |
|
| 532 | + if ($found) { |
|
| 533 | 533 | $this->tokensOrdered = $tokens; |
| 534 | 534 | |
| 535 | 535 | return $this; |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | ); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Creates a new mailcode instance. |
|
| 64 | - * @return Mailcode |
|
| 65 | - */ |
|
| 62 | + /** |
|
| 63 | + * Creates a new mailcode instance. |
|
| 64 | + * @return Mailcode |
|
| 65 | + */ |
|
| 66 | 66 | public static function create() : Mailcode |
| 67 | 67 | { |
| 68 | 68 | return new Mailcode(); |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Parses the string to detect all commands contained within. |
|
| 78 | - * |
|
| 79 | - * @param string $string |
|
| 80 | - * @return Mailcode_Collection |
|
| 81 | - */ |
|
| 77 | + * Parses the string to detect all commands contained within. |
|
| 78 | + * |
|
| 79 | + * @param string $string |
|
| 80 | + * @return Mailcode_Collection |
|
| 81 | + */ |
|
| 82 | 82 | public function parseString(string $string) : Mailcode_Collection |
| 83 | 83 | { |
| 84 | 84 | return $this->getParser() |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | ->getCollection(); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Retrieves the string parser instance used to detect commands. |
|
| 91 | - * |
|
| 92 | - * @return Mailcode_Parser |
|
| 93 | - */ |
|
| 89 | + /** |
|
| 90 | + * Retrieves the string parser instance used to detect commands. |
|
| 91 | + * |
|
| 92 | + * @return Mailcode_Parser |
|
| 93 | + */ |
|
| 94 | 94 | public function getParser() : Mailcode_Parser |
| 95 | 95 | { |
| 96 | 96 | if(!isset($this->parser)) |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | return $this->parser; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Retrieves the commands collection, which is used to |
|
| 106 | - * access information on the available commands. |
|
| 107 | - * |
|
| 108 | - * @return Mailcode_Commands |
|
| 109 | - */ |
|
| 104 | + /** |
|
| 105 | + * Retrieves the commands collection, which is used to |
|
| 106 | + * access information on the available commands. |
|
| 107 | + * |
|
| 108 | + * @return Mailcode_Commands |
|
| 109 | + */ |
|
| 110 | 110 | public function getCommands() : Mailcode_Commands |
| 111 | 111 | { |
| 112 | 112 | if(!isset($this->commands)) |
@@ -149,23 +149,23 @@ discard block |
||
| 149 | 149 | return $this->variables; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Creates the translator, which can be used to convert commands |
|
| 154 | - * to another supported syntax. |
|
| 155 | - * |
|
| 156 | - * @return Mailcode_Translator |
|
| 157 | - */ |
|
| 152 | + /** |
|
| 153 | + * Creates the translator, which can be used to convert commands |
|
| 154 | + * to another supported syntax. |
|
| 155 | + * |
|
| 156 | + * @return Mailcode_Translator |
|
| 157 | + */ |
|
| 158 | 158 | public function createTranslator() : Mailcode_Translator |
| 159 | 159 | { |
| 160 | 160 | return Mailcode_Translator::create(); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * Creates the styler, which can be used to retrieve the |
|
| 165 | - * CSS required to style the highlighted commands in HTML. |
|
| 166 | - * |
|
| 167 | - * @return Mailcode_Styler |
|
| 168 | - */ |
|
| 163 | + /** |
|
| 164 | + * Creates the styler, which can be used to retrieve the |
|
| 165 | + * CSS required to style the highlighted commands in HTML. |
|
| 166 | + * |
|
| 167 | + * @return Mailcode_Styler |
|
| 168 | + */ |
|
| 169 | 169 | public function createStyler() : Mailcode_Styler |
| 170 | 170 | { |
| 171 | 171 | return new Mailcode_Styler(); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public static function getCacheFolder() : FolderInfo |
| 47 | 47 | { |
| 48 | - if(isset(self::$cacheFolder)) { |
|
| 48 | + if (isset(self::$cacheFolder)) { |
|
| 49 | 49 | return self::$cacheFolder; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function getParser() : Mailcode_Parser |
| 95 | 95 | { |
| 96 | - if(!isset($this->parser)) |
|
| 96 | + if (!isset($this->parser)) |
|
| 97 | 97 | { |
| 98 | 98 | $this->parser = new Mailcode_Parser($this); |
| 99 | 99 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function getCommands() : Mailcode_Commands |
| 111 | 111 | { |
| 112 | - if(!isset($this->commands)) |
|
| 112 | + if (!isset($this->commands)) |
|
| 113 | 113 | { |
| 114 | 114 | $this->commands = new Mailcode_Commands(); |
| 115 | 115 | } |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | * @param Mailcode_Commands_Command|null $sourceCommand |
| 135 | 135 | * @return Mailcode_Variables_Collection_Regular |
| 136 | 136 | */ |
| 137 | - public function findVariables(string $subject, ?Mailcode_Commands_Command $sourceCommand=null) : Mailcode_Variables_Collection_Regular |
|
| 137 | + public function findVariables(string $subject, ?Mailcode_Commands_Command $sourceCommand = null) : Mailcode_Variables_Collection_Regular |
|
| 138 | 138 | { |
| 139 | 139 | return $this->createVariables()->parseString($subject, $sourceCommand); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | public function createVariables() : Mailcode_Variables |
| 143 | 143 | { |
| 144 | - if(!isset($this->variables)) |
|
| 144 | + if (!isset($this->variables)) |
|
| 145 | 145 | { |
| 146 | 146 | $this->variables = new Mailcode_Variables(); |
| 147 | 147 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | return self::$logger; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - public static function setDebugging(bool $enabled=true) : void |
|
| 203 | + public static function setDebugging(bool $enabled = true) : void |
|
| 204 | 204 | { |
| 205 | 205 | self::$debug = $enabled; |
| 206 | 206 | } |
@@ -215,9 +215,9 @@ discard block |
||
| 215 | 215 | * @param array<string|int,mixed> $context |
| 216 | 216 | * @return void |
| 217 | 217 | */ |
| 218 | - public static function debug(string $message, array $context=array()) : void |
|
| 218 | + public static function debug(string $message, array $context = array()) : void |
|
| 219 | 219 | { |
| 220 | - if(self::$debug && isset(self::$logger)) |
|
| 220 | + if (self::$debug && isset(self::$logger)) |
|
| 221 | 221 | { |
| 222 | 222 | self::$logger->debug($message, $context); |
| 223 | 223 | } |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | declare(strict_types=1); |
| 14 | 14 | |
| 15 | -use AppUtils\ConvertHelper\JSONConverter;use AppUtils\CSVHelper; |
|
| 16 | -use AppUtils\CSVHelper_Exception;use AppUtils\FileHelper; |
|
| 17 | -use AppUtils\FileHelper_Exception;use libphonenumber\PhoneNumberFormat; |
|
| 18 | -use libphonenumber\PhoneNumberUtil;use Mailcode\Mailcode;use function AppLocalize\pts; |
|
| 15 | +use AppUtils\ConvertHelper\JSONConverter; use AppUtils\CSVHelper; |
|
| 16 | +use AppUtils\CSVHelper_Exception; use AppUtils\FileHelper; |
|
| 17 | +use AppUtils\FileHelper_Exception; use libphonenumber\PhoneNumberFormat; |
|
| 18 | +use libphonenumber\PhoneNumberUtil; use Mailcode\Mailcode; use function AppLocalize\pts; |
|
| 19 | 19 | |
| 20 | 20 | require_once 'prepend.php'; |
| 21 | 21 | |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | $meta = $phoneNumberUtil->getMetadataForRegion($code); |
| 96 | 96 | if (!$meta) { |
| 97 | - die('No metadata for ' . $code); |
|
| 97 | + die('No metadata for '.$code); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $exampleNumber = $phoneNumberUtil->getExampleNumber($code); |
| 101 | 101 | |
| 102 | 102 | // PHPStan complains about this, but the method can return null - it's not documented correctly. |
| 103 | - if($exampleNumber === null) { |
|
| 104 | - die('No example number for ' . $code); |
|
| 103 | + if ($exampleNumber === null) { |
|
| 104 | + die('No example number for '.$code); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $local = $phoneNumberUtil->formatInOriginalFormat($exampleNumber, $code); |