@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * Format the date value as a string based on the current locale |
83 | 83 | * |
84 | - * @param DateTime|int|string $date |
|
84 | + * @param \DateTime $date |
|
85 | 85 | * @param string $format null, 'short', 'medium', 'long', 'full' or pattern |
86 | 86 | * @param string $calendar 'gregorian' or 'traditional' |
87 | 87 | * @return string |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | /** |
105 | 105 | * Format the time value as a string based on the current locale |
106 | 106 | * |
107 | - * @param DateTime|int|string $date |
|
107 | + * @param \DateTime $date |
|
108 | 108 | * @param string $format 'short', 'medium', 'long', 'full' or pattern |
109 | 109 | * @param string $calendar 'gregorian' or 'traditional' |
110 | 110 | * @return string |
@@ -161,6 +161,7 @@ discard block |
||
161 | 161 | * Split duration into seconds, minutes, hours, days, weeks and years. |
162 | 162 | * |
163 | 163 | * @param int $seconds |
164 | + * @param integer $max |
|
164 | 165 | * @return array |
165 | 166 | */ |
166 | 167 | protected function splitDuration($seconds, $max) |
@@ -196,7 +197,7 @@ discard block |
||
196 | 197 | * |
197 | 198 | * @param int $seconds Time in seconds |
198 | 199 | * @param array $units Time units (seconds, minutes, hours, days, weeks, years) |
199 | - * @param string $separator |
|
200 | + * @param string $seperator |
|
200 | 201 | * @return string |
201 | 202 | */ |
202 | 203 | public function duration($seconds, $units=array('s', 'm', 'h', 'd', 'w', 'y'), $seperator=' ') |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | if (!isset($date)) return null; |
92 | 92 | |
93 | 93 | if ($date instanceof \DateTime); |
94 | - elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
95 | - else $date = new \DateTime((string)$date); |
|
94 | + elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
95 | + else $date = new \DateTime((string)$date); |
|
96 | 96 | |
97 | 97 | $calendar = $calendar == 'traditional' ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN; |
98 | 98 | list($format, $pattern) = $this->getFormat($format, $calendar); |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | if (!isset($date)) return null; |
115 | 115 | |
116 | 116 | if ($date instanceof \DateTime); |
117 | - elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
118 | - else $date = new \DateTime((string)$date); |
|
117 | + elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
118 | + else $date = new \DateTime((string)$date); |
|
119 | 119 | |
120 | 120 | $calendar = $calendar == 'traditional' ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN; |
121 | 121 | list($format, $pattern) = $this->getFormat($format, $calendar); |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | if (!isset($date)) return null; |
138 | 138 | |
139 | 139 | if ($date instanceof \DateTime); |
140 | - elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
141 | - else $date = new \DateTime((string)$date); |
|
140 | + elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
141 | + else $date = new \DateTime((string)$date); |
|
142 | 142 | |
143 | 143 | $calendar = $calendar == 'traditional' ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN; |
144 | 144 |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | * @param int $calendar |
52 | 52 | * @return array(format, pattern) |
53 | 53 | */ |
54 | - protected function getFormat($format, $calendar=\IntlDateFormatter::GREGORIAN) |
|
54 | + protected function getFormat($format, $calendar = \IntlDateFormatter::GREGORIAN) |
|
55 | 55 | { |
56 | 56 | $pattern = null; |
57 | 57 | |
58 | 58 | switch ($format) { |
59 | 59 | case null: $format = \IntlDateFormatter::SHORT; $pattern = $this->getDefaultDatePattern($calendar); break; |
60 | - case 'short': $format = \IntlDateFormatter::SHORT; break; |
|
60 | + case 'short': $format = \IntlDateFormatter::SHORT; break; |
|
61 | 61 | case 'medium': $format = \IntlDateFormatter::MEDIUM; break; |
62 | - case 'long': $format = \IntlDateFormatter::LONG; break; |
|
63 | - case 'full': $format = \IntlDateFormatter::FULL; break; |
|
62 | + case 'long': $format = \IntlDateFormatter::LONG; break; |
|
63 | + case 'full': $format = \IntlDateFormatter::FULL; break; |
|
64 | 64 | default: $pattern = $format; $format = \IntlDateFormatter::SHORT; break; |
65 | 65 | } |
66 | 66 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param int $calendar |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - protected function getDefaultDatePattern($calendar=\IntlDateFormatter::GREGORIAN) |
|
76 | + protected function getDefaultDatePattern($calendar = \IntlDateFormatter::GREGORIAN) |
|
77 | 77 | { |
78 | 78 | return preg_replace('/\byy?\b/', 'yyyy', \IntlDateFormatter::create(\Locale::getDefault(), \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, null, $calendar)->getPattern()); |
79 | 79 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param string $calendar 'gregorian' or 'traditional' |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - public function localDate($date, $format=null, $calendar='gregorian') |
|
89 | + public function localDate($date, $format = null, $calendar = 'gregorian') |
|
90 | 90 | { |
91 | 91 | if (!isset($date)) return null; |
92 | 92 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param string $calendar 'gregorian' or 'traditional' |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - public function localTime($date, $format='short', $calendar='gregorian') |
|
112 | + public function localTime($date, $format = 'short', $calendar = 'gregorian') |
|
113 | 113 | { |
114 | 114 | if (!isset($date)) return null; |
115 | 115 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param string $calendar 'gregorian' or 'traditional' |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public function localDateTime($date, $format=null, $calendar='gregorian') |
|
135 | + public function localDateTime($date, $format = null, $calendar = 'gregorian') |
|
136 | 136 | { |
137 | 137 | if (!isset($date)) return null; |
138 | 138 | |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * @param string $separator |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function duration($seconds, $units=array('s', 'm', 'h', 'd', 'w', 'y'), $seperator=' ') |
|
202 | + public function duration($seconds, $units = array('s', 'm', 'h', 'd', 'w', 'y'), $seperator = ' ') |
|
203 | 203 | { |
204 | 204 | list($seconds, $minutes, $hours, $days, $weeks, $years) = |
205 | - $this->splitDuration($seconds, count($units)-1) + array_fill(0, 6, null); |
|
205 | + $this->splitDuration($seconds, count($units) - 1) + array_fill(0, 6, null); |
|
206 | 206 | |
207 | 207 | $duration = ''; |
208 | 208 | if (isset($years) && isset($units[5])) $duration .= $seperator . $years . $units[5]; |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - if (!extension_loaded('intl')) throw new \Exception("Jasny's Date Twig extension requires PHP extension 'intl' (see http://www.php.net/intl)."); |
|
17 | + if (!extension_loaded('intl')) { |
|
18 | + throw new \Exception("Jasny's Date Twig extension requires PHP extension 'intl' (see http://www.php.net/intl)."); |
|
19 | + } |
|
18 | 20 | } |
19 | 21 | |
20 | 22 | |
@@ -88,11 +90,16 @@ discard block |
||
88 | 90 | */ |
89 | 91 | public function localDate($date, $format=null, $calendar='gregorian') |
90 | 92 | { |
91 | - if (!isset($date)) return null; |
|
93 | + if (!isset($date)) { |
|
94 | + return null; |
|
95 | + } |
|
92 | 96 | |
93 | 97 | if ($date instanceof \DateTime); |
94 | - elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
95 | - else $date = new \DateTime((string)$date); |
|
98 | + elseif (is_int($date)) { |
|
99 | + $date = \DateTime::createFromFormat('U', $date); |
|
100 | + } else { |
|
101 | + $date = new \DateTime((string)$date); |
|
102 | + } |
|
96 | 103 | |
97 | 104 | $calendar = $calendar == 'traditional' ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN; |
98 | 105 | list($format, $pattern) = $this->getFormat($format, $calendar); |
@@ -111,11 +118,16 @@ discard block |
||
111 | 118 | */ |
112 | 119 | public function localTime($date, $format='short', $calendar='gregorian') |
113 | 120 | { |
114 | - if (!isset($date)) return null; |
|
121 | + if (!isset($date)) { |
|
122 | + return null; |
|
123 | + } |
|
115 | 124 | |
116 | 125 | if ($date instanceof \DateTime); |
117 | - elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
118 | - else $date = new \DateTime((string)$date); |
|
126 | + elseif (is_int($date)) { |
|
127 | + $date = \DateTime::createFromFormat('U', $date); |
|
128 | + } else { |
|
129 | + $date = new \DateTime((string)$date); |
|
130 | + } |
|
119 | 131 | |
120 | 132 | $calendar = $calendar == 'traditional' ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN; |
121 | 133 | list($format, $pattern) = $this->getFormat($format, $calendar); |
@@ -134,11 +146,16 @@ discard block |
||
134 | 146 | */ |
135 | 147 | public function localDateTime($date, $format=null, $calendar='gregorian') |
136 | 148 | { |
137 | - if (!isset($date)) return null; |
|
149 | + if (!isset($date)) { |
|
150 | + return null; |
|
151 | + } |
|
138 | 152 | |
139 | 153 | if ($date instanceof \DateTime); |
140 | - elseif (is_int($date)) $date = \DateTime::createFromFormat('U', $date); |
|
141 | - else $date = new \DateTime((string)$date); |
|
154 | + elseif (is_int($date)) { |
|
155 | + $date = \DateTime::createFromFormat('U', $date); |
|
156 | + } else { |
|
157 | + $date = new \DateTime((string)$date); |
|
158 | + } |
|
142 | 159 | |
143 | 160 | $calendar = $calendar == 'traditional' ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN; |
144 | 161 | |
@@ -165,23 +182,33 @@ discard block |
||
165 | 182 | */ |
166 | 183 | protected function splitDuration($seconds, $max) |
167 | 184 | { |
168 | - if ($max < 1 || $seconds < 60) return array($seconds); |
|
185 | + if ($max < 1 || $seconds < 60) { |
|
186 | + return array($seconds); |
|
187 | + } |
|
169 | 188 | |
170 | 189 | $minutes = floor($seconds / 60); |
171 | 190 | $seconds = $seconds % 60; |
172 | - if ($max < 2 || $minutes < 60) return array($seconds, $minutes); |
|
191 | + if ($max < 2 || $minutes < 60) { |
|
192 | + return array($seconds, $minutes); |
|
193 | + } |
|
173 | 194 | |
174 | 195 | $hours = floor($minutes / 60); |
175 | 196 | $minutes = $minutes % 60; |
176 | - if ($max < 3 || $hours < 24) return array($seconds, $minutes, $hours); |
|
197 | + if ($max < 3 || $hours < 24) { |
|
198 | + return array($seconds, $minutes, $hours); |
|
199 | + } |
|
177 | 200 | |
178 | 201 | $days = floor($hours / 24); |
179 | 202 | $hours = $hours % 24; |
180 | - if ($max < 4 || $days < 7) return array($seconds, $minutes, $hours, $days); |
|
203 | + if ($max < 4 || $days < 7) { |
|
204 | + return array($seconds, $minutes, $hours, $days); |
|
205 | + } |
|
181 | 206 | |
182 | 207 | $weeks = floor($days / 7); |
183 | 208 | $days = $days % 7; |
184 | - if ($max < 5 || $weeks < 52) return array($seconds, $minutes, $hours, $days, $weeks); |
|
209 | + if ($max < 5 || $weeks < 52) { |
|
210 | + return array($seconds, $minutes, $hours, $days, $weeks); |
|
211 | + } |
|
185 | 212 | |
186 | 213 | $years = floor($weeks / 52); |
187 | 214 | $weeks = $weeks % 52; |
@@ -205,12 +232,24 @@ discard block |
||
205 | 232 | $this->splitDuration($seconds, count($units)-1) + array_fill(0, 6, null); |
206 | 233 | |
207 | 234 | $duration = ''; |
208 | - if (isset($years) && isset($units[5])) $duration .= $seperator . $years . $units[5]; |
|
209 | - if (isset($weeks) && isset($units[4])) $duration .= $seperator . $weeks . $units[4]; |
|
210 | - if (isset($days) && isset($units[3])) $duration .= $seperator . $days . $units[3]; |
|
211 | - if (isset($hours) && isset($units[2])) $duration .= $seperator . $hours . $units[2]; |
|
212 | - if (isset($minutes) && isset($units[1])) $duration .= $seperator . $minutes . $units[1]; |
|
213 | - if (isset($seconds) && isset($units[0])) $duration .= $seperator . $seconds . $units[0]; |
|
235 | + if (isset($years) && isset($units[5])) { |
|
236 | + $duration .= $seperator . $years . $units[5]; |
|
237 | + } |
|
238 | + if (isset($weeks) && isset($units[4])) { |
|
239 | + $duration .= $seperator . $weeks . $units[4]; |
|
240 | + } |
|
241 | + if (isset($days) && isset($units[3])) { |
|
242 | + $duration .= $seperator . $days . $units[3]; |
|
243 | + } |
|
244 | + if (isset($hours) && isset($units[2])) { |
|
245 | + $duration .= $seperator . $hours . $units[2]; |
|
246 | + } |
|
247 | + if (isset($minutes) && isset($units[1])) { |
|
248 | + $duration .= $seperator . $minutes . $units[1]; |
|
249 | + } |
|
250 | + if (isset($seconds) && isset($units[0])) { |
|
251 | + $duration .= $seperator . $seconds . $units[0]; |
|
252 | + } |
|
214 | 253 | |
215 | 254 | return trim($duration, $seperator); |
216 | 255 | } |
@@ -223,7 +262,9 @@ discard block |
||
223 | 262 | */ |
224 | 263 | public function age($date) |
225 | 264 | { |
226 | - if (!$date instanceof \DateTime) $date = new \DateTime($date); |
|
265 | + if (!$date instanceof \DateTime) { |
|
266 | + $date = new \DateTime($date); |
|
267 | + } |
|
227 | 268 | return $date->diff(new \DateTime())->format('%y'); |
228 | 269 | } |
229 | 270 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | * |
66 | 66 | * @param string $value |
67 | 67 | * @param string $pattern |
68 | - * @return boolean |
|
68 | + * @return null|integer |
|
69 | 69 | */ |
70 | 70 | public function match($value, $pattern) |
71 | 71 | { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param string $pattern |
83 | 83 | * @return string |
84 | 84 | */ |
85 | - public function get($value, $pattern, $group=0) |
|
85 | + public function get($value, $pattern, $group = 0) |
|
86 | 86 | { |
87 | 87 | $this->assertNoEval($pattern); |
88 | 88 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param string $pattern |
99 | 99 | * @return array |
100 | 100 | */ |
101 | - public function getAll($value, $pattern, $group=0) |
|
101 | + public function getAll($value, $pattern, $group = 0) |
|
102 | 102 | { |
103 | 103 | $this->assertNoEval($pattern); |
104 | 104 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param strign $flags Optional 'invert' to return entries that do not match the given pattern. |
116 | 116 | * @return array |
117 | 117 | */ |
118 | - public function grep($values, $pattern, $flags='') |
|
118 | + public function grep($values, $pattern, $flags = '') |
|
119 | 119 | { |
120 | 120 | $this->assertNoEval($pattern); |
121 | 121 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param int $limit |
135 | 135 | * @return string |
136 | 136 | */ |
137 | - public function replace($value, $pattern, $replacement='', $limit=-1) |
|
137 | + public function replace($value, $pattern, $replacement = '', $limit = -1) |
|
138 | 138 | { |
139 | 139 | $this->assertNoEval($pattern); |
140 | 140 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param int $limit |
152 | 152 | * @return string |
153 | 153 | */ |
154 | - public function filter($value, $pattern, $replacement='', $limit=-1) |
|
154 | + public function filter($value, $pattern, $replacement = '', $limit = -1) |
|
155 | 155 | { |
156 | 156 | $this->assertNoEval($pattern); |
157 | 157 |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - if (!extension_loaded('pcre')) throw new \Exception("The Twig PCRE extension requires PHP extension 'pcre' (see http://www.php.net/pcre)."); |
|
17 | + if (!extension_loaded('pcre')) { |
|
18 | + throw new \Exception("The Twig PCRE extension requires PHP extension 'pcre' (see http://www.php.net/pcre)."); |
|
19 | + } |
|
18 | 20 | } |
19 | 21 | |
20 | 22 | |
@@ -43,7 +45,9 @@ discard block |
||
43 | 45 | */ |
44 | 46 | protected function assertNoEval($pattern) |
45 | 47 | { |
46 | - if (preg_match('/(.).*\1(.+)$/', trim($pattern), $match) && strpos($match[1], 'e') !== false) throw new \Exception("Using the eval modifier for regular expressions is not allowed"); |
|
48 | + if (preg_match('/(.).*\1(.+)$/', trim($pattern), $match) && strpos($match[1], 'e') !== false) { |
|
49 | + throw new \Exception("Using the eval modifier for regular expressions is not allowed"); |
|
50 | + } |
|
47 | 51 | } |
48 | 52 | |
49 | 53 | |
@@ -56,7 +60,9 @@ discard block |
||
56 | 60 | */ |
57 | 61 | public function quote($value, $delimiter = '/') |
58 | 62 | { |
59 | - if (!isset($value)) return null; |
|
63 | + if (!isset($value)) { |
|
64 | + return null; |
|
65 | + } |
|
60 | 66 | return preg_quote($value, $delimiter); |
61 | 67 | } |
62 | 68 | |
@@ -71,7 +77,9 @@ discard block |
||
71 | 77 | { |
72 | 78 | $this->assertNoEval($pattern); |
73 | 79 | |
74 | - if (!isset($value)) return null; |
|
80 | + if (!isset($value)) { |
|
81 | + return null; |
|
82 | + } |
|
75 | 83 | return preg_match($pattern, $value); |
76 | 84 | } |
77 | 85 | |
@@ -86,8 +94,12 @@ discard block |
||
86 | 94 | { |
87 | 95 | $this->assertNoEval($pattern); |
88 | 96 | |
89 | - if (!isset($value)) return null; |
|
90 | - if (!preg_match($pattern, $value, $matches)) return null; |
|
97 | + if (!isset($value)) { |
|
98 | + return null; |
|
99 | + } |
|
100 | + if (!preg_match($pattern, $value, $matches)) { |
|
101 | + return null; |
|
102 | + } |
|
91 | 103 | return isset($matches[$group]) ? $matches[$group] : null; |
92 | 104 | } |
93 | 105 | |
@@ -102,8 +114,12 @@ discard block |
||
102 | 114 | { |
103 | 115 | $this->assertNoEval($pattern); |
104 | 116 | |
105 | - if (!isset($value)) return null; |
|
106 | - if (!preg_match_all($pattern, $value, $matches, PREG_PATTERN_ORDER)) return array(); |
|
117 | + if (!isset($value)) { |
|
118 | + return null; |
|
119 | + } |
|
120 | + if (!preg_match_all($pattern, $value, $matches, PREG_PATTERN_ORDER)) { |
|
121 | + return array(); |
|
122 | + } |
|
107 | 123 | return isset($matches[$group]) ? $matches[$group] : array(); |
108 | 124 | } |
109 | 125 | |
@@ -119,9 +135,13 @@ discard block |
||
119 | 135 | { |
120 | 136 | $this->assertNoEval($pattern); |
121 | 137 | |
122 | - if (!isset($values)) return null; |
|
138 | + if (!isset($values)) { |
|
139 | + return null; |
|
140 | + } |
|
123 | 141 | |
124 | - if (is_string($flags)) $flags = $flags == 'invert' ? PREG_GREP_INVERT : 0; |
|
142 | + if (is_string($flags)) { |
|
143 | + $flags = $flags == 'invert' ? PREG_GREP_INVERT : 0; |
|
144 | + } |
|
125 | 145 | return preg_grep($pattern, $values, $flags); |
126 | 146 | } |
127 | 147 | |
@@ -138,7 +158,9 @@ discard block |
||
138 | 158 | { |
139 | 159 | $this->assertNoEval($pattern); |
140 | 160 | |
141 | - if (!isset($value)) return null; |
|
161 | + if (!isset($value)) { |
|
162 | + return null; |
|
163 | + } |
|
142 | 164 | return preg_replace($pattern, $replacement, $value, $limit); |
143 | 165 | } |
144 | 166 | |
@@ -155,7 +177,9 @@ discard block |
||
155 | 177 | { |
156 | 178 | $this->assertNoEval($pattern); |
157 | 179 | |
158 | - if (!isset($value)) return null; |
|
180 | + if (!isset($value)) { |
|
181 | + return null; |
|
182 | + } |
|
159 | 183 | return preg_filter($pattern, $replacement, $value, $limit); |
160 | 184 | } |
161 | 185 | |
@@ -170,7 +194,9 @@ discard block |
||
170 | 194 | { |
171 | 195 | $this->assertNoEval($pattern); |
172 | 196 | |
173 | - if (!isset($value)) return null; |
|
197 | + if (!isset($value)) { |
|
198 | + return null; |
|
199 | + } |
|
174 | 200 | return preg_split($pattern, $value); |
175 | 201 | } |
176 | 202 |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function sum($array) |
45 | 45 | { |
46 | - if (!isset($array)) return null; |
|
47 | - return array_sum((array)$array); |
|
46 | + if (!isset($array)) return null; |
|
47 | + return array_sum((array)$array); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function product($array) |
57 | 57 | { |
58 | - if (!isset($array)) return null; |
|
59 | - return array_product((array)$array); |
|
58 | + if (!isset($array)) return null; |
|
59 | + return array_product((array)$array); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function values($array) |
69 | 69 | { |
70 | - if (!isset($array)) return null; |
|
71 | - return array_values((array)$array); |
|
70 | + if (!isset($array)) return null; |
|
71 | + return array_values((array)$array); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 |
@@ -43,7 +43,9 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function sum($array) |
45 | 45 | { |
46 | - if (!isset($array)) return null; |
|
46 | + if (!isset($array)) { |
|
47 | + return null; |
|
48 | + } |
|
47 | 49 | return array_sum((array)$array); |
48 | 50 | } |
49 | 51 | |
@@ -55,7 +57,9 @@ discard block |
||
55 | 57 | */ |
56 | 58 | public function product($array) |
57 | 59 | { |
58 | - if (!isset($array)) return null; |
|
60 | + if (!isset($array)) { |
|
61 | + return null; |
|
62 | + } |
|
59 | 63 | return array_product((array)$array); |
60 | 64 | } |
61 | 65 | |
@@ -67,7 +71,9 @@ discard block |
||
67 | 71 | */ |
68 | 72 | public function values($array) |
69 | 73 | { |
70 | - if (!isset($array)) return null; |
|
74 | + if (!isset($array)) { |
|
75 | + return null; |
|
76 | + } |
|
71 | 77 | return array_values((array)$array); |
72 | 78 | } |
73 | 79 | |
@@ -91,13 +97,19 @@ discard block |
||
91 | 97 | */ |
92 | 98 | public function HTMLAttributes($array) |
93 | 99 | { |
94 | - if (!isset($array)) return null; |
|
100 | + if (!isset($array)) { |
|
101 | + return null; |
|
102 | + } |
|
95 | 103 | |
96 | 104 | $str = ""; |
97 | 105 | foreach ($array as $key=>$value) { |
98 | - if (!isset($value) || $value === false) continue; |
|
106 | + if (!isset($value) || $value === false) { |
|
107 | + continue; |
|
108 | + } |
|
99 | 109 | |
100 | - if ($value === true) $value = $key; |
|
110 | + if ($value === true) { |
|
111 | + $value = $key; |
|
112 | + } |
|
101 | 113 | $str .= ' ' . $key . '="' . addcslashes($value, '"') . '"'; |
102 | 114 | } |
103 | 115 | return trim($str); |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | * @param int $line Line number (starts at 1) |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function line($value, $line=1) |
|
45 | + public function line($value, $line = 1) |
|
46 | 46 | { |
47 | 47 | if (!isset($value)) return null; |
48 | 48 | |
49 | 49 | $lines = explode("\n", $value); |
50 | - return isset($lines[$line-1]) ? $lines[$line-1] : null; |
|
50 | + return isset($lines[$line - 1]) ? $lines[$line - 1] : null; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -102,24 +102,24 @@ discard block |
||
102 | 102 | $links = array(); |
103 | 103 | |
104 | 104 | // Extract existing links and tags |
105 | - $value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', function ($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value); |
|
105 | + $value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', function($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value); |
|
106 | 106 | |
107 | 107 | // Extract text links for each protocol |
108 | 108 | foreach ((array)$protocols as $protocol) { |
109 | 109 | switch ($protocol) { |
110 | 110 | case 'http': |
111 | - case 'https': $value = preg_replace_callback($mode != 'all' ? '~(?:(https?)://([^\s<>]+)|(www\.[^\s<>]+?\.[^\s<>]+))(?<![\.,:;\?!\'"\|])~i' : '~(?:(https?)://([^\s<>]+)|([^\s<>]+?\.[^\s<>]+)(?<![\.,:]))~i', function ($match) use ($protocol, &$links, $attr) { if ($match[1]) $protocol = $match[1]; $link = $match[2] ?: $match[3]; return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . '://' . $link . '">' . rtrim($link, '/') . '</a>') . '>'; }, $value); break; |
|
112 | - case 'mail': $value = preg_replace_callback('~([^\s<>]+?@[^\s<>]+?\.[^\s<>]+)(?<![\.,:;\?!\'"\|])~', function ($match) use (&$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="mailto:' . $match[1] . '">' . $match[1] . '</a>') . '>'; }, $value); break; |
|
113 | - case 'twitter': $value = preg_replace_callback('~(?<!\w)[@#](\w++)~', function ($match) use (&$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="https://twitter.com/' . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . '">' . $match[0] . '</a>') . '>'; }, $value); break; |
|
111 | + case 'https': $value = preg_replace_callback($mode != 'all' ? '~(?:(https?)://([^\s<>]+)|(www\.[^\s<>]+?\.[^\s<>]+))(?<![\.,:;\?!\'"\|])~i' : '~(?:(https?)://([^\s<>]+)|([^\s<>]+?\.[^\s<>]+)(?<![\.,:]))~i', function($match) use ($protocol, &$links, $attr) { if ($match[1]) $protocol = $match[1]; $link = $match[2] ?: $match[3]; return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . '://' . $link . '">' . rtrim($link, '/') . '</a>') . '>'; }, $value); break; |
|
112 | + case 'mail': $value = preg_replace_callback('~([^\s<>]+?@[^\s<>]+?\.[^\s<>]+)(?<![\.,:;\?!\'"\|])~', function($match) use (&$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="mailto:' . $match[1] . '">' . $match[1] . '</a>') . '>'; }, $value); break; |
|
113 | + case 'twitter': $value = preg_replace_callback('~(?<!\w)[@#](\w++)~', function($match) use (&$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="https://twitter.com/' . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . '">' . $match[0] . '</a>') . '>'; }, $value); break; |
|
114 | 114 | |
115 | 115 | default: |
116 | - if (strpos($protocol, ':') === false) $protocol .= in_array($protocol, array('ftp', 'tftp', 'ssh', 'scp')) ? '://' : ':'; |
|
117 | - $value = preg_replace_callback($mode != 'all' ? '~' . preg_quote($protocol, '~') . '([^\s<>]+?)(?<![\.,:;\?!\'"\|])~i' : '~([^\s<>]+)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . $match[1] . '">' . $match[1] . '</a>') . '>'; }, $value); break; |
|
116 | + if (strpos($protocol, ':') === false) $protocol .= in_array($protocol, array('ftp', 'tftp', 'ssh', 'scp')) ? '://' : ':'; |
|
117 | + $value = preg_replace_callback($mode != 'all' ? '~' . preg_quote($protocol, '~') . '([^\s<>]+?)(?<![\.,:;\?!\'"\|])~i' : '~([^\s<>]+)(?<![\.,:])~i', function($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . $match[1] . '">' . $match[1] . '</a>') . '>'; }, $value); break; |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Insert all link |
122 | - return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { return $links[$match[1] - 1]; }, $value); |
|
122 | + return preg_replace_callback('/<(\d+)>/', function($match) use (&$links) { return $links[$match[1] - 1]; }, $value); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -31,7 +31,9 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function paragraph($value) |
33 | 33 | { |
34 | - if (!isset($value)) return null; |
|
34 | + if (!isset($value)) { |
|
35 | + return null; |
|
36 | + } |
|
35 | 37 | return '<p>' . preg_replace(array('~\n(\s*)\n\s*~', '~(?<!</p>)\n\s*~'), array("</p>\n\$1<p>", "<br>\n"), trim($value)) . '</p>'; |
36 | 38 | } |
37 | 39 | |
@@ -44,7 +46,9 @@ discard block |
||
44 | 46 | */ |
45 | 47 | public function line($value, $line=1) |
46 | 48 | { |
47 | - if (!isset($value)) return null; |
|
49 | + if (!isset($value)) { |
|
50 | + return null; |
|
51 | + } |
|
48 | 52 | |
49 | 53 | $lines = explode("\n", $value); |
50 | 54 | return isset($lines[$line-1]) ? $lines[$line-1] : null; |
@@ -60,7 +64,9 @@ discard block |
||
60 | 64 | */ |
61 | 65 | public function less($value, $replace = '...', $break = '<!-- pagebreak -->') |
62 | 66 | { |
63 | - if (!isset($value)) return null; |
|
67 | + if (!isset($value)) { |
|
68 | + return null; |
|
69 | + } |
|
64 | 70 | |
65 | 71 | $pos = stripos($value, $break); |
66 | 72 | return $pos === false ? $value : substr($value, 0, $pos) . $replace; |
@@ -76,7 +82,9 @@ discard block |
||
76 | 82 | */ |
77 | 83 | public function truncate($value, $length, $replace = '...') |
78 | 84 | { |
79 | - if (!isset($value)) return null; |
|
85 | + if (!isset($value)) { |
|
86 | + return null; |
|
87 | + } |
|
80 | 88 | return strlen($value) <= $length ? $value : substr($value, 0, $length - strip_tags($replace)) . $replace; |
81 | 89 | } |
82 | 90 | |
@@ -91,7 +99,9 @@ discard block |
||
91 | 99 | */ |
92 | 100 | public function linkify($value, $protocols = array('http', 'mail'), array $attributes = array(), $mode = 'normal') |
93 | 101 | { |
94 | - if (!isset($value)) return null; |
|
102 | + if (!isset($value)) { |
|
103 | + return null; |
|
104 | + } |
|
95 | 105 | |
96 | 106 | // Link attributes |
97 | 107 | $attr = ''; |
@@ -108,12 +118,17 @@ discard block |
||
108 | 118 | foreach ((array)$protocols as $protocol) { |
109 | 119 | switch ($protocol) { |
110 | 120 | case 'http': |
111 | - case 'https': $value = preg_replace_callback($mode != 'all' ? '~(?:(https?)://([^\s<>]+)|(www\.[^\s<>]+?\.[^\s<>]+))(?<![\.,:;\?!\'"\|])~i' : '~(?:(https?)://([^\s<>]+)|([^\s<>]+?\.[^\s<>]+)(?<![\.,:]))~i', function ($match) use ($protocol, &$links, $attr) { if ($match[1]) $protocol = $match[1]; $link = $match[2] ?: $match[3]; return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . '://' . $link . '">' . rtrim($link, '/') . '</a>') . '>'; }, $value); break; |
|
121 | + case 'https': $value = preg_replace_callback($mode != 'all' ? '~(?:(https?)://([^\s<>]+)|(www\.[^\s<>]+?\.[^\s<>]+))(?<![\.,:;\?!\'"\|])~i' : '~(?:(https?)://([^\s<>]+)|([^\s<>]+?\.[^\s<>]+)(?<![\.,:]))~i', function ($match) use ($protocol, &$links, $attr) { if ($match[1]) { |
|
122 | + $protocol = $match[1]; |
|
123 | + } |
|
124 | + $link = $match[2] ?: $match[3]; return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . '://' . $link . '">' . rtrim($link, '/') . '</a>') . '>'; }, $value); break; |
|
112 | 125 | case 'mail': $value = preg_replace_callback('~([^\s<>]+?@[^\s<>]+?\.[^\s<>]+)(?<![\.,:;\?!\'"\|])~', function ($match) use (&$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="mailto:' . $match[1] . '">' . $match[1] . '</a>') . '>'; }, $value); break; |
113 | 126 | case 'twitter': $value = preg_replace_callback('~(?<!\w)[@#](\w++)~', function ($match) use (&$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="https://twitter.com/' . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . '">' . $match[0] . '</a>') . '>'; }, $value); break; |
114 | 127 | |
115 | 128 | default: |
116 | - if (strpos($protocol, ':') === false) $protocol .= in_array($protocol, array('ftp', 'tftp', 'ssh', 'scp')) ? '://' : ':'; |
|
129 | + if (strpos($protocol, ':') === false) { |
|
130 | + $protocol .= in_array($protocol, array('ftp', 'tftp', 'ssh', 'scp')) ? '://' : ':'; |
|
131 | + } |
|
117 | 132 | $value = preg_replace_callback($mode != 'all' ? '~' . preg_quote($protocol, '~') . '([^\s<>]+?)(?<![\.,:;\?!\'"\|])~i' : '~([^\s<>]+)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . $match[1] . '">' . $match[1] . '</a>') . '>'; }, $value); break; |
118 | 133 | } |
119 | 134 | } |