@@ -32,7 +32,7 @@ |
||
| 32 | 32 | |
| 33 | 33 | public function requiresAdjustment(): bool |
| 34 | 34 | { |
| 35 | - if(!parent::requiresAdjustment()) |
|
| 35 | + if (!parent::requiresAdjustment()) |
|
| 36 | 36 | { |
| 37 | 37 | return false; |
| 38 | 38 | } |
@@ -119,8 +119,7 @@ |
||
| 119 | 119 | if($closing) |
| 120 | 120 | { |
| 121 | 121 | array_pop($stack); |
| 122 | - } |
|
| 123 | - else |
|
| 122 | + } else |
|
| 124 | 123 | { |
| 125 | 124 | $stack[] = $tagName; |
| 126 | 125 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | { |
| 54 | 54 | $pos = $this->getStartPosition(); |
| 55 | 55 | |
| 56 | - if(is_bool($pos)) |
|
| 56 | + if (is_bool($pos)) |
|
| 57 | 57 | { |
| 58 | 58 | return ''; |
| 59 | 59 | } |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | $tagNames = $this->getParentTags(); |
| 77 | 77 | |
| 78 | - foreach($tagNames as $tagName) |
|
| 78 | + foreach ($tagNames as $tagName) |
|
| 79 | 79 | { |
| 80 | - if($this->formatter->isTagExcluded($tagName)) |
|
| 80 | + if ($this->formatter->isTagExcluded($tagName)) |
|
| 81 | 81 | { |
| 82 | 82 | return true; |
| 83 | 83 | } |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | // Create a stack of all direct parent tags of the command. |
| 100 | 100 | // Handles closing tags as well. |
| 101 | 101 | $stack = array(); |
| 102 | - foreach($tags[2] as $idx => $tagName) |
|
| 102 | + foreach ($tags[2] as $idx => $tagName) |
|
| 103 | 103 | { |
| 104 | 104 | $closing = $tags[1][$idx] === '/'; |
| 105 | 105 | |
| 106 | - if($closing) |
|
| 106 | + if ($closing) |
|
| 107 | 107 | { |
| 108 | 108 | array_pop($stack); |
| 109 | 109 | } |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | // This check is easy: if the command is in the attribute |
| 130 | 130 | // of any of the tags, we will find the command marker in there. |
| 131 | - foreach($tags[3] as $attributes) |
|
| 131 | + foreach ($tags[3] as $attributes) |
|
| 132 | 132 | { |
| 133 | - if(strstr($attributes, self::COMMAND_MARKER)) |
|
| 133 | + if (strstr($attributes, self::COMMAND_MARKER)) |
|
| 134 | 134 | { |
| 135 | 135 | return true; |
| 136 | 136 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | private function getTagAncestry() : array |
| 149 | 149 | { |
| 150 | - if($this->ancestryChecked) |
|
| 150 | + if ($this->ancestryChecked) |
|
| 151 | 151 | { |
| 152 | 152 | return $this->tagAncestry; |
| 153 | 153 | } |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | public const COMMAND_MARKER = '__MAILCODE_COMMAND__'; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var boolean |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var boolean |
|
| 29 | + */ |
|
| 30 | 30 | private $ancestryChecked = false; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var array<int,array<int,string>> |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var array<int,array<int,string>> |
|
| 34 | + */ |
|
| 35 | 35 | private $tagAncestry = array(); |
| 36 | 36 | |
| 37 | 37 | protected function init() : void |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | return !$this->isInTagAttributes() && !$this->isInExcludedTag(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Retrieves the part of the subject string that comes |
|
| 48 | - * before the command. |
|
| 49 | - * |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 46 | + /** |
|
| 47 | + * Retrieves the part of the subject string that comes |
|
| 48 | + * before the command. |
|
| 49 | + * |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | 52 | private function getHaystackBefore() : string |
| 53 | 53 | { |
| 54 | 54 | $pos = $this->getStartPosition(); |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | return $this->subject->getSubstr(0, $pos).self::COMMAND_MARKER.'>'; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Whether the command is nested in one of the tags |
|
| 70 | - * that have been added to the list of excluded tags. |
|
| 71 | - * |
|
| 72 | - * @return bool |
|
| 73 | - */ |
|
| 68 | + /** |
|
| 69 | + * Whether the command is nested in one of the tags |
|
| 70 | + * that have been added to the list of excluded tags. |
|
| 71 | + * |
|
| 72 | + * @return bool |
|
| 73 | + */ |
|
| 74 | 74 | protected function isInExcludedTag() : bool |
| 75 | 75 | { |
| 76 | 76 | $tagNames = $this->getParentTags(); |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | return false; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Retrieves a list of the command's parent HTML tags, from |
|
| 91 | - * highest to lowest. |
|
| 92 | - * |
|
| 93 | - * @return string[] |
|
| 94 | - */ |
|
| 89 | + /** |
|
| 90 | + * Retrieves a list of the command's parent HTML tags, from |
|
| 91 | + * highest to lowest. |
|
| 92 | + * |
|
| 93 | + * @return string[] |
|
| 94 | + */ |
|
| 95 | 95 | private function getParentTags() : array |
| 96 | 96 | { |
| 97 | 97 | $tags = $this->getTagAncestry(); |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | return $stack; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Checks whether the command is located within the attributes |
|
| 121 | - * of an HTML tag. |
|
| 122 | - * |
|
| 123 | - * @return bool |
|
| 124 | - */ |
|
| 119 | + /** |
|
| 120 | + * Checks whether the command is located within the attributes |
|
| 121 | + * of an HTML tag. |
|
| 122 | + * |
|
| 123 | + * @return bool |
|
| 124 | + */ |
|
| 125 | 125 | protected function isInTagAttributes() : bool |
| 126 | 126 | { |
| 127 | 127 | $tags = $this->getTagAncestry(); |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | return false; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Retrieves a list of tag names that come as parents |
|
| 144 | - * above the command. |
|
| 145 | - * |
|
| 146 | - * @return array<int,array<int,string>> |
|
| 147 | - */ |
|
| 142 | + /** |
|
| 143 | + * Retrieves a list of tag names that come as parents |
|
| 144 | + * above the command. |
|
| 145 | + * |
|
| 146 | + * @return array<int,array<int,string>> |
|
| 147 | + */ |
|
| 148 | 148 | private function getTagAncestry() : array |
| 149 | 149 | { |
| 150 | 150 | if($this->ancestryChecked) |
@@ -25,11 +25,11 @@ |
||
| 25 | 25 | return PHP_INT_MAX; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Formats the specified string according to the formatter. |
|
| 30 | - * Retrieve the updated string from the string container used |
|
| 31 | - * to create the formatter, or use `getSubjectString()`. |
|
| 32 | - */ |
|
| 28 | + /** |
|
| 29 | + * Formats the specified string according to the formatter. |
|
| 30 | + * Retrieve the updated string from the string container used |
|
| 31 | + * to create the formatter, or use `getSubjectString()`. |
|
| 32 | + */ |
|
| 33 | 33 | public function format() : void |
| 34 | 34 | { |
| 35 | 35 | $locations = $this->resolveLocations(); |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | { |
| 35 | 35 | $locations = $this->resolveLocations(); |
| 36 | 36 | |
| 37 | - foreach($locations as $location) |
|
| 37 | + foreach ($locations as $location) |
|
| 38 | 38 | { |
| 39 | 39 | $location->format(); |
| 40 | 40 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | public function applyFormatting() : void |
| 133 | 133 | { |
| 134 | - if($this->applied) |
|
| 134 | + if ($this->applied) |
|
| 135 | 135 | { |
| 136 | 136 | return; |
| 137 | 137 | } |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | private function applyFormatTypes() : void |
| 148 | 148 | { |
| 149 | - foreach($this->formatters as $formatter) |
|
| 149 | + foreach ($this->formatters as $formatter) |
|
| 150 | 150 | { |
| 151 | - if($formatter instanceof Mailcode_Parser_Safeguard_Formatter_FormatType) |
|
| 151 | + if ($formatter instanceof Mailcode_Parser_Safeguard_Formatter_FormatType) |
|
| 152 | 152 | { |
| 153 | 153 | $formatter->format(); |
| 154 | 154 | } |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | private function applyReplaceTypes() : void |
| 159 | 159 | { |
| 160 | - foreach($this->formatters as $formatter) |
|
| 160 | + foreach ($this->formatters as $formatter) |
|
| 161 | 161 | { |
| 162 | - if($formatter instanceof Mailcode_Parser_Safeguard_Formatter_ReplacerType) |
|
| 162 | + if ($formatter instanceof Mailcode_Parser_Safeguard_Formatter_ReplacerType) |
|
| 163 | 163 | { |
| 164 | 164 | $formatter->replace(); |
| 165 | 165 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | private function validateFormatters() : void |
| 170 | 170 | { |
| 171 | - if(empty($this->formatters)) |
|
| 171 | + if (empty($this->formatters)) |
|
| 172 | 172 | { |
| 173 | 173 | throw new Mailcode_Exception( |
| 174 | 174 | 'No formatters selected', |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | $amount = $this->countReplacers(); |
| 181 | 181 | |
| 182 | - if($amount > 1) |
|
| 182 | + if ($amount > 1) |
|
| 183 | 183 | { |
| 184 | 184 | throw new Mailcode_Exception( |
| 185 | 185 | 'More than one replacer formatter selected', |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // by default, at minimum the normalized formatter must be selected. |
| 192 | - if($amount === 0) |
|
| 192 | + if ($amount === 0) |
|
| 193 | 193 | { |
| 194 | 194 | $this->replaceWithNormalized(); |
| 195 | 195 | } |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | { |
| 205 | 205 | $count = 0; |
| 206 | 206 | |
| 207 | - foreach($this->formatters as $formatter) |
|
| 207 | + foreach ($this->formatters as $formatter) |
|
| 208 | 208 | { |
| 209 | - if($formatter instanceof Mailcode_Parser_Safeguard_Formatter_ReplacerType) |
|
| 209 | + if ($formatter instanceof Mailcode_Parser_Safeguard_Formatter_ReplacerType) |
|
| 210 | 210 | { |
| 211 | 211 | $count++; |
| 212 | 212 | } |
@@ -32,29 +32,29 @@ discard block |
||
| 32 | 32 | public const ERROR_TOO_MANY_REPLACERS = 65902; |
| 33 | 33 | public const ERROR_NO_FORMATTERS_ADDED = 65903; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var Mailcode_Parser_Safeguard |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var Mailcode_Parser_Safeguard |
|
| 37 | + */ |
|
| 38 | 38 | private $safeguard; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var Mailcode_Parser_Safeguard_Formatter[] |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var Mailcode_Parser_Safeguard_Formatter[] |
|
| 42 | + */ |
|
| 43 | 43 | private $formatters = array(); |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var Mailcode_StringContainer |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var Mailcode_StringContainer |
|
| 47 | + */ |
|
| 48 | 48 | private $subject; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var boolean |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var boolean |
|
| 52 | + */ |
|
| 53 | 53 | private $applied = false; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var boolean |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var boolean |
|
| 57 | + */ |
|
| 58 | 58 | private $partial = false; |
| 59 | 59 | |
| 60 | 60 | public function __construct(Mailcode_Parser_Safeguard $safeguard, Mailcode_StringContainer $subject) |
@@ -96,17 +96,17 @@ discard block |
||
| 96 | 96 | return $formatter; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Adds a formatter that will surround all variables with |
|
| 101 | - * markup to highlight them independently of command syntax |
|
| 102 | - * highlighting. |
|
| 103 | - * |
|
| 104 | - * This is used to mark variables visually even after commands |
|
| 105 | - * have been replaced by the target system's post processing. |
|
| 106 | - * Can be combined with a replacer and other formats. |
|
| 107 | - * |
|
| 108 | - * @return Mailcode_Parser_Safeguard_Formatter_Type_MarkVariables |
|
| 109 | - */ |
|
| 99 | + /** |
|
| 100 | + * Adds a formatter that will surround all variables with |
|
| 101 | + * markup to highlight them independently of command syntax |
|
| 102 | + * highlighting. |
|
| 103 | + * |
|
| 104 | + * This is used to mark variables visually even after commands |
|
| 105 | + * have been replaced by the target system's post processing. |
|
| 106 | + * Can be combined with a replacer and other formats. |
|
| 107 | + * |
|
| 108 | + * @return Mailcode_Parser_Safeguard_Formatter_Type_MarkVariables |
|
| 109 | + */ |
|
| 110 | 110 | public function formatWithMarkedVariables() : Mailcode_Parser_Safeguard_Formatter_Type_MarkVariables |
| 111 | 111 | { |
| 112 | 112 | $formatter = $this->createMarkVariables(); |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * Counts the amount of replacer formatters that have been added. |
|
| 205 | - * |
|
| 206 | - * @return int |
|
| 207 | - */ |
|
| 203 | + /** |
|
| 204 | + * Counts the amount of replacer formatters that have been added. |
|
| 205 | + * |
|
| 206 | + * @return int |
|
| 207 | + */ |
|
| 208 | 208 | private function countReplacers() : int |
| 209 | 209 | { |
| 210 | 210 | $count = 0; |
@@ -220,37 +220,37 @@ discard block |
||
| 220 | 220 | return $count; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * Creates a formatter that adds HTML syntax highlighting |
|
| 225 | - * for all commands in the specified string, intelligently |
|
| 226 | - * checking the location of the commands to ensure that they |
|
| 227 | - * can be syntax highlighted. |
|
| 228 | - * |
|
| 229 | - * For example, commands in HTML attributes will not be |
|
| 230 | - * highlighted, as this would break the HTML. |
|
| 231 | - * |
|
| 232 | - * @return Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting |
|
| 233 | - */ |
|
| 223 | + /** |
|
| 224 | + * Creates a formatter that adds HTML syntax highlighting |
|
| 225 | + * for all commands in the specified string, intelligently |
|
| 226 | + * checking the location of the commands to ensure that they |
|
| 227 | + * can be syntax highlighted. |
|
| 228 | + * |
|
| 229 | + * For example, commands in HTML attributes will not be |
|
| 230 | + * highlighted, as this would break the HTML. |
|
| 231 | + * |
|
| 232 | + * @return Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting |
|
| 233 | + */ |
|
| 234 | 234 | public function createHTMLHighlighting() : Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting |
| 235 | 235 | { |
| 236 | 236 | return new Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting($this); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Creates the formatter that ensures that all commands |
|
| 241 | - * are placed on a separate line in the subject string. |
|
| 242 | - */ |
|
| 239 | + /** |
|
| 240 | + * Creates the formatter that ensures that all commands |
|
| 241 | + * are placed on a separate line in the subject string. |
|
| 242 | + */ |
|
| 243 | 243 | public function createSingleLines() : Mailcode_Parser_Safeguard_Formatter_Type_SingleLines |
| 244 | 244 | { |
| 245 | 245 | return new Mailcode_Parser_Safeguard_Formatter_Type_SingleLines($this); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Creates the formatter that replaces all commands by |
|
| 250 | - * their normalized variants. |
|
| 251 | - * |
|
| 252 | - * @return Mailcode_Parser_Safeguard_Formatter_Type_Normalized |
|
| 253 | - */ |
|
| 248 | + /** |
|
| 249 | + * Creates the formatter that replaces all commands by |
|
| 250 | + * their normalized variants. |
|
| 251 | + * |
|
| 252 | + * @return Mailcode_Parser_Safeguard_Formatter_Type_Normalized |
|
| 253 | + */ |
|
| 254 | 254 | public function createNormalized() : Mailcode_Parser_Safeguard_Formatter_Type_Normalized |
| 255 | 255 | { |
| 256 | 256 | return new Mailcode_Parser_Safeguard_Formatter_Type_Normalized($this); |
@@ -278,26 +278,26 @@ discard block |
||
| 278 | 278 | return $this->subject->getString(); |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Whether the formatting is done partially: missing placeholders |
|
| 283 | - * will simply be ignored. |
|
| 284 | - * |
|
| 285 | - * @return bool |
|
| 286 | - */ |
|
| 281 | + /** |
|
| 282 | + * Whether the formatting is done partially: missing placeholders |
|
| 283 | + * will simply be ignored. |
|
| 284 | + * |
|
| 285 | + * @return bool |
|
| 286 | + */ |
|
| 287 | 287 | public function isPartial() : bool |
| 288 | 288 | { |
| 289 | 289 | return $this->partial; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * The formatting will ignore missing placeholders. Use this if the |
|
| 294 | - * formatting will be done on a text that may not contain all of the |
|
| 295 | - * initial placeholders anymore. |
|
| 296 | - * |
|
| 297 | - * This is like the safeguard's makeWholePartial() method. |
|
| 298 | - * |
|
| 299 | - * @return Mailcode_Parser_Safeguard_Formatting |
|
| 300 | - */ |
|
| 292 | + /** |
|
| 293 | + * The formatting will ignore missing placeholders. Use this if the |
|
| 294 | + * formatting will be done on a text that may not contain all of the |
|
| 295 | + * initial placeholders anymore. |
|
| 296 | + * |
|
| 297 | + * This is like the safeguard's makeWholePartial() method. |
|
| 298 | + * |
|
| 299 | + * @return Mailcode_Parser_Safeguard_Formatting |
|
| 300 | + */ |
|
| 301 | 301 | public function makePartial() : Mailcode_Parser_Safeguard_Formatting |
| 302 | 302 | { |
| 303 | 303 | $this->partial = true; |
@@ -260,8 +260,7 @@ |
||
| 260 | 260 | if($highlighted) |
| 261 | 261 | { |
| 262 | 262 | $formatting->replaceWithHTMLHighlighting(); |
| 263 | - } |
|
| 264 | - else |
|
| 263 | + } else |
|
| 265 | 264 | { |
| 266 | 265 | $formatting->replaceWithNormalized(); |
| 267 | 266 | } |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $placeholders = $this->getPlaceholders(); |
| 181 | 181 | $string = $this->originalString; |
| 182 | 182 | |
| 183 | - foreach($placeholders as $placeholder) |
|
| 183 | + foreach ($placeholders as $placeholder) |
|
| 184 | 184 | { |
| 185 | 185 | $string = $this->makePlaceholderSafe($string, $placeholder); |
| 186 | 186 | } |
@@ -210,14 +210,14 @@ discard block |
||
| 210 | 210 | $placeholders = $this->getPlaceholders(); |
| 211 | 211 | $total = count($placeholders); |
| 212 | 212 | |
| 213 | - for($i=0; $i < $total; $i++) |
|
| 213 | + for ($i = 0; $i < $total; $i++) |
|
| 214 | 214 | { |
| 215 | 215 | $placeholder = $placeholders[$i]; |
| 216 | 216 | $command = $placeholder->getCommand(); |
| 217 | 217 | |
| 218 | - if($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
| 218 | + if ($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
| 219 | 219 | { |
| 220 | - $string = $command->protectContent($string, $placeholder, $placeholders[$i+1]); |
|
| 220 | + $string = $command->protectContent($string, $placeholder, $placeholders[$i + 1]); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | { |
| 229 | 229 | $pos = mb_strpos($string, $placeholder->getOriginalText()); |
| 230 | 230 | |
| 231 | - if($pos === false) |
|
| 231 | + if ($pos === false) |
|
| 232 | 232 | { |
| 233 | 233 | throw new Mailcode_Exception( |
| 234 | 234 | 'Placeholder original text not found', |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting |
| 269 | 269 | { |
| 270 | - if(is_string($subject)) |
|
| 270 | + if (is_string($subject)) |
|
| 271 | 271 | { |
| 272 | 272 | $subject = Mailcode::create()->createString($subject); |
| 273 | 273 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | public function getPlaceholders() |
| 285 | 285 | { |
| 286 | - if(isset($this->placeholders)) |
|
| 286 | + if (isset($this->placeholders)) |
|
| 287 | 287 | { |
| 288 | 288 | return $this->placeholders; |
| 289 | 289 | } |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | $cmds = $this->getCollection()->getCommands(); |
| 294 | 294 | |
| 295 | - foreach($cmds as $command) |
|
| 295 | + foreach ($cmds as $command) |
|
| 296 | 296 | { |
| 297 | 297 | self::$counter++; |
| 298 | 298 | |
@@ -313,21 +313,21 @@ discard block |
||
| 313 | 313 | * @return string |
| 314 | 314 | * @throws Mailcode_Exception |
| 315 | 315 | */ |
| 316 | - protected function restore(string $string, bool $partial=false, bool $highlighted=false) : string |
|
| 316 | + protected function restore(string $string, bool $partial = false, bool $highlighted = false) : string |
|
| 317 | 317 | { |
| 318 | - if(!$partial) |
|
| 318 | + if (!$partial) |
|
| 319 | 319 | { |
| 320 | 320 | $this->requireValidCollection(); |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | $formatting = $this->createFormatting($string); |
| 324 | 324 | |
| 325 | - if($partial) |
|
| 325 | + if ($partial) |
|
| 326 | 326 | { |
| 327 | 327 | $formatting->makePartial(); |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if($highlighted) |
|
| 330 | + if ($highlighted) |
|
| 331 | 331 | { |
| 332 | 332 | $formatting->replaceWithHTMLHighlighting(); |
| 333 | 333 | } |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | { |
| 348 | 348 | $command = $placeholder->getCommand(); |
| 349 | 349 | |
| 350 | - if($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
| 350 | + if ($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
| 351 | 351 | { |
| 352 | 352 | $string = $command->restoreContent($string); |
| 353 | 353 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | public function getCollection() : Mailcode_Collection |
| 442 | 442 | { |
| 443 | - if(isset($this->collection)) |
|
| 443 | + if (isset($this->collection)) |
|
| 444 | 444 | { |
| 445 | 445 | return $this->collection; |
| 446 | 446 | } |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | protected function requireValidCollection() : void |
| 464 | 464 | { |
| 465 | - if($this->getCollection()->isValid()) |
|
| 465 | + if ($this->getCollection()->isValid()) |
|
| 466 | 466 | { |
| 467 | 467 | return; |
| 468 | 468 | } |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | */ |
| 486 | 486 | public function getPlaceholderStrings() : array |
| 487 | 487 | { |
| 488 | - if(is_array($this->placeholderStrings)) |
|
| 488 | + if (is_array($this->placeholderStrings)) |
|
| 489 | 489 | { |
| 490 | 490 | return $this->placeholderStrings; |
| 491 | 491 | } |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | |
| 495 | 495 | $this->placeholderStrings = array(); |
| 496 | 496 | |
| 497 | - foreach($placeholders as $placeholder) |
|
| 497 | + foreach ($placeholders as $placeholder) |
|
| 498 | 498 | { |
| 499 | 499 | $this->placeholderStrings[] = $placeholder->getReplacementText(); |
| 500 | 500 | } |
@@ -520,9 +520,9 @@ discard block |
||
| 520 | 520 | { |
| 521 | 521 | $placeholders = $this->getPlaceholders(); |
| 522 | 522 | |
| 523 | - foreach($placeholders as $placeholder) |
|
| 523 | + foreach ($placeholders as $placeholder) |
|
| 524 | 524 | { |
| 525 | - if($placeholder->getID() === $id) |
|
| 525 | + if ($placeholder->getID() === $id) |
|
| 526 | 526 | { |
| 527 | 527 | return $placeholder; |
| 528 | 528 | } |
@@ -549,9 +549,9 @@ discard block |
||
| 549 | 549 | { |
| 550 | 550 | $placeholders = $this->getPlaceholders(); |
| 551 | 551 | |
| 552 | - foreach($placeholders as $placeholder) |
|
| 552 | + foreach ($placeholders as $placeholder) |
|
| 553 | 553 | { |
| 554 | - if($placeholder->getReplacementText() === $string) |
|
| 554 | + if ($placeholder->getReplacementText() === $string) |
|
| 555 | 555 | { |
| 556 | 556 | return $placeholder; |
| 557 | 557 | } |
@@ -52,45 +52,45 @@ discard block |
||
| 52 | 52 | public const ERROR_INVALID_COMMANDS = 47801; |
| 53 | 53 | public const ERROR_PLACEHOLDER_NOT_FOUND = 47804; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var Mailcode_Parser |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var Mailcode_Parser |
|
| 57 | + */ |
|
| 58 | 58 | protected $parser; |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var Mailcode_Collection |
|
| 62 | - */ |
|
| 60 | + /** |
|
| 61 | + * @var Mailcode_Collection |
|
| 62 | + */ |
|
| 63 | 63 | protected $commands; |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var string |
|
| 67 | - */ |
|
| 65 | + /** |
|
| 66 | + * @var string |
|
| 67 | + */ |
|
| 68 | 68 | protected $originalString; |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @var Mailcode_Collection |
|
| 72 | - */ |
|
| 70 | + /** |
|
| 71 | + * @var Mailcode_Collection |
|
| 72 | + */ |
|
| 73 | 73 | protected $collection; |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Counter for the placeholders, global for all placeholders. |
|
| 77 | - * @var integer |
|
| 78 | - */ |
|
| 75 | + /** |
|
| 76 | + * Counter for the placeholders, global for all placeholders. |
|
| 77 | + * @var integer |
|
| 78 | + */ |
|
| 79 | 79 | private static $counter = 0; |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @var Mailcode_Parser_Safeguard_Placeholder[] |
|
| 83 | - */ |
|
| 81 | + /** |
|
| 82 | + * @var Mailcode_Parser_Safeguard_Placeholder[] |
|
| 83 | + */ |
|
| 84 | 84 | protected $placeholders; |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @var string |
|
| 88 | - */ |
|
| 86 | + /** |
|
| 87 | + * @var string |
|
| 88 | + */ |
|
| 89 | 89 | protected $delimiter = '999'; |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @var string[]|NULL |
|
| 93 | - */ |
|
| 91 | + /** |
|
| 92 | + * @var string[]|NULL |
|
| 93 | + */ |
|
| 94 | 94 | protected $placeholderStrings; |
| 95 | 95 | |
| 96 | 96 | public function __construct(Mailcode_Parser $parser, string $subject) |
@@ -109,28 +109,28 @@ discard block |
||
| 109 | 109 | self::$counter = 0; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Retrieves the string the safeguard was created for. |
|
| 114 | - * |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 112 | + /** |
|
| 113 | + * Retrieves the string the safeguard was created for. |
|
| 114 | + * |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | 117 | public function getOriginalString() : string |
| 118 | 118 | { |
| 119 | 119 | return $this->originalString; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Sets the delimiter character sequence used to prepend |
|
| 124 | - * and append to the placeholders. |
|
| 125 | - * |
|
| 126 | - * The delimiter's default is "999". |
|
| 127 | - * |
|
| 128 | - * Minimum characters: 2 |
|
| 129 | - * Invalid characters: Any characters that get URL encoded |
|
| 130 | - * |
|
| 131 | - * @param string $delimiter |
|
| 132 | - * @return Mailcode_Parser_Safeguard |
|
| 133 | - */ |
|
| 122 | + /** |
|
| 123 | + * Sets the delimiter character sequence used to prepend |
|
| 124 | + * and append to the placeholders. |
|
| 125 | + * |
|
| 126 | + * The delimiter's default is "999". |
|
| 127 | + * |
|
| 128 | + * Minimum characters: 2 |
|
| 129 | + * Invalid characters: Any characters that get URL encoded |
|
| 130 | + * |
|
| 131 | + * @param string $delimiter |
|
| 132 | + * @return Mailcode_Parser_Safeguard |
|
| 133 | + */ |
|
| 134 | 134 | public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard |
| 135 | 135 | { |
| 136 | 136 | $validator = new Mailcode_Parser_Safeguard_DelimiterValidator($delimiter); |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | return $this->delimiter; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Retrieves the safe string in which all commands have been replaced |
|
| 151 | - * by placeholder strings. |
|
| 152 | - * |
|
| 153 | - * @return string |
|
| 154 | - * @throws Mailcode_Exception |
|
| 155 | - * |
|
| 156 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 157 | - */ |
|
| 149 | + /** |
|
| 150 | + * Retrieves the safe string in which all commands have been replaced |
|
| 151 | + * by placeholder strings. |
|
| 152 | + * |
|
| 153 | + * @return string |
|
| 154 | + * @throws Mailcode_Exception |
|
| 155 | + * |
|
| 156 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 157 | + */ |
|
| 158 | 158 | public function makeSafe() : string |
| 159 | 159 | { |
| 160 | 160 | $this->requireValidCollection(); |
@@ -162,16 +162,16 @@ discard block |
||
| 162 | 162 | return $this->makeSafePartial(); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Like makeSafe(), but allows partial (invalid) commands: use this |
|
| 167 | - * if the subject string may contain only part of the whole set of |
|
| 168 | - * commands. |
|
| 169 | - * |
|
| 170 | - * Example: parsing a text with an opening if statement, without the |
|
| 171 | - * matching end statement. |
|
| 172 | - * |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 165 | + /** |
|
| 166 | + * Like makeSafe(), but allows partial (invalid) commands: use this |
|
| 167 | + * if the subject string may contain only part of the whole set of |
|
| 168 | + * commands. |
|
| 169 | + * |
|
| 170 | + * Example: parsing a text with an opening if statement, without the |
|
| 171 | + * matching end statement. |
|
| 172 | + * |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | 175 | public function makeSafePartial() : string |
| 176 | 176 | { |
| 177 | 177 | $placeholders = $this->getPlaceholders(); |
@@ -255,13 +255,13 @@ discard block |
||
| 255 | 255 | $analyzer->analyze(); |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * Creates a formatting handler, which can be used to specify |
|
| 260 | - * which formattings to use for the commands in the subject string. |
|
| 261 | - * |
|
| 262 | - * @param Mailcode_StringContainer|string $subject |
|
| 263 | - * @return Mailcode_Parser_Safeguard_Formatting |
|
| 264 | - */ |
|
| 258 | + /** |
|
| 259 | + * Creates a formatting handler, which can be used to specify |
|
| 260 | + * which formattings to use for the commands in the subject string. |
|
| 261 | + * |
|
| 262 | + * @param Mailcode_StringContainer|string $subject |
|
| 263 | + * @return Mailcode_Parser_Safeguard_Formatting |
|
| 264 | + */ |
|
| 265 | 265 | public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting |
| 266 | 266 | { |
| 267 | 267 | if(is_string($subject)) |
@@ -272,12 +272,12 @@ discard block |
||
| 272 | 272 | return new Mailcode_Parser_Safeguard_Formatting($this, $subject); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Retrieves all placeholders that have to be added to |
|
| 277 | - * the subject text. |
|
| 278 | - * |
|
| 279 | - * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[] |
|
| 280 | - */ |
|
| 275 | + /** |
|
| 276 | + * Retrieves all placeholders that have to be added to |
|
| 277 | + * the subject text. |
|
| 278 | + * |
|
| 279 | + * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[] |
|
| 280 | + */ |
|
| 281 | 281 | public function getPlaceholders() |
| 282 | 282 | { |
| 283 | 283 | if(isset($this->placeholders)) |
@@ -353,16 +353,16 @@ discard block |
||
| 353 | 353 | return $string; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - /** |
|
| 357 | - * Makes the string whole again after transforming or filtering it, |
|
| 358 | - * by replacing the command placeholders with the original commands. |
|
| 359 | - * |
|
| 360 | - * @param string $string |
|
| 361 | - * @return string |
|
| 362 | - * @throws Mailcode_Exception |
|
| 363 | - * |
|
| 364 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 365 | - */ |
|
| 356 | + /** |
|
| 357 | + * Makes the string whole again after transforming or filtering it, |
|
| 358 | + * by replacing the command placeholders with the original commands. |
|
| 359 | + * |
|
| 360 | + * @param string $string |
|
| 361 | + * @return string |
|
| 362 | + * @throws Mailcode_Exception |
|
| 363 | + * |
|
| 364 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 365 | + */ |
|
| 366 | 366 | public function makeWhole(string $string) : string |
| 367 | 367 | { |
| 368 | 368 | return $this->restore( |
@@ -372,15 +372,15 @@ discard block |
||
| 372 | 372 | ); |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * Like `makeWhole()`, but ignores missing command placeholders. |
|
| 377 | - * |
|
| 378 | - * @param string $string |
|
| 379 | - * @return string |
|
| 380 | - * @throws Mailcode_Exception |
|
| 381 | - * |
|
| 382 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 383 | - */ |
|
| 375 | + /** |
|
| 376 | + * Like `makeWhole()`, but ignores missing command placeholders. |
|
| 377 | + * |
|
| 378 | + * @param string $string |
|
| 379 | + * @return string |
|
| 380 | + * @throws Mailcode_Exception |
|
| 381 | + * |
|
| 382 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 383 | + */ |
|
| 384 | 384 | public function makeWholePartial(string $string) : string |
| 385 | 385 | { |
| 386 | 386 | return $this->restore( |
@@ -390,19 +390,19 @@ discard block |
||
| 390 | 390 | ); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - /** |
|
| 394 | - * Like `makeWhole()`, but replaces the commands with a syntax |
|
| 395 | - * highlighted version, meant for human readable texts only. |
|
| 396 | - * |
|
| 397 | - * Note: the commands lose their functionality (They cannot be |
|
| 398 | - * parsed from that string again). |
|
| 399 | - * |
|
| 400 | - * @param string $string |
|
| 401 | - * @return string |
|
| 402 | - * @throws Mailcode_Exception |
|
| 403 | - * |
|
| 404 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 405 | - */ |
|
| 393 | + /** |
|
| 394 | + * Like `makeWhole()`, but replaces the commands with a syntax |
|
| 395 | + * highlighted version, meant for human readable texts only. |
|
| 396 | + * |
|
| 397 | + * Note: the commands lose their functionality (They cannot be |
|
| 398 | + * parsed from that string again). |
|
| 399 | + * |
|
| 400 | + * @param string $string |
|
| 401 | + * @return string |
|
| 402 | + * @throws Mailcode_Exception |
|
| 403 | + * |
|
| 404 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 405 | + */ |
|
| 406 | 406 | public function makeHighlighted(string $string) : string |
| 407 | 407 | { |
| 408 | 408 | return $this->restore( |
@@ -412,15 +412,15 @@ discard block |
||
| 412 | 412 | ); |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - /** |
|
| 416 | - * Like `makeHighlighted()`, but ignores missing command placeholders. |
|
| 417 | - * |
|
| 418 | - * @param string $string |
|
| 419 | - * @return string |
|
| 420 | - * @throws Mailcode_Exception |
|
| 421 | - * |
|
| 422 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 423 | - */ |
|
| 415 | + /** |
|
| 416 | + * Like `makeHighlighted()`, but ignores missing command placeholders. |
|
| 417 | + * |
|
| 418 | + * @param string $string |
|
| 419 | + * @return string |
|
| 420 | + * @throws Mailcode_Exception |
|
| 421 | + * |
|
| 422 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 423 | + */ |
|
| 424 | 424 | public function makeHighlightedPartial(string $string) : string |
| 425 | 425 | { |
| 426 | 426 | return $this->restore( |
@@ -430,11 +430,11 @@ discard block |
||
| 430 | 430 | ); |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - /** |
|
| 434 | - * Retrieves the commands collection contained in the string. |
|
| 435 | - * |
|
| 436 | - * @return Mailcode_Collection |
|
| 437 | - */ |
|
| 433 | + /** |
|
| 434 | + * Retrieves the commands collection contained in the string. |
|
| 435 | + * |
|
| 436 | + * @return Mailcode_Collection |
|
| 437 | + */ |
|
| 438 | 438 | public function getCollection() : Mailcode_Collection |
| 439 | 439 | { |
| 440 | 440 | if(isset($this->collection)) |
@@ -452,11 +452,11 @@ discard block |
||
| 452 | 452 | return $this->getCollection()->isValid(); |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - /** |
|
| 456 | - * @throws Mailcode_Exception |
|
| 457 | - * |
|
| 458 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 459 | - */ |
|
| 455 | + /** |
|
| 456 | + * @throws Mailcode_Exception |
|
| 457 | + * |
|
| 458 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 459 | + */ |
|
| 460 | 460 | protected function requireValidCollection() : void |
| 461 | 461 | { |
| 462 | 462 | if($this->getCollection()->isValid()) |
@@ -479,11 +479,11 @@ discard block |
||
| 479 | 479 | throw $exception; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - /** |
|
| 483 | - * Retrieves a list of all placeholder IDs used in the text. |
|
| 484 | - * |
|
| 485 | - * @return string[] |
|
| 486 | - */ |
|
| 482 | + /** |
|
| 483 | + * Retrieves a list of all placeholder IDs used in the text. |
|
| 484 | + * |
|
| 485 | + * @return string[] |
|
| 486 | + */ |
|
| 487 | 487 | public function getPlaceholderStrings() : array |
| 488 | 488 | { |
| 489 | 489 | if(is_array($this->placeholderStrings)) |
@@ -510,13 +510,13 @@ discard block |
||
| 510 | 510 | return in_array($subject, $ids, true); |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - /** |
|
| 514 | - * Retrieves a placeholder instance by its ID. |
|
| 515 | - * |
|
| 516 | - * @param int $id |
|
| 517 | - * @throws Mailcode_Exception If the placeholder was not found. |
|
| 518 | - * @return Mailcode_Parser_Safeguard_Placeholder |
|
| 519 | - */ |
|
| 513 | + /** |
|
| 514 | + * Retrieves a placeholder instance by its ID. |
|
| 515 | + * |
|
| 516 | + * @param int $id |
|
| 517 | + * @throws Mailcode_Exception If the placeholder was not found. |
|
| 518 | + * @return Mailcode_Parser_Safeguard_Placeholder |
|
| 519 | + */ |
|
| 520 | 520 | public function getPlaceholderByID(int $id) : Mailcode_Parser_Safeguard_Placeholder |
| 521 | 521 | { |
| 522 | 522 | $placeholders = $this->getPlaceholders(); |
@@ -539,13 +539,13 @@ discard block |
||
| 539 | 539 | ); |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - /** |
|
| 543 | - * Retrieves a placeholder instance by its replacement text. |
|
| 544 | - * |
|
| 545 | - * @param string $string |
|
| 546 | - * @throws Mailcode_Exception |
|
| 547 | - * @return Mailcode_Parser_Safeguard_Placeholder |
|
| 548 | - */ |
|
| 542 | + /** |
|
| 543 | + * Retrieves a placeholder instance by its replacement text. |
|
| 544 | + * |
|
| 545 | + * @param string $string |
|
| 546 | + * @throws Mailcode_Exception |
|
| 547 | + * @return Mailcode_Parser_Safeguard_Placeholder |
|
| 548 | + */ |
|
| 549 | 549 | public function getPlaceholderByString(string $string) : Mailcode_Parser_Safeguard_Placeholder |
| 550 | 550 | { |
| 551 | 551 | $placeholders = $this->getPlaceholders(); |
@@ -88,12 +88,12 @@ discard block |
||
| 88 | 88 | public function updateString(string $subject) : bool |
| 89 | 89 | { |
| 90 | 90 | // avoid triggering an update if there are no changes in the string |
| 91 | - if($subject === $this->subject) |
|
| 91 | + if ($subject === $this->subject) |
|
| 92 | 92 | { |
| 93 | 93 | return false; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if($this->updating) |
|
| 96 | + if ($this->updating) |
|
| 97 | 97 | { |
| 98 | 98 | throw new Mailcode_Exception( |
| 99 | 99 | 'Cannot modify subject string during update', |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $this->subject = $subject; |
| 108 | 108 | $this->length = mb_strlen($this->subject); |
| 109 | 109 | |
| 110 | - foreach($this->listeners as $listener) |
|
| 110 | + foreach ($this->listeners as $listener) |
|
| 111 | 111 | { |
| 112 | 112 | $listener($this); |
| 113 | 113 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | { |
| 143 | 143 | self::$listenerCounter++; |
| 144 | 144 | |
| 145 | - if(!is_callable($callback)) |
|
| 145 | + if (!is_callable($callback)) |
|
| 146 | 146 | { |
| 147 | 147 | throw new Mailcode_Exception( |
| 148 | 148 | 'Not a valid callable', |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function removeListener(int $listenerID) : void |
| 174 | 174 | { |
| 175 | - if(isset($this->listeners[$listenerID])) |
|
| 175 | + if (isset($this->listeners[$listenerID])) |
|
| 176 | 176 | { |
| 177 | 177 | unset($this->listeners[$listenerID]); |
| 178 | 178 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | return mb_strpos($this->subject, $needle); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - public function getSubstr(int $start, ?int $length=null) : string |
|
| 206 | + public function getSubstr(int $start, ?int $length = null) : string |
|
| 207 | 207 | { |
| 208 | 208 | return mb_substr($this->subject, $start, $length); |
| 209 | 209 | } |
@@ -26,39 +26,39 @@ discard block |
||
| 26 | 26 | public const ERROR_INVALID_CALLABLE = 65701; |
| 27 | 27 | public const ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION = 65702; |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | 32 | private $subject; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var integer |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var integer |
|
| 36 | + */ |
|
| 37 | 37 | private static $listenerCounter = 0; |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var callable[] |
|
| 41 | - */ |
|
| 39 | + /** |
|
| 40 | + * @var callable[] |
|
| 41 | + */ |
|
| 42 | 42 | private $listeners = array(); |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var boolean |
|
| 46 | - */ |
|
| 44 | + /** |
|
| 45 | + * @var boolean |
|
| 46 | + */ |
|
| 47 | 47 | private $updating = false; |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var integer |
|
| 51 | - */ |
|
| 49 | + /** |
|
| 50 | + * @var integer |
|
| 51 | + */ |
|
| 52 | 52 | private static $idCounter = 0; |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var integer |
|
| 56 | - */ |
|
| 54 | + /** |
|
| 55 | + * @var integer |
|
| 56 | + */ |
|
| 57 | 57 | private $id; |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var integer |
|
| 61 | - */ |
|
| 59 | + /** |
|
| 60 | + * @var integer |
|
| 61 | + */ |
|
| 62 | 62 | private $length; |
| 63 | 63 | |
| 64 | 64 | public function __construct(string $subject) |
@@ -75,16 +75,16 @@ discard block |
||
| 75 | 75 | return $this->id; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Updates the string with the specified string. |
|
| 80 | - * Notifies all listeners of the change. |
|
| 81 | - * |
|
| 82 | - * @param string $subject |
|
| 83 | - * @throws Mailcode_Exception |
|
| 84 | - * @return bool Whether the string had modifications. |
|
| 85 | - * |
|
| 86 | - * @see Mailcode_StringContainer::ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION |
|
| 87 | - */ |
|
| 78 | + /** |
|
| 79 | + * Updates the string with the specified string. |
|
| 80 | + * Notifies all listeners of the change. |
|
| 81 | + * |
|
| 82 | + * @param string $subject |
|
| 83 | + * @throws Mailcode_Exception |
|
| 84 | + * @return bool Whether the string had modifications. |
|
| 85 | + * |
|
| 86 | + * @see Mailcode_StringContainer::ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION |
|
| 87 | + */ |
|
| 88 | 88 | public function updateString(string $subject) : bool |
| 89 | 89 | { |
| 90 | 90 | // avoid triggering an update if there are no changes in the string |
@@ -117,27 +117,27 @@ discard block |
||
| 117 | 117 | return true; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Retrieves the stored string. |
|
| 122 | - * |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 120 | + /** |
|
| 121 | + * Retrieves the stored string. |
|
| 122 | + * |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | 125 | public function getString() : string |
| 126 | 126 | { |
| 127 | 127 | return $this->subject; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Adds a listener that will be informed every time the string is modified. |
|
| 132 | - * The callback gets the string container instance as parameter. |
|
| 133 | - * |
|
| 134 | - * @param callable $callback |
|
| 135 | - * @throws Mailcode_Exception If it is not a valid callable. |
|
| 136 | - * @return int The listener number, to be able to remove it using `removeListener()`. |
|
| 137 | - * |
|
| 138 | - * @see Mailcode_StringContainer::removeListener() |
|
| 139 | - * @see Mailcode_StringContainer::ERROR_INVALID_CALLABLE |
|
| 140 | - */ |
|
| 130 | + /** |
|
| 131 | + * Adds a listener that will be informed every time the string is modified. |
|
| 132 | + * The callback gets the string container instance as parameter. |
|
| 133 | + * |
|
| 134 | + * @param callable $callback |
|
| 135 | + * @throws Mailcode_Exception If it is not a valid callable. |
|
| 136 | + * @return int The listener number, to be able to remove it using `removeListener()`. |
|
| 137 | + * |
|
| 138 | + * @see Mailcode_StringContainer::removeListener() |
|
| 139 | + * @see Mailcode_StringContainer::ERROR_INVALID_CALLABLE |
|
| 140 | + */ |
|
| 141 | 141 | public function addListener($callback) : int |
| 142 | 142 | { |
| 143 | 143 | self::$listenerCounter++; |
@@ -164,12 +164,12 @@ discard block |
||
| 164 | 164 | return $this->length; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Removes an existing listener by its ID. |
|
| 169 | - * Has no effect if it does not exist, or has already been removed. |
|
| 170 | - * |
|
| 171 | - * @param int $listenerID |
|
| 172 | - */ |
|
| 167 | + /** |
|
| 168 | + * Removes an existing listener by its ID. |
|
| 169 | + * Has no effect if it does not exist, or has already been removed. |
|
| 170 | + * |
|
| 171 | + * @param int $listenerID |
|
| 172 | + */ |
|
| 173 | 173 | public function removeListener(int $listenerID) : void |
| 174 | 174 | { |
| 175 | 175 | if(isset($this->listeners[$listenerID])) |
@@ -178,13 +178,13 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Replaces all substrings matching needle with the replacement text. |
|
| 183 | - * |
|
| 184 | - * @param string $needle |
|
| 185 | - * @param string $replacement |
|
| 186 | - * @return bool |
|
| 187 | - */ |
|
| 181 | + /** |
|
| 182 | + * Replaces all substrings matching needle with the replacement text. |
|
| 183 | + * |
|
| 184 | + * @param string $needle |
|
| 185 | + * @param string $replacement |
|
| 186 | + * @return bool |
|
| 187 | + */ |
|
| 188 | 188 | public function replaceSubstrings(string $needle, string $replacement) : bool |
| 189 | 189 | { |
| 190 | 190 | $string = str_replace($needle, $replacement, $this->subject); |
@@ -192,12 +192,12 @@ discard block |
||
| 192 | 192 | return $this->updateString($string); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Get the position of a substring in the string. |
|
| 197 | - * |
|
| 198 | - * @param string $needle |
|
| 199 | - * @return int|bool The zero-based position, or false if not found. |
|
| 200 | - */ |
|
| 195 | + /** |
|
| 196 | + * Get the position of a substring in the string. |
|
| 197 | + * |
|
| 198 | + * @param string $needle |
|
| 199 | + * @return int|bool The zero-based position, or false if not found. |
|
| 200 | + */ |
|
| 201 | 201 | public function getSubstrPosition(string $needle) |
| 202 | 202 | { |
| 203 | 203 | return mb_strpos($this->subject, $needle); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | $instance = new $class($this, $placeholder); |
| 79 | 79 | |
| 80 | - if($instance instanceof Mailcode_Parser_Safeguard_Formatter_Location) |
|
| 80 | + if ($instance instanceof Mailcode_Parser_Safeguard_Formatter_Location) |
|
| 81 | 81 | { |
| 82 | 82 | return $instance; |
| 83 | 83 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | $result = array(); |
| 107 | 107 | |
| 108 | - foreach($placeholders as $placeholder) |
|
| 108 | + foreach ($placeholders as $placeholder) |
|
| 109 | 109 | { |
| 110 | 110 | $result[] = $this->createLocation($placeholder); |
| 111 | 111 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | { |
| 124 | 124 | $eol = ConvertHelper::detectEOLCharacter($subject); |
| 125 | 125 | |
| 126 | - if($eol) |
|
| 126 | + if ($eol) |
|
| 127 | 127 | { |
| 128 | 128 | $this->log(sprintf( |
| 129 | 129 | 'Detected EOL character: %s.', |
@@ -27,19 +27,19 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | public const ERROR_INVALID_LOCATION_INSTANCE = 65601; |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var Mailcode_Parser_Safeguard_Formatting |
|
| 32 | - */ |
|
| 30 | + /** |
|
| 31 | + * @var Mailcode_Parser_Safeguard_Formatting |
|
| 32 | + */ |
|
| 33 | 33 | protected $formatting; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var Mailcode_StringContainer |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var Mailcode_StringContainer |
|
| 37 | + */ |
|
| 38 | 38 | protected $subject; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string[] |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var string[] |
|
| 42 | + */ |
|
| 43 | 43 | protected $log = array(); |
| 44 | 44 | |
| 45 | 45 | public function __construct(Mailcode_Parser_Safeguard_Formatting $formatting) |
@@ -98,12 +98,12 @@ discard block |
||
| 98 | 98 | ); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Retrieves all formatter-specific placeholder locations |
|
| 103 | - * in the subject string. |
|
| 104 | - * |
|
| 105 | - * @return Mailcode_Parser_Safeguard_Formatter_Location[] |
|
| 106 | - */ |
|
| 101 | + /** |
|
| 102 | + * Retrieves all formatter-specific placeholder locations |
|
| 103 | + * in the subject string. |
|
| 104 | + * |
|
| 105 | + * @return Mailcode_Parser_Safeguard_Formatter_Location[] |
|
| 106 | + */ |
|
| 107 | 107 | protected function resolveLocations() : array |
| 108 | 108 | { |
| 109 | 109 | $placeholders = $this->formatting->getSafeguard()->getPlaceholders(); |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | return $result; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Resolves the newline character used in the string. |
|
| 123 | - * |
|
| 124 | - * @param string $subject |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 121 | + /** |
|
| 122 | + * Resolves the newline character used in the string. |
|
| 123 | + * |
|
| 124 | + * @param string $subject |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | 127 | protected function resolveNewlineChar(string $subject) : string |
| 128 | 128 | { |
| 129 | 129 | $eol = ConvertHelper::detectEOLCharacter($subject); |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | ); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * @return string[] |
|
| 160 | - */ |
|
| 158 | + /** |
|
| 159 | + * @return string[] |
|
| 160 | + */ |
|
| 161 | 161 | public function getLog() : array |
| 162 | 162 | { |
| 163 | 163 | return $this->log; |
@@ -89,23 +89,23 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $placeholderID = $this->placeholder->getID(); |
| 91 | 91 | |
| 92 | - foreach($placeholders as $placeholder) |
|
| 92 | + foreach ($placeholders as $placeholder) |
|
| 93 | 93 | { |
| 94 | - if($placeholder->getID() === $placeholderID) |
|
| 94 | + if ($placeholder->getID() === $placeholderID) |
|
| 95 | 95 | { |
| 96 | 96 | continue; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | $start = $this->subject->getSubstrPosition($placeholder->getReplacementText()); |
| 100 | 100 | |
| 101 | - if($start === false) |
|
| 101 | + if ($start === false) |
|
| 102 | 102 | { |
| 103 | 103 | continue; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $end = $start + $placeholder->getReplacementLength(); |
| 107 | 107 | |
| 108 | - if($position >= $start && $position <= $end) |
|
| 108 | + if ($position >= $start && $position <= $end) |
|
| 109 | 109 | { |
| 110 | 110 | return true; |
| 111 | 111 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | $start = $this->getStartPosition(); |
| 123 | 123 | |
| 124 | - if($start !== false) |
|
| 124 | + if ($start !== false) |
|
| 125 | 125 | { |
| 126 | 126 | return $start + $this->placeholder->getReplacementLength(); |
| 127 | 127 | } |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | $needle = $this->placeholder->getReplacementText(); |
| 153 | 153 | |
| 154 | - if($this->subject->replaceSubstrings($needle, $replacementText)) |
|
| 154 | + if ($this->subject->replaceSubstrings($needle, $replacementText)) |
|
| 155 | 155 | { |
| 156 | 156 | return; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Complain about missing placeholders only if we |
| 160 | 160 | // are not in partial mode. |
| 161 | - if(!$this->formatter->getFormatting()->isPartial()) |
|
| 161 | + if (!$this->formatter->getFormatting()->isPartial()) |
|
| 162 | 162 | { |
| 163 | 163 | throw new Mailcode_Exception( |
| 164 | 164 | 'Could not find the placeholder to replace', |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | public function format() : void |
| 175 | 175 | { |
| 176 | - if($this->requiresAdjustment() && (!empty($this->prepend) || !empty($this->append))) |
|
| 176 | + if ($this->requiresAdjustment() && (!empty($this->prepend) || !empty($this->append))) |
|
| 177 | 177 | { |
| 178 | 178 | $this->replaceWith(sprintf( |
| 179 | 179 | '%s%s%s', |
@@ -24,34 +24,34 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | public const ERROR_PLACEHOLDER_NOT_FOUND = 66001; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var Mailcode_Parser_Safeguard_Formatter |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var Mailcode_Parser_Safeguard_Formatter |
|
| 29 | + */ |
|
| 30 | 30 | protected $formatter; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $append = ''; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | 40 | protected $prepend = ''; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var Mailcode_Parser_Safeguard_Placeholder |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var Mailcode_Parser_Safeguard_Placeholder |
|
| 44 | + */ |
|
| 45 | 45 | protected $placeholder; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var Mailcode_StringContainer |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var Mailcode_StringContainer |
|
| 49 | + */ |
|
| 50 | 50 | protected $subject; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var string[] |
|
| 54 | - */ |
|
| 52 | + /** |
|
| 53 | + * @var string[] |
|
| 54 | + */ |
|
| 55 | 55 | protected $log = array(); |
| 56 | 56 | |
| 57 | 57 | public function __construct(Mailcode_Parser_Safeguard_Formatter $formatter, Mailcode_Parser_Safeguard_Placeholder $placeholder) |
@@ -67,22 +67,22 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | abstract public function requiresAdjustment() : bool; |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return int|boolean |
|
| 72 | - */ |
|
| 70 | + /** |
|
| 71 | + * @return int|boolean |
|
| 72 | + */ |
|
| 73 | 73 | public function getStartPosition() |
| 74 | 74 | { |
| 75 | 75 | return $this->subject->getSubstrPosition($this->placeholder->getReplacementText()); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Checks whether the specified position within the string |
|
| 80 | - * is within another command's placeholder (excluding this |
|
| 81 | - * location's placeholder). |
|
| 82 | - * |
|
| 83 | - * @param int $position |
|
| 84 | - * @return bool |
|
| 85 | - */ |
|
| 78 | + /** |
|
| 79 | + * Checks whether the specified position within the string |
|
| 80 | + * is within another command's placeholder (excluding this |
|
| 81 | + * location's placeholder). |
|
| 82 | + * |
|
| 83 | + * @param int $position |
|
| 84 | + * @return bool |
|
| 85 | + */ |
|
| 86 | 86 | public function isWithinCommand(int $position) : bool |
| 87 | 87 | { |
| 88 | 88 | $placeholders = $this->formatter->getSafeguard()->getPlaceholders(); |
@@ -114,9 +114,9 @@ discard block |
||
| 114 | 114 | return false; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @return int|boolean |
|
| 119 | - */ |
|
| 117 | + /** |
|
| 118 | + * @return int|boolean |
|
| 119 | + */ |
|
| 120 | 120 | public function getEndPosition() |
| 121 | 121 | { |
| 122 | 122 | $start = $this->getStartPosition(); |
@@ -139,14 +139,14 @@ discard block |
||
| 139 | 139 | return $this->placeholder; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Replaces the placeholder with the specified replacement text. |
|
| 144 | - * |
|
| 145 | - * @param string $replacementText |
|
| 146 | - * @throws Mailcode_Exception |
|
| 147 | - * |
|
| 148 | - * @see Mailcode_Parser_Safeguard_Formatter_Location::ERROR_PLACEHOLDER_NOT_FOUND |
|
| 149 | - */ |
|
| 142 | + /** |
|
| 143 | + * Replaces the placeholder with the specified replacement text. |
|
| 144 | + * |
|
| 145 | + * @param string $replacementText |
|
| 146 | + * @throws Mailcode_Exception |
|
| 147 | + * |
|
| 148 | + * @see Mailcode_Parser_Safeguard_Formatter_Location::ERROR_PLACEHOLDER_NOT_FOUND |
|
| 149 | + */ |
|
| 150 | 150 | public function replaceWith(string $replacementText) : void |
| 151 | 151 | { |
| 152 | 152 | $needle = $this->placeholder->getReplacementText(); |
@@ -196,10 +196,10 @@ discard block |
||
| 196 | 196 | ); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Retrieves the location's log messages, if any. |
|
| 201 | - * @return string[] |
|
| 202 | - */ |
|
| 199 | + /** |
|
| 200 | + * Retrieves the location's log messages, if any. |
|
| 201 | + * @return string[] |
|
| 202 | + */ |
|
| 203 | 203 | public function getLog() : array |
| 204 | 204 | { |
| 205 | 205 | return $this->log; |
@@ -146,8 +146,7 @@ discard block |
||
| 146 | 146 | if($cmd instanceof Mailcode_Commands_Command_Type_Opening) |
| 147 | 147 | { |
| 148 | 148 | $this->stack[] = $cmd; |
| 149 | - } |
|
| 150 | - else if($cmd instanceof Mailcode_Commands_Command_Type_Closing) |
|
| 149 | + } else if($cmd instanceof Mailcode_Commands_Command_Type_Closing) |
|
| 151 | 150 | { |
| 152 | 151 | array_pop($this->stack); |
| 153 | 152 | } |
@@ -177,13 +176,11 @@ discard block |
||
| 177 | 176 | if(!empty($matches[1][$index])) |
| 178 | 177 | { |
| 179 | 178 | $name = $matches[1][$index]; |
| 180 | - } |
|
| 181 | - else if(!empty($matches[2][$index])) |
|
| 179 | + } else if(!empty($matches[2][$index])) |
|
| 182 | 180 | { |
| 183 | 181 | $name = $matches[2][$index]; |
| 184 | 182 | $params = $matches[3][$index]; |
| 185 | - } |
|
| 186 | - else if(!empty($matches[4][$index])) |
|
| 183 | + } else if(!empty($matches[4][$index])) |
|
| 187 | 184 | { |
| 188 | 185 | $name = $matches[4][$index]; |
| 189 | 186 | $type = $matches[5][$index]; |
@@ -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(); |
@@ -135,14 +135,14 @@ discard block |
||
| 135 | 135 | return str_replace($needle, $replacement, $subject); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Processes a single match found in the string: creates the command, |
|
| 140 | - * and adds it to the collection if it's a valid command, or to the list |
|
| 141 | - * of invalid commands otherwise. |
|
| 142 | - * |
|
| 143 | - * @param Mailcode_Parser_Match $match |
|
| 144 | - * @param Mailcode_Collection $collection |
|
| 145 | - */ |
|
| 138 | + /** |
|
| 139 | + * Processes a single match found in the string: creates the command, |
|
| 140 | + * and adds it to the collection if it's a valid command, or to the list |
|
| 141 | + * of invalid commands otherwise. |
|
| 142 | + * |
|
| 143 | + * @param Mailcode_Parser_Match $match |
|
| 144 | + * @param Mailcode_Collection $collection |
|
| 145 | + */ |
|
| 146 | 146 | protected function processMatch(Mailcode_Parser_Match $match, Mailcode_Collection $collection) : void |
| 147 | 147 | { |
| 148 | 148 | $name = $match->getName(); |
@@ -205,14 +205,14 @@ discard block |
||
| 205 | 205 | throw new Mailcode_Exception('Not a command', '', self::ERROR_NOT_A_COMMAND); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Parses a single regex match: determines which named group |
|
| 210 | - * matches, and retrieves the according information. |
|
| 211 | - * |
|
| 212 | - * @param array[] $matches The regex results array. |
|
| 213 | - * @param int $index The matched index. |
|
| 214 | - * @return Mailcode_Parser_Match |
|
| 215 | - */ |
|
| 208 | + /** |
|
| 209 | + * Parses a single regex match: determines which named group |
|
| 210 | + * matches, and retrieves the according information. |
|
| 211 | + * |
|
| 212 | + * @param array[] $matches The regex results array. |
|
| 213 | + * @param int $index The matched index. |
|
| 214 | + * @return Mailcode_Parser_Match |
|
| 215 | + */ |
|
| 216 | 216 | protected function parseMatch(array $matches, int $index) : Mailcode_Parser_Match |
| 217 | 217 | { |
| 218 | 218 | $name = ''; // the command name, e.g. "showvar" |
@@ -250,14 +250,14 @@ discard block |
||
| 250 | 250 | ); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Creates an instance of the safeguard tool, which |
|
| 255 | - * is used to safeguard commands in a string with placeholders. |
|
| 256 | - * |
|
| 257 | - * @param string $subject The string to use to safeguard commands in. |
|
| 258 | - * @return Mailcode_Parser_Safeguard |
|
| 259 | - * @see Mailcode_Parser_Safeguard |
|
| 260 | - */ |
|
| 253 | + /** |
|
| 254 | + * Creates an instance of the safeguard tool, which |
|
| 255 | + * is used to safeguard commands in a string with placeholders. |
|
| 256 | + * |
|
| 257 | + * @param string $subject The string to use to safeguard commands in. |
|
| 258 | + * @return Mailcode_Parser_Safeguard |
|
| 259 | + * @see Mailcode_Parser_Safeguard |
|
| 260 | + */ |
|
| 261 | 261 | public function createSafeguard(string $subject) : Mailcode_Parser_Safeguard |
| 262 | 262 | { |
| 263 | 263 | 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 | |
@@ -101,18 +101,18 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | $matches = array_unique($result[0]); |
| 103 | 103 | |
| 104 | - if(!empty($matches)) |
|
| 104 | + if (!empty($matches)) |
|
| 105 | 105 | { |
| 106 | - foreach($matches as $match) |
|
| 106 | + foreach ($matches as $match) |
|
| 107 | 107 | { |
| 108 | - if(strpos($match, '{') !== false || strpos($match, '}') !== false) |
|
| 108 | + if (strpos($match, '{') !== false || strpos($match, '}') !== false) |
|
| 109 | 109 | { |
| 110 | 110 | $subject = $this->replaceBrackets($subject, $match); |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if(!ConvertHelper::isStringHTML($subject)) |
|
| 115 | + if (!ConvertHelper::isStringHTML($subject)) |
|
| 116 | 116 | { |
| 117 | 117 | return $subject; |
| 118 | 118 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | private function replaceBrackets(string $subject, string $needle) : string |
| 125 | 125 | { |
| 126 | - $replacement = str_replace( |
|
| 126 | + $replacement = str_replace( |
|
| 127 | 127 | array('{', '}'), |
| 128 | 128 | array( |
| 129 | 129 | self::LITERAL_BRACKET_LEFT_REPLACEMENT, |
@@ -177,17 +177,17 @@ discard block |
||
| 177 | 177 | private function handleNesting(Mailcode_Commands_Command $cmd) : void |
| 178 | 178 | { |
| 179 | 179 | // Set the command's parent from the stack, if any is present. |
| 180 | - if(!empty($this->stack)) |
|
| 180 | + if (!empty($this->stack)) |
|
| 181 | 181 | { |
| 182 | 182 | $cmd->setParent($this->getStackLast()); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // Handle opening and closing commands, adding and removing from the stack. |
| 186 | - if($cmd instanceof Mailcode_Commands_Command_Type_Opening) |
|
| 186 | + if ($cmd instanceof Mailcode_Commands_Command_Type_Opening) |
|
| 187 | 187 | { |
| 188 | 188 | $this->stack[] = $cmd; |
| 189 | 189 | } |
| 190 | - else if($cmd instanceof Mailcode_Commands_Command_Type_Closing) |
|
| 190 | + else if ($cmd instanceof Mailcode_Commands_Command_Type_Closing) |
|
| 191 | 191 | { |
| 192 | 192 | array_pop($this->stack); |
| 193 | 193 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | { |
| 198 | 198 | $cmd = $this->stack[array_key_last($this->stack)]; |
| 199 | 199 | |
| 200 | - if($cmd instanceof Mailcode_Commands_Command) |
|
| 200 | + if ($cmd instanceof Mailcode_Commands_Command) |
|
| 201 | 201 | { |
| 202 | 202 | return $cmd; |
| 203 | 203 | } |
@@ -226,16 +226,16 @@ discard block |
||
| 226 | 226 | // 5 = parameter type command, type |
| 227 | 227 | // 6 = parameter type command, params |
| 228 | 228 | |
| 229 | - if(!empty($matches[1][$index])) |
|
| 229 | + if (!empty($matches[1][$index])) |
|
| 230 | 230 | { |
| 231 | 231 | $name = $matches[1][$index]; |
| 232 | 232 | } |
| 233 | - else if(!empty($matches[2][$index])) |
|
| 233 | + else if (!empty($matches[2][$index])) |
|
| 234 | 234 | { |
| 235 | 235 | $name = $matches[2][$index]; |
| 236 | 236 | $params = $matches[3][$index]; |
| 237 | 237 | } |
| 238 | - else if(!empty($matches[4][$index])) |
|
| 238 | + else if (!empty($matches[4][$index])) |
|
| 239 | 239 | { |
| 240 | 240 | $name = $matches[4][$index]; |
| 241 | 241 | $type = $matches[5][$index]; |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @param Mailcode_Commands_Command|null $sourceCommand |
| 273 | 273 | * @return Mailcode_Parser_Statement |
| 274 | 274 | */ |
| 275 | - public function createStatement(string $statement, bool $freeform=false, ?Mailcode_Commands_Command $sourceCommand=null) : Mailcode_Parser_Statement |
|
| 275 | + public function createStatement(string $statement, bool $freeform = false, ?Mailcode_Commands_Command $sourceCommand = null) : Mailcode_Parser_Statement |
|
| 276 | 276 | { |
| 277 | 277 | return new Mailcode_Parser_Statement($statement, $freeform, $sourceCommand); |
| 278 | 278 | } |