@@ -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 |
@@ -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 | /** |
@@ -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]; |