@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | protected function validateSyntax_params_parse() : void |
| 37 | 37 | { |
| 38 | - if(!$this->requiresParameters()) |
|
| 38 | + if (!$this->requiresParameters()) |
|
| 39 | 39 | { |
| 40 | 40 | return; |
| 41 | 41 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $this |
| 47 | 47 | ); |
| 48 | 48 | |
| 49 | - if(!$this->params->isValid()) |
|
| 49 | + if (!$this->params->isValid()) |
|
| 50 | 50 | { |
| 51 | 51 | $error = $this->params->getValidationResult(); |
| 52 | 52 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | private $sourceCommand; |
| 58 | 58 | |
| 59 | - public function __construct(string $statement, bool $freeform=false, ?Mailcode_Commands_Command $sourceCommand=null) |
|
| 59 | + public function __construct(string $statement, bool $freeform = false, ?Mailcode_Commands_Command $sourceCommand = null) |
|
| 60 | 60 | { |
| 61 | 61 | $this->sourceCommand = $sourceCommand; |
| 62 | 62 | $this->statement = $statement; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | public function getInfo() : Mailcode_Parser_Statement_Info |
| 93 | 93 | { |
| 94 | - if($this->info instanceof Mailcode_Parser_Statement_Info) |
|
| 94 | + if ($this->info instanceof Mailcode_Parser_Statement_Info) |
|
| 95 | 95 | { |
| 96 | 96 | return $this->info; |
| 97 | 97 | } |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | protected function validate() : void |
| 105 | 105 | { |
| 106 | - if($this->freeform) |
|
| 106 | + if ($this->freeform) |
|
| 107 | 107 | { |
| 108 | 108 | return; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if(!$this->tokenizer->hasTokens()) |
|
| 111 | + if (!$this->tokenizer->hasTokens()) |
|
| 112 | 112 | { |
| 113 | 113 | $this->result->makeError( |
| 114 | 114 | t('Empty statement'), |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $unknown = $this->tokenizer->getFirstUnknown(); |
| 122 | 122 | |
| 123 | - if($unknown) |
|
| 123 | + if ($unknown) |
|
| 124 | 124 | { |
| 125 | 125 | $this->result->makeError( |
| 126 | 126 | t('Unquoted string literal found:').' ('.htmlspecialchars($unknown->getMatchedText()).')', |
@@ -20,19 +20,19 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | abstract class Mailcode_Parser_Statement_Tokenizer_Token implements Mailcode_Parser_Statement_Tokenizer_TypeInterface |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | 26 | protected $tokenID; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | 31 | protected $matchedText; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var mixed |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var mixed |
|
| 35 | + */ |
|
| 36 | 36 | protected $subject; |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -62,20 +62,20 @@ discard block |
||
| 62 | 62 | return $this->sourceCommand; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * The ID of the type. i.e. the class name ("Keyword", "StringLiteral"). |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 65 | + /** |
|
| 66 | + * The ID of the type. i.e. the class name ("Keyword", "StringLiteral"). |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | 69 | public function getTypeID() : string |
| 70 | 70 | { |
| 71 | 71 | $parts = explode('_', get_class($this)); |
| 72 | 72 | return array_pop($parts); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Retrieves a unique ID of the token. |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 75 | + /** |
|
| 76 | + * Retrieves a unique ID of the token. |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | 79 | public function getID() : string |
| 80 | 80 | { |
| 81 | 81 | return $this->tokenID; |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | * @param mixed $subject |
| 47 | 47 | * @param Mailcode_Commands_Command|null $sourceCommand |
| 48 | 48 | */ |
| 49 | - public function __construct(string $tokenID, string $matchedText, $subject=null, ?Mailcode_Commands_Command $sourceCommand=null) |
|
| 49 | + public function __construct(string $tokenID, string $matchedText, $subject = null, ?Mailcode_Commands_Command $sourceCommand = null) |
|
| 50 | 50 | { |
| 51 | 51 | $this->tokenID = $tokenID; |
| 52 | 52 | $this->matchedText = $matchedText; |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | { |
| 11 | 11 | $vars = Mailcode::create()->findVariables($this->tokenized, $this->tokenizer->getSourceCommand())->getGroupedByHash(); |
| 12 | 12 | |
| 13 | - foreach($vars as $var) |
|
| 13 | + foreach ($vars as $var) |
|
| 14 | 14 | { |
| 15 | 15 | $this->registerToken('Variable', $var->getMatchedText(), $var); |
| 16 | 16 | } |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | 'ExtractTokens' |
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var Mailcode_Parser_Statement |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var Mailcode_Parser_Statement |
|
| 43 | + */ |
|
| 44 | 44 | protected $statement; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | 49 | protected $tokenized; |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | protected $tokensOrdered = array(); |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var string[] |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var string[] |
|
| 58 | + */ |
|
| 59 | 59 | protected static $ids = array(); |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | return $this->statement->getSourceCommand(); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Retrieves all tokens detected in the statement string, in |
|
| 80 | - * the order they were found. |
|
| 81 | - * |
|
| 82 | - * @return Mailcode_Parser_Statement_Tokenizer_Token[] |
|
| 83 | - */ |
|
| 78 | + /** |
|
| 79 | + * Retrieves all tokens detected in the statement string, in |
|
| 80 | + * the order they were found. |
|
| 81 | + * |
|
| 82 | + * @return Mailcode_Parser_Statement_Tokenizer_Token[] |
|
| 83 | + */ |
|
| 84 | 84 | public function getTokens() |
| 85 | 85 | { |
| 86 | 86 | return $this->tokensOrdered; |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | return !empty($this->tokensOrdered); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Whether there were any unknown tokens in the statement. |
|
| 96 | - * |
|
| 97 | - * @return bool |
|
| 98 | - */ |
|
| 94 | + /** |
|
| 95 | + * Whether there were any unknown tokens in the statement. |
|
| 96 | + * |
|
| 97 | + * @return bool |
|
| 98 | + */ |
|
| 99 | 99 | public function hasUnknown() : bool |
| 100 | 100 | { |
| 101 | 101 | $unknown = $this->getUnknown(); |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | return !empty($unknown); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Retrieves all unknown content tokens, if any. |
|
| 108 | - * |
|
| 109 | - * @return Mailcode_Parser_Statement_Tokenizer_Token_Unknown[] |
|
| 110 | - */ |
|
| 106 | + /** |
|
| 107 | + * Retrieves all unknown content tokens, if any. |
|
| 108 | + * |
|
| 109 | + * @return Mailcode_Parser_Statement_Tokenizer_Token_Unknown[] |
|
| 110 | + */ |
|
| 111 | 111 | public function getUnknown() |
| 112 | 112 | { |
| 113 | 113 | $result = array(); |
@@ -278,13 +278,13 @@ discard block |
||
| 278 | 278 | return $token; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Generates a unique alphabet-based ID without numbers |
|
| 283 | - * to use as token name, to avoid conflicts with the |
|
| 284 | - * numbers detection. |
|
| 285 | - * |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 281 | + /** |
|
| 282 | + * Generates a unique alphabet-based ID without numbers |
|
| 283 | + * to use as token name, to avoid conflicts with the |
|
| 284 | + * numbers detection. |
|
| 285 | + * |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | 288 | protected function generateID() : string |
| 289 | 289 | { |
| 290 | 290 | static $alphas; |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | '{\s*([a-z]+)\s+([a-z-]+)\s*:([^}]*)}' |
| 31 | 31 | ); |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var Mailcode |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var Mailcode |
|
| 35 | + */ |
|
| 36 | 36 | protected $mailcode; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var Mailcode_Commands |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var Mailcode_Commands |
|
| 40 | + */ |
|
| 41 | 41 | protected $commands; |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -51,24 +51,24 @@ discard block |
||
| 51 | 51 | $this->commands = $this->mailcode->getCommands(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Gets the regex format string used to detect commands. |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 54 | + /** |
|
| 55 | + * Gets the regex format string used to detect commands. |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | 59 | protected static function getRegex() : string |
| 60 | 60 | { |
| 61 | 61 | return '/'.implode('|', self::COMMAND_REGEX_PARTS).'/sixU'; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Parses a string to detect all commands within. Returns a |
|
| 66 | - * collection instance that contains information on all the |
|
| 67 | - * commands. |
|
| 68 | - * |
|
| 69 | - * @param string $string |
|
| 70 | - * @return Mailcode_Collection A collection with all unique commands found. |
|
| 71 | - */ |
|
| 64 | + /** |
|
| 65 | + * Parses a string to detect all commands within. Returns a |
|
| 66 | + * collection instance that contains information on all the |
|
| 67 | + * commands. |
|
| 68 | + * |
|
| 69 | + * @param string $string |
|
| 70 | + * @return Mailcode_Collection A collection with all unique commands found. |
|
| 71 | + */ |
|
| 72 | 72 | public function parseString(string $string) : Mailcode_Collection |
| 73 | 73 | { |
| 74 | 74 | $collection = new Mailcode_Collection(); |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | return preg_replace('%<style\b[^>]*>(.*?)</style>%six', '', $subject); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Processes a single match found in the string: creates the command, |
|
| 108 | - * and adds it to the collection if it's a valid command, or to the list |
|
| 109 | - * of invalid commands otherwise. |
|
| 110 | - * |
|
| 111 | - * @param Mailcode_Parser_Match $match |
|
| 112 | - * @param Mailcode_Collection $collection |
|
| 113 | - */ |
|
| 106 | + /** |
|
| 107 | + * Processes a single match found in the string: creates the command, |
|
| 108 | + * and adds it to the collection if it's a valid command, or to the list |
|
| 109 | + * of invalid commands otherwise. |
|
| 110 | + * |
|
| 111 | + * @param Mailcode_Parser_Match $match |
|
| 112 | + * @param Mailcode_Collection $collection |
|
| 113 | + */ |
|
| 114 | 114 | protected function processMatch(Mailcode_Parser_Match $match, Mailcode_Collection $collection) : void |
| 115 | 115 | { |
| 116 | 116 | $name = $match->getName(); |
@@ -173,14 +173,14 @@ discard block |
||
| 173 | 173 | throw new Mailcode_Exception('Not a command', '', self::ERROR_NOT_A_COMMAND); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Parses a single regex match: determines which named group |
|
| 178 | - * matches, and retrieves the according information. |
|
| 179 | - * |
|
| 180 | - * @param array[] $matches The regex results array. |
|
| 181 | - * @param int $index The matched index. |
|
| 182 | - * @return Mailcode_Parser_Match |
|
| 183 | - */ |
|
| 176 | + /** |
|
| 177 | + * Parses a single regex match: determines which named group |
|
| 178 | + * matches, and retrieves the according information. |
|
| 179 | + * |
|
| 180 | + * @param array[] $matches The regex results array. |
|
| 181 | + * @param int $index The matched index. |
|
| 182 | + * @return Mailcode_Parser_Match |
|
| 183 | + */ |
|
| 184 | 184 | protected function parseMatch(array $matches, int $index) : Mailcode_Parser_Match |
| 185 | 185 | { |
| 186 | 186 | $name = ''; // the command name, e.g. "showvar" |
@@ -218,14 +218,14 @@ discard block |
||
| 218 | 218 | ); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Creates an instance of the safeguard tool, which |
|
| 223 | - * is used to safeguard commands in a string with placeholders. |
|
| 224 | - * |
|
| 225 | - * @param string $subject The string to use to safeguard commands in. |
|
| 226 | - * @return Mailcode_Parser_Safeguard |
|
| 227 | - * @see Mailcode_Parser_Safeguard |
|
| 228 | - */ |
|
| 221 | + /** |
|
| 222 | + * Creates an instance of the safeguard tool, which |
|
| 223 | + * is used to safeguard commands in a string with placeholders. |
|
| 224 | + * |
|
| 225 | + * @param string $subject The string to use to safeguard commands in. |
|
| 226 | + * @return Mailcode_Parser_Safeguard |
|
| 227 | + * @see Mailcode_Parser_Safeguard |
|
| 228 | + */ |
|
| 229 | 229 | public function createSafeguard(string $subject) : Mailcode_Parser_Safeguard |
| 230 | 230 | { |
| 231 | 231 | return new Mailcode_Parser_Safeguard($this, $subject); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | $total = count($matches[0]); |
| 82 | 82 | |
| 83 | - for($i=0; $i < $total; $i++) |
|
| 83 | + for ($i = 0; $i < $total; $i++) |
|
| 84 | 84 | { |
| 85 | 85 | $match = $this->parseMatch($matches, $i); |
| 86 | 86 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | protected function prepareString(string $subject) : string |
| 96 | 96 | { |
| 97 | - if(!ConvertHelper::isStringHTML($subject)) |
|
| 97 | + if (!ConvertHelper::isStringHTML($subject)) |
|
| 98 | 98 | { |
| 99 | 99 | return $subject; |
| 100 | 100 | } |
@@ -145,17 +145,17 @@ discard block |
||
| 145 | 145 | private function handleNesting(Mailcode_Commands_Command $cmd) : void |
| 146 | 146 | { |
| 147 | 147 | // Set the command's parent from the stack, if any is present. |
| 148 | - if(!empty($this->stack)) |
|
| 148 | + if (!empty($this->stack)) |
|
| 149 | 149 | { |
| 150 | 150 | $cmd->setParent($this->getStackLast()); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Handle opening and closing commands, adding and removing from the stack. |
| 154 | - if($cmd instanceof Mailcode_Commands_Command_Type_Opening) |
|
| 154 | + if ($cmd instanceof Mailcode_Commands_Command_Type_Opening) |
|
| 155 | 155 | { |
| 156 | 156 | $this->stack[] = $cmd; |
| 157 | 157 | } |
| 158 | - else if($cmd instanceof Mailcode_Commands_Command_Type_Closing) |
|
| 158 | + else if ($cmd instanceof Mailcode_Commands_Command_Type_Closing) |
|
| 159 | 159 | { |
| 160 | 160 | array_pop($this->stack); |
| 161 | 161 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $cmd = $this->stack[array_key_last($this->stack)]; |
| 167 | 167 | |
| 168 | - if($cmd instanceof Mailcode_Commands_Command) |
|
| 168 | + if ($cmd instanceof Mailcode_Commands_Command) |
|
| 169 | 169 | { |
| 170 | 170 | return $cmd; |
| 171 | 171 | } |
@@ -194,16 +194,16 @@ discard block |
||
| 194 | 194 | // 5 = parameter type command, type |
| 195 | 195 | // 6 = parameter type command, params |
| 196 | 196 | |
| 197 | - if(!empty($matches[1][$index])) |
|
| 197 | + if (!empty($matches[1][$index])) |
|
| 198 | 198 | { |
| 199 | 199 | $name = $matches[1][$index]; |
| 200 | 200 | } |
| 201 | - else if(!empty($matches[2][$index])) |
|
| 201 | + else if (!empty($matches[2][$index])) |
|
| 202 | 202 | { |
| 203 | 203 | $name = $matches[2][$index]; |
| 204 | 204 | $params = $matches[3][$index]; |
| 205 | 205 | } |
| 206 | - else if(!empty($matches[4][$index])) |
|
| 206 | + else if (!empty($matches[4][$index])) |
|
| 207 | 207 | { |
| 208 | 208 | $name = $matches[4][$index]; |
| 209 | 209 | $type = $matches[5][$index]; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * @param Mailcode_Commands_Command|null $sourceCommand |
| 241 | 241 | * @return Mailcode_Parser_Statement |
| 242 | 242 | */ |
| 243 | - public function createStatement(string $statement, bool $freeform=false, ?Mailcode_Commands_Command $sourceCommand=null) : Mailcode_Parser_Statement |
|
| 243 | + public function createStatement(string $statement, bool $freeform = false, ?Mailcode_Commands_Command $sourceCommand = null) : Mailcode_Parser_Statement |
|
| 244 | 244 | { |
| 245 | 245 | return new Mailcode_Parser_Statement($statement, $freeform, $sourceCommand); |
| 246 | 246 | } |