@@ -35,13 +35,13 @@ |
||
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | - /** |
|
39 | - * Resolves the string with which this location needs to be |
|
40 | - * replaced. |
|
41 | - * |
|
42 | - * @param Mailcode_Parser_Safeguard_Formatter_Location $location |
|
43 | - * @return string |
|
44 | - */ |
|
38 | + /** |
|
39 | + * Resolves the string with which this location needs to be |
|
40 | + * replaced. |
|
41 | + * |
|
42 | + * @param Mailcode_Parser_Safeguard_Formatter_Location $location |
|
43 | + * @return string |
|
44 | + */ |
|
45 | 45 | private function resolveReplacement(Mailcode_Parser_Safeguard_Formatter_Location $location) : string |
46 | 46 | { |
47 | 47 | if($location->requiresAdjustment()) |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | { |
30 | 30 | $locations = $this->resolveLocations(); |
31 | 31 | |
32 | - foreach($locations as $location) |
|
32 | + foreach ($locations as $location) |
|
33 | 33 | { |
34 | 34 | $location->replaceWith($this->resolveReplacement($location)); |
35 | 35 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | private function resolveReplacement(Mailcode_Parser_Safeguard_Formatter_Location $location) : string |
46 | 46 | { |
47 | - if($location->requiresAdjustment()) |
|
47 | + if ($location->requiresAdjustment()) |
|
48 | 48 | { |
49 | 49 | return $this->getReplaceString($location); |
50 | 50 | } |
@@ -23,14 +23,14 @@ |
||
23 | 23 | */ |
24 | 24 | class Mailcode_Parser_Safeguard_Formatter_Type_SingleLines extends Mailcode_Parser_Safeguard_Formatter_FormatType |
25 | 25 | { |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | 29 | private $eol; |
30 | 30 | |
31 | - /** |
|
32 | - * @var int |
|
33 | - */ |
|
31 | + /** |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | private $eolLength; |
35 | 35 | |
36 | 36 | protected function initFormatting() : void |
@@ -25,14 +25,14 @@ |
||
25 | 25 | */ |
26 | 26 | class Mailcode_Parser_Safeguard_Formatter_Type_SingleLines_Location extends Mailcode_Parser_Safeguard_Formatter_Location |
27 | 27 | { |
28 | - /** |
|
29 | - * @var int |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var int |
|
30 | + */ |
|
31 | 31 | protected $eolLength; |
32 | 32 | |
33 | - /** |
|
34 | - * @var string |
|
35 | - */ |
|
33 | + /** |
|
34 | + * @var string |
|
35 | + */ |
|
36 | 36 | protected $eol; |
37 | 37 | |
38 | 38 | protected function init() : void |
@@ -54,26 +54,26 @@ discard block |
||
54 | 54 | $position = $this->getStartPosition(); |
55 | 55 | |
56 | 56 | // we're at the beginning of the string |
57 | - if($position === false || $position === 0) |
|
57 | + if ($position === false || $position === 0) |
|
58 | 58 | { |
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | 62 | $prevPos = $position - $this->eolLength; |
63 | 63 | |
64 | - if($prevPos < 0) |
|
64 | + if ($prevPos < 0) |
|
65 | 65 | { |
66 | 66 | $prevPos = 0; |
67 | 67 | } |
68 | 68 | |
69 | - if($this->isWithinCommand($prevPos)) |
|
69 | + if ($this->isWithinCommand($prevPos)) |
|
70 | 70 | { |
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $prev = $this->subject->getSubstr($prevPos, $this->eolLength); |
75 | 75 | |
76 | - if($prev !== $this->formatter->getEOLChar()) |
|
76 | + if ($prev !== $this->formatter->getEOLChar()) |
|
77 | 77 | { |
78 | 78 | $this->prepend = $this->eol; |
79 | 79 | } |
@@ -86,21 +86,21 @@ discard block |
||
86 | 86 | $position = $this->getEndPosition(); |
87 | 87 | |
88 | 88 | // we're at the end of the string |
89 | - if($position === false || $position >= $subjectLength) |
|
89 | + if ($position === false || $position >= $subjectLength) |
|
90 | 90 | { |
91 | 91 | return; |
92 | 92 | } |
93 | 93 | |
94 | 94 | $nextPos = $position + $this->eolLength; |
95 | 95 | |
96 | - if($nextPos > $subjectLength) |
|
96 | + if ($nextPos > $subjectLength) |
|
97 | 97 | { |
98 | 98 | $nextPos = $subjectLength - $this->eolLength; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $next = $this->subject->getSubstr($nextPos, $this->eolLength); |
102 | 102 | |
103 | - if($next !== $this->formatter->getEOLChar()) |
|
103 | + if ($next !== $this->formatter->getEOLChar()) |
|
104 | 104 | { |
105 | 105 | $this->append = $this->eol; |
106 | 106 | } |
@@ -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 | } |
@@ -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(); |
@@ -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 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | private function getTagAncestry() : array |
143 | 143 | { |
144 | - if($this->ancestryChecked) |
|
144 | + if ($this->ancestryChecked) |
|
145 | 145 | { |
146 | 146 | return $this->tagAncestry; |
147 | 147 | } |
@@ -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 | } |
@@ -29,9 +29,9 @@ |
||
29 | 29 | |
30 | 30 | const ERROR_INVALID_TAG_TEMPLATE = 66101; |
31 | 31 | |
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | 35 | private $tagTemplate = '<span class="mailcode-marked-variable">%s</span>'; |
36 | 36 | |
37 | 37 | protected function initFormatting() : void |
@@ -40,7 +40,7 @@ |
||
40 | 40 | |
41 | 41 | public function setTemplate(string $template) : void |
42 | 42 | { |
43 | - if(substr_count($template, '%s') !== 1) |
|
43 | + if (substr_count($template, '%s') !== 1) |
|
44 | 44 | { |
45 | 45 | throw new Mailcode_Exception( |
46 | 46 | 'Invalid tag template', |
@@ -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 | } |
@@ -24,29 +24,29 @@ 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 | 52 | public function __construct(Mailcode_Parser_Safeguard_Formatter $formatter, Mailcode_Parser_Safeguard_Placeholder $placeholder) |
@@ -62,22 +62,22 @@ discard block |
||
62 | 62 | |
63 | 63 | abstract public function requiresAdjustment() : bool; |
64 | 64 | |
65 | - /** |
|
66 | - * @return int|boolean |
|
67 | - */ |
|
65 | + /** |
|
66 | + * @return int|boolean |
|
67 | + */ |
|
68 | 68 | public function getStartPosition() |
69 | 69 | { |
70 | 70 | return $this->subject->getSubstrPosition($this->placeholder->getReplacementText()); |
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * Checks whether the specified position within the string |
|
75 | - * is within another command's placeholder (excluding this |
|
76 | - * location's placeholder). |
|
77 | - * |
|
78 | - * @param int $position |
|
79 | - * @return bool |
|
80 | - */ |
|
73 | + /** |
|
74 | + * Checks whether the specified position within the string |
|
75 | + * is within another command's placeholder (excluding this |
|
76 | + * location's placeholder). |
|
77 | + * |
|
78 | + * @param int $position |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | 81 | public function isWithinCommand(int $position) : bool |
82 | 82 | { |
83 | 83 | $placeholders = $this->formatter->getSafeguard()->getPlaceholders(); |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | return false; |
110 | 110 | } |
111 | 111 | |
112 | - /** |
|
113 | - * @return int|boolean |
|
114 | - */ |
|
112 | + /** |
|
113 | + * @return int|boolean |
|
114 | + */ |
|
115 | 115 | public function getEndPosition() |
116 | 116 | { |
117 | 117 | $start = $this->getStartPosition(); |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | return $this->placeholder; |
135 | 135 | } |
136 | 136 | |
137 | - /** |
|
138 | - * Replaces the placeholder with the specified replacement text. |
|
139 | - * |
|
140 | - * @param string $replacementText |
|
141 | - * @throws Mailcode_Exception |
|
142 | - * |
|
143 | - * @see Mailcode_Parser_Safeguard_Formatter_Location::ERROR_PLACEHOLDER_NOT_FOUND |
|
144 | - */ |
|
137 | + /** |
|
138 | + * Replaces the placeholder with the specified replacement text. |
|
139 | + * |
|
140 | + * @param string $replacementText |
|
141 | + * @throws Mailcode_Exception |
|
142 | + * |
|
143 | + * @see Mailcode_Parser_Safeguard_Formatter_Location::ERROR_PLACEHOLDER_NOT_FOUND |
|
144 | + */ |
|
145 | 145 | public function replaceWith(string $replacementText) : void |
146 | 146 | { |
147 | 147 | $needle = $this->placeholder->getReplacementText(); |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | |
85 | 85 | $placeholderID = $this->placeholder->getID(); |
86 | 86 | |
87 | - foreach($placeholders as $placeholder) |
|
87 | + foreach ($placeholders as $placeholder) |
|
88 | 88 | { |
89 | - if($placeholder->getID() === $placeholderID) |
|
89 | + if ($placeholder->getID() === $placeholderID) |
|
90 | 90 | { |
91 | 91 | continue; |
92 | 92 | } |
93 | 93 | |
94 | 94 | $start = $this->subject->getSubstrPosition($placeholder->getReplacementText()); |
95 | 95 | |
96 | - if($start === false) |
|
96 | + if ($start === false) |
|
97 | 97 | { |
98 | 98 | continue; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $end = $start + $placeholder->getLength(); |
102 | 102 | |
103 | - if($position >= $start && $position <= $end) |
|
103 | + if ($position >= $start && $position <= $end) |
|
104 | 104 | { |
105 | 105 | return true; |
106 | 106 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | { |
117 | 117 | $start = $this->getStartPosition(); |
118 | 118 | |
119 | - if($start !== false) |
|
119 | + if ($start !== false) |
|
120 | 120 | { |
121 | 121 | return $start + $this->placeholder->getLength(); |
122 | 122 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | { |
147 | 147 | $needle = $this->placeholder->getReplacementText(); |
148 | 148 | |
149 | - if($this->subject->replaceSubstrings($needle, $replacementText)) |
|
149 | + if ($this->subject->replaceSubstrings($needle, $replacementText)) |
|
150 | 150 | { |
151 | 151 | return; |
152 | 152 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | |
164 | 164 | public function format() : void |
165 | 165 | { |
166 | - if($this->requiresAdjustment() && (!empty($this->prepend) || !empty($this->append))) |
|
166 | + if ($this->requiresAdjustment() && (!empty($this->prepend) || !empty($this->append))) |
|
167 | 167 | { |
168 | 168 | $this->replaceWith(sprintf( |
169 | 169 | '%s%s%s', |
@@ -27,14 +27,14 @@ 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 | 40 | public function __construct(Mailcode_Parser_Safeguard_Formatting $formatting) |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
91 | - /** |
|
92 | - * Retrieves all formatter-specific placeholder locations |
|
93 | - * in the subject string. |
|
94 | - * |
|
95 | - * @return Mailcode_Parser_Safeguard_Formatter_Location[] |
|
96 | - */ |
|
91 | + /** |
|
92 | + * Retrieves all formatter-specific placeholder locations |
|
93 | + * in the subject string. |
|
94 | + * |
|
95 | + * @return Mailcode_Parser_Safeguard_Formatter_Location[] |
|
96 | + */ |
|
97 | 97 | protected function resolveLocations() : array |
98 | 98 | { |
99 | 99 | $placeholders = $this->formatting->getSafeguard()->getPlaceholders(); |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | return $result; |
109 | 109 | } |
110 | 110 | |
111 | - /** |
|
112 | - * Resolves the newline character used in the string. |
|
113 | - * |
|
114 | - * @param string $subject |
|
115 | - * @return string |
|
116 | - */ |
|
111 | + /** |
|
112 | + * Resolves the newline character used in the string. |
|
113 | + * |
|
114 | + * @param string $subject |
|
115 | + * @return string |
|
116 | + */ |
|
117 | 117 | protected function resolveNewlineChar(string $subject) : string |
118 | 118 | { |
119 | 119 | $eol = ConvertHelper::detectEOLCharacter($subject); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | $instance = new $class($this, $placeholder); |
74 | 74 | |
75 | - if($instance instanceof Mailcode_Parser_Safeguard_Formatter_Location) |
|
75 | + if ($instance instanceof Mailcode_Parser_Safeguard_Formatter_Location) |
|
76 | 76 | { |
77 | 77 | return $instance; |
78 | 78 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | |
101 | 101 | $result = array(); |
102 | 102 | |
103 | - foreach($placeholders as $placeholder) |
|
103 | + foreach ($placeholders as $placeholder) |
|
104 | 104 | { |
105 | 105 | $result[] = $this->createLocation($placeholder); |
106 | 106 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | { |
119 | 119 | $eol = ConvertHelper::detectEOLCharacter($subject); |
120 | 120 | |
121 | - if($eol) |
|
121 | + if ($eol) |
|
122 | 122 | { |
123 | 123 | return $eol->getCharacter(); |
124 | 124 | } |