@@ -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 | } |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | 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) |
@@ -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 | } |
@@ -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 | const ERROR_TOO_MANY_REPLACERS = 65902; |
| 33 | 33 | 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); |
@@ -273,26 +273,26 @@ discard block |
||
| 273 | 273 | return $this->subject->getString(); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * Whether the formatting is done partially: missing placeholders |
|
| 278 | - * will simply be ignored. |
|
| 279 | - * |
|
| 280 | - * @return bool |
|
| 281 | - */ |
|
| 276 | + /** |
|
| 277 | + * Whether the formatting is done partially: missing placeholders |
|
| 278 | + * will simply be ignored. |
|
| 279 | + * |
|
| 280 | + * @return bool |
|
| 281 | + */ |
|
| 282 | 282 | public function isPartial() : bool |
| 283 | 283 | { |
| 284 | 284 | return $this->partial; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * The formatting will ignore missing placeholders. Use this if the |
|
| 289 | - * formatting will be done on a text that may not contain all of the |
|
| 290 | - * initial placeholders anymore. |
|
| 291 | - * |
|
| 292 | - * This is like the safeguard's makeWholePartial() method. |
|
| 293 | - * |
|
| 294 | - * @return Mailcode_Parser_Safeguard_Formatting |
|
| 295 | - */ |
|
| 287 | + /** |
|
| 288 | + * The formatting will ignore missing placeholders. Use this if the |
|
| 289 | + * formatting will be done on a text that may not contain all of the |
|
| 290 | + * initial placeholders anymore. |
|
| 291 | + * |
|
| 292 | + * This is like the safeguard's makeWholePartial() method. |
|
| 293 | + * |
|
| 294 | + * @return Mailcode_Parser_Safeguard_Formatting |
|
| 295 | + */ |
|
| 296 | 296 | public function makePartial() : Mailcode_Parser_Safeguard_Formatting |
| 297 | 297 | { |
| 298 | 298 | $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 | } |
@@ -55,45 +55,45 @@ discard block |
||
| 55 | 55 | const ERROR_EMPTY_DELIMITER = 47803; |
| 56 | 56 | const ERROR_PLACEHOLDER_NOT_FOUND = 47804; |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @var Mailcode_Parser |
|
| 60 | - */ |
|
| 58 | + /** |
|
| 59 | + * @var Mailcode_Parser |
|
| 60 | + */ |
|
| 61 | 61 | protected $parser; |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var Mailcode_Collection |
|
| 65 | - */ |
|
| 63 | + /** |
|
| 64 | + * @var Mailcode_Collection |
|
| 65 | + */ |
|
| 66 | 66 | protected $commands; |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @var string |
|
| 70 | - */ |
|
| 68 | + /** |
|
| 69 | + * @var string |
|
| 70 | + */ |
|
| 71 | 71 | protected $originalString; |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @var Mailcode_Collection |
|
| 75 | - */ |
|
| 73 | + /** |
|
| 74 | + * @var Mailcode_Collection |
|
| 75 | + */ |
|
| 76 | 76 | protected $collection; |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Counter for the placeholders, global for all placeholders. |
|
| 80 | - * @var integer |
|
| 81 | - */ |
|
| 78 | + /** |
|
| 79 | + * Counter for the placeholders, global for all placeholders. |
|
| 80 | + * @var integer |
|
| 81 | + */ |
|
| 82 | 82 | private static $counter = 0; |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @var Mailcode_Parser_Safeguard_Placeholder[] |
|
| 86 | - */ |
|
| 84 | + /** |
|
| 85 | + * @var Mailcode_Parser_Safeguard_Placeholder[] |
|
| 86 | + */ |
|
| 87 | 87 | protected $placeholders; |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 89 | + /** |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | 92 | protected $delimiter = '__'; |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @var string[]|NULL |
|
| 96 | - */ |
|
| 94 | + /** |
|
| 95 | + * @var string[]|NULL |
|
| 96 | + */ |
|
| 97 | 97 | protected $placeholderStrings; |
| 98 | 98 | |
| 99 | 99 | public function __construct(Mailcode_Parser $parser, string $subject) |
@@ -102,25 +102,25 @@ discard block |
||
| 102 | 102 | $this->originalString = $subject; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Retrieves the string the safeguard was created for. |
|
| 107 | - * |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 105 | + /** |
|
| 106 | + * Retrieves the string the safeguard was created for. |
|
| 107 | + * |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | 110 | public function getOriginalString() : string |
| 111 | 111 | { |
| 112 | 112 | return $this->originalString; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Sets the delimiter character sequence used to prepend |
|
| 117 | - * and append to the placeholders. |
|
| 118 | - * |
|
| 119 | - * The delimiter's default is "__" (two underscores). |
|
| 120 | - * |
|
| 121 | - * @param string $delimiter |
|
| 122 | - * @return Mailcode_Parser_Safeguard |
|
| 123 | - */ |
|
| 115 | + /** |
|
| 116 | + * Sets the delimiter character sequence used to prepend |
|
| 117 | + * and append to the placeholders. |
|
| 118 | + * |
|
| 119 | + * The delimiter's default is "__" (two underscores). |
|
| 120 | + * |
|
| 121 | + * @param string $delimiter |
|
| 122 | + * @return Mailcode_Parser_Safeguard |
|
| 123 | + */ |
|
| 124 | 124 | public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard |
| 125 | 125 | { |
| 126 | 126 | if(empty($delimiter)) |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | return $this->delimiter; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Retrieves the safe string in which all commands have been replaced |
|
| 147 | - * by placeholder strings. |
|
| 148 | - * |
|
| 149 | - * @return string |
|
| 150 | - * @throws Mailcode_Exception |
|
| 151 | - * |
|
| 152 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 153 | - */ |
|
| 145 | + /** |
|
| 146 | + * Retrieves the safe string in which all commands have been replaced |
|
| 147 | + * by placeholder strings. |
|
| 148 | + * |
|
| 149 | + * @return string |
|
| 150 | + * @throws Mailcode_Exception |
|
| 151 | + * |
|
| 152 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 153 | + */ |
|
| 154 | 154 | public function makeSafe() : string |
| 155 | 155 | { |
| 156 | 156 | $this->requireValidCollection(); |
@@ -158,16 +158,16 @@ discard block |
||
| 158 | 158 | return $this->makeSafePartial(); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Like makeSafe(), but allows partial (invalid) commands: use this |
|
| 163 | - * if the subject string may contain only part of the whole set of |
|
| 164 | - * commands. |
|
| 165 | - * |
|
| 166 | - * Example: parsing a text with an opening if statement, without the |
|
| 167 | - * matching end statement. |
|
| 168 | - * |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 161 | + /** |
|
| 162 | + * Like makeSafe(), but allows partial (invalid) commands: use this |
|
| 163 | + * if the subject string may contain only part of the whole set of |
|
| 164 | + * commands. |
|
| 165 | + * |
|
| 166 | + * Example: parsing a text with an opening if statement, without the |
|
| 167 | + * matching end statement. |
|
| 168 | + * |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | 171 | public function makeSafePartial() : string |
| 172 | 172 | { |
| 173 | 173 | $placeholders = $this->getPlaceholders(); |
@@ -272,13 +272,13 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Creates a formatting handler, which can be used to specify |
|
| 277 | - * which formattings to use for the commands in the subject string. |
|
| 278 | - * |
|
| 279 | - * @param Mailcode_StringContainer|string $subject |
|
| 280 | - * @return Mailcode_Parser_Safeguard_Formatting |
|
| 281 | - */ |
|
| 275 | + /** |
|
| 276 | + * Creates a formatting handler, which can be used to specify |
|
| 277 | + * which formattings to use for the commands in the subject string. |
|
| 278 | + * |
|
| 279 | + * @param Mailcode_StringContainer|string $subject |
|
| 280 | + * @return Mailcode_Parser_Safeguard_Formatting |
|
| 281 | + */ |
|
| 282 | 282 | public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting |
| 283 | 283 | { |
| 284 | 284 | if(is_string($subject)) |
@@ -289,12 +289,12 @@ discard block |
||
| 289 | 289 | return new Mailcode_Parser_Safeguard_Formatting($this, $subject); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Retrieves all placeholders that have to be added to |
|
| 294 | - * the subject text. |
|
| 295 | - * |
|
| 296 | - * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[] |
|
| 297 | - */ |
|
| 292 | + /** |
|
| 293 | + * Retrieves all placeholders that have to be added to |
|
| 294 | + * the subject text. |
|
| 295 | + * |
|
| 296 | + * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[] |
|
| 297 | + */ |
|
| 298 | 298 | public function getPlaceholders() |
| 299 | 299 | { |
| 300 | 300 | if(isset($this->placeholders)) |
@@ -370,16 +370,16 @@ discard block |
||
| 370 | 370 | return $string; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * Makes the string whole again after transforming or filtering it, |
|
| 375 | - * by replacing the command placeholders with the original commands. |
|
| 376 | - * |
|
| 377 | - * @param string $string |
|
| 378 | - * @return string |
|
| 379 | - * @throws Mailcode_Exception |
|
| 380 | - * |
|
| 381 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 382 | - */ |
|
| 373 | + /** |
|
| 374 | + * Makes the string whole again after transforming or filtering it, |
|
| 375 | + * by replacing the command placeholders with the original commands. |
|
| 376 | + * |
|
| 377 | + * @param string $string |
|
| 378 | + * @return string |
|
| 379 | + * @throws Mailcode_Exception |
|
| 380 | + * |
|
| 381 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 382 | + */ |
|
| 383 | 383 | public function makeWhole(string $string) : string |
| 384 | 384 | { |
| 385 | 385 | return $this->restore( |
@@ -389,15 +389,15 @@ discard block |
||
| 389 | 389 | ); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - /** |
|
| 393 | - * Like `makeWhole()`, but ignores missing command placeholders. |
|
| 394 | - * |
|
| 395 | - * @param string $string |
|
| 396 | - * @return string |
|
| 397 | - * @throws Mailcode_Exception |
|
| 398 | - * |
|
| 399 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 400 | - */ |
|
| 392 | + /** |
|
| 393 | + * Like `makeWhole()`, but ignores missing command placeholders. |
|
| 394 | + * |
|
| 395 | + * @param string $string |
|
| 396 | + * @return string |
|
| 397 | + * @throws Mailcode_Exception |
|
| 398 | + * |
|
| 399 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 400 | + */ |
|
| 401 | 401 | public function makeWholePartial(string $string) : string |
| 402 | 402 | { |
| 403 | 403 | return $this->restore( |
@@ -407,19 +407,19 @@ discard block |
||
| 407 | 407 | ); |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - /** |
|
| 411 | - * Like `makeWhole()`, but replaces the commands with a syntax |
|
| 412 | - * highlighted version, meant for human readable texts only. |
|
| 413 | - * |
|
| 414 | - * Note: the commands lose their functionality (They cannot be |
|
| 415 | - * parsed from that string again). |
|
| 416 | - * |
|
| 417 | - * @param string $string |
|
| 418 | - * @return string |
|
| 419 | - * @throws Mailcode_Exception |
|
| 420 | - * |
|
| 421 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 422 | - */ |
|
| 410 | + /** |
|
| 411 | + * Like `makeWhole()`, but replaces the commands with a syntax |
|
| 412 | + * highlighted version, meant for human readable texts only. |
|
| 413 | + * |
|
| 414 | + * Note: the commands lose their functionality (They cannot be |
|
| 415 | + * parsed from that string again). |
|
| 416 | + * |
|
| 417 | + * @param string $string |
|
| 418 | + * @return string |
|
| 419 | + * @throws Mailcode_Exception |
|
| 420 | + * |
|
| 421 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 422 | + */ |
|
| 423 | 423 | public function makeHighlighted(string $string) : string |
| 424 | 424 | { |
| 425 | 425 | return $this->restore( |
@@ -429,15 +429,15 @@ discard block |
||
| 429 | 429 | ); |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - /** |
|
| 433 | - * Like `makeHighlighted()`, but ignores missing command placeholders. |
|
| 434 | - * |
|
| 435 | - * @param string $string |
|
| 436 | - * @return string |
|
| 437 | - * @throws Mailcode_Exception |
|
| 438 | - * |
|
| 439 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 440 | - */ |
|
| 432 | + /** |
|
| 433 | + * Like `makeHighlighted()`, but ignores missing command placeholders. |
|
| 434 | + * |
|
| 435 | + * @param string $string |
|
| 436 | + * @return string |
|
| 437 | + * @throws Mailcode_Exception |
|
| 438 | + * |
|
| 439 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 440 | + */ |
|
| 441 | 441 | public function makeHighlightedPartial(string $string) : string |
| 442 | 442 | { |
| 443 | 443 | return $this->restore( |
@@ -447,11 +447,11 @@ discard block |
||
| 447 | 447 | ); |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - /** |
|
| 451 | - * Retrieves the commands collection contained in the string. |
|
| 452 | - * |
|
| 453 | - * @return Mailcode_Collection |
|
| 454 | - */ |
|
| 450 | + /** |
|
| 451 | + * Retrieves the commands collection contained in the string. |
|
| 452 | + * |
|
| 453 | + * @return Mailcode_Collection |
|
| 454 | + */ |
|
| 455 | 455 | public function getCollection() : Mailcode_Collection |
| 456 | 456 | { |
| 457 | 457 | if(isset($this->collection)) |
@@ -469,11 +469,11 @@ discard block |
||
| 469 | 469 | return $this->getCollection()->isValid(); |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - /** |
|
| 473 | - * @throws Mailcode_Exception |
|
| 474 | - * |
|
| 475 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 476 | - */ |
|
| 472 | + /** |
|
| 473 | + * @throws Mailcode_Exception |
|
| 474 | + * |
|
| 475 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
| 476 | + */ |
|
| 477 | 477 | protected function requireValidCollection() : void |
| 478 | 478 | { |
| 479 | 479 | if($this->getCollection()->isValid()) |
@@ -492,11 +492,11 @@ discard block |
||
| 492 | 492 | ); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - /** |
|
| 496 | - * Retrieves a list of all placeholder IDs used in the text. |
|
| 497 | - * |
|
| 498 | - * @return string[] |
|
| 499 | - */ |
|
| 495 | + /** |
|
| 496 | + * Retrieves a list of all placeholder IDs used in the text. |
|
| 497 | + * |
|
| 498 | + * @return string[] |
|
| 499 | + */ |
|
| 500 | 500 | public function getPlaceholderStrings() : array |
| 501 | 501 | { |
| 502 | 502 | if(is_array($this->placeholderStrings)) |
@@ -523,13 +523,13 @@ discard block |
||
| 523 | 523 | return in_array($subject, $ids); |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - /** |
|
| 527 | - * Retrieves a placeholder instance by its ID. |
|
| 528 | - * |
|
| 529 | - * @param int $id |
|
| 530 | - * @throws Mailcode_Exception If the placeholder was not found. |
|
| 531 | - * @return Mailcode_Parser_Safeguard_Placeholder |
|
| 532 | - */ |
|
| 526 | + /** |
|
| 527 | + * Retrieves a placeholder instance by its ID. |
|
| 528 | + * |
|
| 529 | + * @param int $id |
|
| 530 | + * @throws Mailcode_Exception If the placeholder was not found. |
|
| 531 | + * @return Mailcode_Parser_Safeguard_Placeholder |
|
| 532 | + */ |
|
| 533 | 533 | public function getPlaceholderByID(int $id) : Mailcode_Parser_Safeguard_Placeholder |
| 534 | 534 | { |
| 535 | 535 | $placeholders = $this->getPlaceholders(); |
@@ -552,13 +552,13 @@ discard block |
||
| 552 | 552 | ); |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - /** |
|
| 556 | - * Retrieves a placeholder instance by its replacement text. |
|
| 557 | - * |
|
| 558 | - * @param string $string |
|
| 559 | - * @throws Mailcode_Exception |
|
| 560 | - * @return Mailcode_Parser_Safeguard_Placeholder |
|
| 561 | - */ |
|
| 555 | + /** |
|
| 556 | + * Retrieves a placeholder instance by its replacement text. |
|
| 557 | + * |
|
| 558 | + * @param string $string |
|
| 559 | + * @throws Mailcode_Exception |
|
| 560 | + * @return Mailcode_Parser_Safeguard_Placeholder |
|
| 561 | + */ |
|
| 562 | 562 | public function getPlaceholderByString(string $string) : Mailcode_Parser_Safeguard_Placeholder |
| 563 | 563 | { |
| 564 | 564 | $placeholders = $this->getPlaceholders(); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard |
| 125 | 125 | { |
| 126 | - if(empty($delimiter)) |
|
| 126 | + if (empty($delimiter)) |
|
| 127 | 127 | { |
| 128 | 128 | throw new Mailcode_Exception( |
| 129 | 129 | 'Empty delimiter', |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | $placeholders = $this->getPlaceholders(); |
| 174 | 174 | $string = $this->originalString; |
| 175 | 175 | |
| 176 | - foreach($placeholders as $placeholder) |
|
| 176 | + foreach ($placeholders as $placeholder) |
|
| 177 | 177 | { |
| 178 | 178 | $string = $this->makePlaceholderSafe($string, $placeholder); |
| 179 | 179 | } |
@@ -203,14 +203,14 @@ discard block |
||
| 203 | 203 | $placeholders = $this->getPlaceholders(); |
| 204 | 204 | $total = count($placeholders); |
| 205 | 205 | |
| 206 | - for($i=0; $i < $total; $i++) |
|
| 206 | + for ($i = 0; $i < $total; $i++) |
|
| 207 | 207 | { |
| 208 | 208 | $placeholder = $placeholders[$i]; |
| 209 | 209 | $command = $placeholder->getCommand(); |
| 210 | 210 | |
| 211 | - if($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
| 211 | + if ($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
| 212 | 212 | { |
| 213 | - $string = $command->protectContent($string, $placeholder, $placeholders[$i+1]); |
|
| 213 | + $string = $command->protectContent($string, $placeholder, $placeholders[$i + 1]); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | { |
| 222 | 222 | $pos = mb_strpos($string, $placeholder->getOriginalText()); |
| 223 | 223 | |
| 224 | - if($pos === false) |
|
| 224 | + if ($pos === false) |
|
| 225 | 225 | { |
| 226 | 226 | throw new Mailcode_Exception( |
| 227 | 227 | 'Placeholder original text not found', |
@@ -253,18 +253,18 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | $placeholders = $this->getPlaceholders(); |
| 255 | 255 | |
| 256 | - foreach($urls as $url) |
|
| 256 | + foreach ($urls as $url) |
|
| 257 | 257 | { |
| 258 | - foreach($placeholders as $placeholder) |
|
| 258 | + foreach ($placeholders as $placeholder) |
|
| 259 | 259 | { |
| 260 | 260 | $command = $placeholder->getCommand(); |
| 261 | 261 | |
| 262 | - if(!$command->supportsURLEncoding()) |
|
| 262 | + if (!$command->supportsURLEncoding()) |
|
| 263 | 263 | { |
| 264 | 264 | continue; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if(strstr($url, $placeholder->getReplacementText()) && !$command->isURLDecoded()) |
|
| 267 | + if (strstr($url, $placeholder->getReplacementText()) && !$command->isURLDecoded()) |
|
| 268 | 268 | { |
| 269 | 269 | $command->setURLEncoding(true); |
| 270 | 270 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting |
| 283 | 283 | { |
| 284 | - if(is_string($subject)) |
|
| 284 | + if (is_string($subject)) |
|
| 285 | 285 | { |
| 286 | 286 | $subject = Mailcode::create()->createString($subject); |
| 287 | 287 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function getPlaceholders() |
| 299 | 299 | { |
| 300 | - if(isset($this->placeholders)) |
|
| 300 | + if (isset($this->placeholders)) |
|
| 301 | 301 | { |
| 302 | 302 | return $this->placeholders; |
| 303 | 303 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | $cmds = $this->getCollection()->getCommands(); |
| 308 | 308 | |
| 309 | - foreach($cmds as $command) |
|
| 309 | + foreach ($cmds as $command) |
|
| 310 | 310 | { |
| 311 | 311 | self::$counter++; |
| 312 | 312 | |
@@ -327,21 +327,21 @@ discard block |
||
| 327 | 327 | * @return string |
| 328 | 328 | * @throws Mailcode_Exception |
| 329 | 329 | */ |
| 330 | - protected function restore(string $string, bool $partial=false, bool $highlighted=false) : string |
|
| 330 | + protected function restore(string $string, bool $partial = false, bool $highlighted = false) : string |
|
| 331 | 331 | { |
| 332 | - if(!$partial) |
|
| 332 | + if (!$partial) |
|
| 333 | 333 | { |
| 334 | 334 | $this->requireValidCollection(); |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | $formatting = $this->createFormatting($string); |
| 338 | 338 | |
| 339 | - if($partial) |
|
| 339 | + if ($partial) |
|
| 340 | 340 | { |
| 341 | 341 | $formatting->makePartial(); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if($highlighted) |
|
| 344 | + if ($highlighted) |
|
| 345 | 345 | { |
| 346 | 346 | $formatting->replaceWithHTMLHighlighting(); |
| 347 | 347 | } |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | { |
| 362 | 362 | $command = $placeholder->getCommand(); |
| 363 | 363 | |
| 364 | - if($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
| 364 | + if ($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
| 365 | 365 | { |
| 366 | 366 | $string = $command->restoreContent($string); |
| 367 | 367 | } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | */ |
| 455 | 455 | public function getCollection() : Mailcode_Collection |
| 456 | 456 | { |
| 457 | - if(isset($this->collection)) |
|
| 457 | + if (isset($this->collection)) |
|
| 458 | 458 | { |
| 459 | 459 | return $this->collection; |
| 460 | 460 | } |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | */ |
| 477 | 477 | protected function requireValidCollection() : void |
| 478 | 478 | { |
| 479 | - if($this->getCollection()->isValid()) |
|
| 479 | + if ($this->getCollection()->isValid()) |
|
| 480 | 480 | { |
| 481 | 481 | return; |
| 482 | 482 | } |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | */ |
| 500 | 500 | public function getPlaceholderStrings() : array |
| 501 | 501 | { |
| 502 | - if(is_array($this->placeholderStrings)) |
|
| 502 | + if (is_array($this->placeholderStrings)) |
|
| 503 | 503 | { |
| 504 | 504 | return $this->placeholderStrings; |
| 505 | 505 | } |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | |
| 509 | 509 | $this->placeholderStrings = array(); |
| 510 | 510 | |
| 511 | - foreach($placeholders as $placeholder) |
|
| 511 | + foreach ($placeholders as $placeholder) |
|
| 512 | 512 | { |
| 513 | 513 | $this->placeholderStrings[] = $placeholder->getReplacementText(); |
| 514 | 514 | } |
@@ -534,9 +534,9 @@ discard block |
||
| 534 | 534 | { |
| 535 | 535 | $placeholders = $this->getPlaceholders(); |
| 536 | 536 | |
| 537 | - foreach($placeholders as $placeholder) |
|
| 537 | + foreach ($placeholders as $placeholder) |
|
| 538 | 538 | { |
| 539 | - if($placeholder->getID() === $id) |
|
| 539 | + if ($placeholder->getID() === $id) |
|
| 540 | 540 | { |
| 541 | 541 | return $placeholder; |
| 542 | 542 | } |
@@ -563,9 +563,9 @@ discard block |
||
| 563 | 563 | { |
| 564 | 564 | $placeholders = $this->getPlaceholders(); |
| 565 | 565 | |
| 566 | - foreach($placeholders as $placeholder) |
|
| 566 | + foreach ($placeholders as $placeholder) |
|
| 567 | 567 | { |
| 568 | - if($placeholder->getReplacementText() === $string) |
|
| 568 | + if ($placeholder->getReplacementText() === $string) |
|
| 569 | 569 | { |
| 570 | 570 | return $placeholder; |
| 571 | 571 | } |
@@ -26,39 +26,39 @@ discard block |
||
| 26 | 26 | const ERROR_INVALID_CALLABLE = 65701; |
| 27 | 27 | 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); |
@@ -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 | } |
@@ -24,34 +24,34 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | 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(); |
@@ -189,10 +189,10 @@ discard block |
||
| 189 | 189 | ); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Retrieves the location's log messages, if any. |
|
| 194 | - * @return string[] |
|
| 195 | - */ |
|
| 192 | + /** |
|
| 193 | + * Retrieves the location's log messages, if any. |
|
| 194 | + * @return string[] |
|
| 195 | + */ |
|
| 196 | 196 | public function getLog() : array |
| 197 | 197 | { |
| 198 | 198 | 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', |
@@ -27,19 +27,19 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | 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) |
@@ -93,12 +93,12 @@ discard block |
||
| 93 | 93 | ); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Retrieves all formatter-specific placeholder locations |
|
| 98 | - * in the subject string. |
|
| 99 | - * |
|
| 100 | - * @return Mailcode_Parser_Safeguard_Formatter_Location[] |
|
| 101 | - */ |
|
| 96 | + /** |
|
| 97 | + * Retrieves all formatter-specific placeholder locations |
|
| 98 | + * in the subject string. |
|
| 99 | + * |
|
| 100 | + * @return Mailcode_Parser_Safeguard_Formatter_Location[] |
|
| 101 | + */ |
|
| 102 | 102 | protected function resolveLocations() : array |
| 103 | 103 | { |
| 104 | 104 | $placeholders = $this->formatting->getSafeguard()->getPlaceholders(); |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | return $result; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Resolves the newline character used in the string. |
|
| 118 | - * |
|
| 119 | - * @param string $subject |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 116 | + /** |
|
| 117 | + * Resolves the newline character used in the string. |
|
| 118 | + * |
|
| 119 | + * @param string $subject |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | 122 | protected function resolveNewlineChar(string $subject) : string |
| 123 | 123 | { |
| 124 | 124 | $eol = ConvertHelper::detectEOLCharacter($subject); |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | ); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * @return string[] |
|
| 155 | - */ |
|
| 153 | + /** |
|
| 154 | + * @return string[] |
|
| 155 | + */ |
|
| 156 | 156 | public function getLog() : array |
| 157 | 157 | { |
| 158 | 158 | return $this->log; |
@@ -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.', |
@@ -23,21 +23,21 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | trait Mailcode_Traits_Formatting_HTMLHighlighting |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var string[] |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var string[] |
|
| 28 | + */ |
|
| 29 | 29 | private $excludeTags = array( |
| 30 | 30 | 'style', // NOTE: style tags are excluded natively on the parser level. |
| 31 | 31 | 'script' |
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Adds an HTML tag name to the list of tags within which |
|
| 36 | - * commands may not be highlighted. |
|
| 37 | - * |
|
| 38 | - * @param string $tagName Case insensitive. |
|
| 39 | - * @return $this |
|
| 40 | - */ |
|
| 34 | + /** |
|
| 35 | + * Adds an HTML tag name to the list of tags within which |
|
| 36 | + * commands may not be highlighted. |
|
| 37 | + * |
|
| 38 | + * @param string $tagName Case insensitive. |
|
| 39 | + * @return $this |
|
| 40 | + */ |
|
| 41 | 41 | public function excludeTag(string $tagName) |
| 42 | 42 | { |
| 43 | 43 | $tagName = strtolower($tagName); |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | return $this; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Adds several exluded tag names at once. |
|
| 55 | - * |
|
| 56 | - * @param string[] $tagNames |
|
| 57 | - * @return $this |
|
| 58 | - */ |
|
| 53 | + /** |
|
| 54 | + * Adds several exluded tag names at once. |
|
| 55 | + * |
|
| 56 | + * @param string[] $tagNames |
|
| 57 | + * @return $this |
|
| 58 | + */ |
|
| 59 | 59 | public function excludeTags(array $tagNames) |
| 60 | 60 | { |
| 61 | 61 | foreach($tagNames as $tagName) |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | return $this; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Whether the specified tag name is in the exlusion list. |
|
| 71 | - * |
|
| 72 | - * @param string $tagName |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 69 | + /** |
|
| 70 | + * Whether the specified tag name is in the exlusion list. |
|
| 71 | + * |
|
| 72 | + * @param string $tagName |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | 75 | public function isTagExcluded(string $tagName) : bool |
| 76 | 76 | { |
| 77 | 77 | $tagName = strtolower($tagName); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $tagName = strtolower($tagName); |
| 44 | 44 | |
| 45 | - if(!in_array($tagName, $this->excludeTags)) |
|
| 45 | + if (!in_array($tagName, $this->excludeTags)) |
|
| 46 | 46 | { |
| 47 | 47 | $this->excludeTags[] = $tagName; |
| 48 | 48 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function excludeTags(array $tagNames) |
| 60 | 60 | { |
| 61 | - foreach($tagNames as $tagName) |
|
| 61 | + foreach ($tagNames as $tagName) |
|
| 62 | 62 | { |
| 63 | 63 | $this->excludeTag((string)$tagName); |
| 64 | 64 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | $errors = $this->errors; |
| 101 | 101 | |
| 102 | - if(!$result->isValid()) |
|
| 102 | + if (!$result->isValid()) |
|
| 103 | 103 | { |
| 104 | 104 | $errors[] = new Mailcode_Collection_Error_Message( |
| 105 | 105 | '', |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | { |
| 116 | 116 | $errors = $this->getErrors(); |
| 117 | 117 | |
| 118 | - if(!empty($errors)) |
|
| 118 | + if (!empty($errors)) |
|
| 119 | 119 | { |
| 120 | 120 | return array_shift($errors); |
| 121 | 121 | } |
@@ -157,11 +157,11 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | $hashes = array(); |
| 159 | 159 | |
| 160 | - foreach($this->commands as $command) |
|
| 160 | + foreach ($this->commands as $command) |
|
| 161 | 161 | { |
| 162 | 162 | $hash = $command->getHash(); |
| 163 | 163 | |
| 164 | - if(!isset($hashes[$hash])) |
|
| 164 | + if (!isset($hashes[$hash])) |
|
| 165 | 165 | { |
| 166 | 166 | $hashes[$hash] = $command; |
| 167 | 167 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function addCommands(array $commands) : Mailcode_Collection |
| 180 | 180 | { |
| 181 | - foreach($commands as $command) |
|
| 181 | + foreach ($commands as $command) |
|
| 182 | 182 | { |
| 183 | 183 | $this->addCommand($command); |
| 184 | 184 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | { |
| 198 | 198 | $collection = new Mailcode_Variables_Collection_Regular(); |
| 199 | 199 | |
| 200 | - foreach($this->commands as $command) |
|
| 200 | + foreach ($this->commands as $command) |
|
| 201 | 201 | { |
| 202 | 202 | $collection->mergeWith($command->getVariables()); |
| 203 | 203 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | public function getValidationResult() : OperationResult |
| 209 | 209 | { |
| 210 | - if($this->validationResult instanceof OperationResult) |
|
| 210 | + if ($this->validationResult instanceof OperationResult) |
|
| 211 | 211 | { |
| 212 | 212 | return $this->validationResult; |
| 213 | 213 | } |
@@ -223,9 +223,9 @@ discard block |
||
| 223 | 223 | { |
| 224 | 224 | $errors = $this->getErrors(); |
| 225 | 225 | |
| 226 | - foreach($errors as $error) |
|
| 226 | + foreach ($errors as $error) |
|
| 227 | 227 | { |
| 228 | - if($error->getCode() === $code) |
|
| 228 | + if ($error->getCode() === $code) |
|
| 229 | 229 | { |
| 230 | 230 | return true; |
| 231 | 231 | } |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | { |
| 263 | 263 | $result = array(); |
| 264 | 264 | |
| 265 | - foreach($this->commands as $command) |
|
| 265 | + foreach ($this->commands as $command) |
|
| 266 | 266 | { |
| 267 | - if($command instanceof $className) |
|
| 267 | + if ($command instanceof $className) |
|
| 268 | 268 | { |
| 269 | 269 | $result[] = $command; |
| 270 | 270 | } |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | { |
| 278 | 278 | $commands = $this->getCommands(); |
| 279 | 279 | |
| 280 | - if(!empty($commands)) |
|
| 280 | + if (!empty($commands)) |
|
| 281 | 281 | { |
| 282 | 282 | return array_shift($commands); |
| 283 | 283 | } |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | const ERROR_CANNOT_RETRIEVE_FIRST_ERROR = 52301; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var Mailcode_Commands_Command[] |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var Mailcode_Commands_Command[] |
|
| 29 | + */ |
|
| 30 | 30 | protected $commands = array(); |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -34,17 +34,17 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | protected $errors = array(); |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var OperationResult|NULL |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var OperationResult|NULL |
|
| 39 | + */ |
|
| 40 | 40 | protected $validationResult; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Adds a command to the collection. |
|
| 44 | - * |
|
| 45 | - * @param Mailcode_Commands_Command $command |
|
| 46 | - * @return Mailcode_Collection |
|
| 47 | - */ |
|
| 42 | + /** |
|
| 43 | + * Adds a command to the collection. |
|
| 44 | + * |
|
| 45 | + * @param Mailcode_Commands_Command $command |
|
| 46 | + * @return Mailcode_Collection |
|
| 47 | + */ |
|
| 48 | 48 | public function addCommand(Mailcode_Commands_Command $command) : Mailcode_Collection |
| 49 | 49 | { |
| 50 | 50 | $this->commands[] = $command; |
@@ -56,21 +56,21 @@ discard block |
||
| 56 | 56 | return $this; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Whether there are any commands in the collection. |
|
| 61 | - * |
|
| 62 | - * @return bool |
|
| 63 | - */ |
|
| 59 | + /** |
|
| 60 | + * Whether there are any commands in the collection. |
|
| 61 | + * |
|
| 62 | + * @return bool |
|
| 63 | + */ |
|
| 64 | 64 | public function hasCommands() : bool |
| 65 | 65 | { |
| 66 | 66 | return !empty($this->commands); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Counts the amount of commands in the collection. |
|
| 71 | - * |
|
| 72 | - * @return int |
|
| 73 | - */ |
|
| 69 | + /** |
|
| 70 | + * Counts the amount of commands in the collection. |
|
| 71 | + * |
|
| 72 | + * @return int |
|
| 73 | + */ |
|
| 74 | 74 | public function countCommands() : int |
| 75 | 75 | { |
| 76 | 76 | return count($this->commands); |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | $this->errors[] = new Mailcode_Collection_Error_Command($command); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @return Mailcode_Collection_Error[] |
|
| 95 | - */ |
|
| 93 | + /** |
|
| 94 | + * @return Mailcode_Collection_Error[] |
|
| 95 | + */ |
|
| 96 | 96 | public function getErrors() |
| 97 | 97 | { |
| 98 | 98 | $result = $this->getValidationResult(); |
@@ -134,25 +134,25 @@ discard block |
||
| 134 | 134 | return empty($errors); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Retrieves all commands that were detected, in the exact order |
|
| 139 | - * they were found. |
|
| 140 | - * |
|
| 141 | - * @return \Mailcode\Mailcode_Commands_Command[] |
|
| 142 | - */ |
|
| 137 | + /** |
|
| 138 | + * Retrieves all commands that were detected, in the exact order |
|
| 139 | + * they were found. |
|
| 140 | + * |
|
| 141 | + * @return \Mailcode\Mailcode_Commands_Command[] |
|
| 142 | + */ |
|
| 143 | 143 | public function getCommands() |
| 144 | 144 | { |
| 145 | - return $this->commands; |
|
| 145 | + return $this->commands; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Retrieves all unique commands by their matched |
|
| 150 | - * string hash: this ensures only commands that were |
|
| 151 | - * written the exact same way (including spacing) |
|
| 152 | - * are returned. |
|
| 153 | - * |
|
| 154 | - * @return \Mailcode\Mailcode_Commands_Command[] |
|
| 155 | - */ |
|
| 148 | + /** |
|
| 149 | + * Retrieves all unique commands by their matched |
|
| 150 | + * string hash: this ensures only commands that were |
|
| 151 | + * written the exact same way (including spacing) |
|
| 152 | + * are returned. |
|
| 153 | + * |
|
| 154 | + * @return \Mailcode\Mailcode_Commands_Command[] |
|
| 155 | + */ |
|
| 156 | 156 | public function getGroupedByHash() |
| 157 | 157 | { |
| 158 | 158 | $hashes = array(); |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | return array_values($hashes); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * Adds several commands at once. |
|
| 175 | - * |
|
| 176 | - * @param Mailcode_Commands_Command[] $commands |
|
| 177 | - * @return Mailcode_Collection |
|
| 178 | - */ |
|
| 173 | + /** |
|
| 174 | + * Adds several commands at once. |
|
| 175 | + * |
|
| 176 | + * @param Mailcode_Commands_Command[] $commands |
|
| 177 | + * @return Mailcode_Collection |
|
| 178 | + */ |
|
| 179 | 179 | public function addCommands(array $commands) : Mailcode_Collection |
| 180 | 180 | { |
| 181 | 181 | foreach($commands as $command) |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
| 249 | - * Retrieves only show variable commands in the collection, if any. |
|
| 250 | - * |
|
| 251 | - * @return Mailcode_Commands_Command_ShowVariable[] |
|
| 252 | - */ |
|
| 249 | + * Retrieves only show variable commands in the collection, if any. |
|
| 250 | + * |
|
| 251 | + * @return Mailcode_Commands_Command_ShowVariable[] |
|
| 252 | + */ |
|
| 253 | 253 | public function getShowVariableCommands() |
| 254 | 254 | { |
| 255 | 255 | return $this->getCommandsByClass(Mailcode_Commands_Command_ShowVariable::class); |
@@ -263,11 +263,11 @@ discard block |
||
| 263 | 263 | return $this->getCommandsByClass(Mailcode_Commands_Command_For::class); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Retrieves only show date commands in the collection, if any. |
|
| 268 | - * |
|
| 269 | - * @return Mailcode_Commands_Command_ShowDate[] |
|
| 270 | - */ |
|
| 266 | + /** |
|
| 267 | + * Retrieves only show date commands in the collection, if any. |
|
| 268 | + * |
|
| 269 | + * @return Mailcode_Commands_Command_ShowDate[] |
|
| 270 | + */ |
|
| 271 | 271 | public function getShowDateCommands() : array |
| 272 | 272 | { |
| 273 | 273 | return $this->getCommandsByClass(Mailcode_Commands_Command_ShowDate::class); |