Completed
Pull Request — master (#9)
by
unknown
03:29
created
src/Jasny/Twig/PcreExtension.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         
Please login to merge, or discard this patch.
tests/Jasny/Twig/DateExtensionTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 namespace Jasny\Twig;
4 4
 
5 5
 
6
-class DateExtensionTest extends \PHPUnit_Framework_TestCase  {
6
+class DateExtensionTest extends \PHPUnit_Framework_TestCase {
7 7
 
8 8
     public static function setUpBeforeClass() {
9 9
         parent::setUpBeforeClass();
Please login to merge, or discard this patch.
tests/Jasny/Twig/TextExtensionTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 namespace Jasny\Twig;
4 4
 
5 5
 
6
-class TextExtensionTest extends \PHPUnit_Framework_TestCase  {
6
+class TextExtensionTest extends \PHPUnit_Framework_TestCase {
7 7
 
8 8
     private function buildEnv($template) {
9 9
         $loader = new \Twig_Loader_Array(array(
Please login to merge, or discard this patch.
tests/Jasny/Twig/ArrayExtensionTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 namespace Jasny\Twig;
4 4
 
5 5
 
6
-class ArrayExtensionTest extends \PHPUnit_Framework_TestCase  {
6
+class ArrayExtensionTest extends \PHPUnit_Framework_TestCase {
7 7
 
8 8
     private function buildEnv($template) {
9 9
         $loader = new \Twig_Loader_Array(array(
Please login to merge, or discard this patch.
tests/Jasny/Twig/PcreExtensionTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 namespace Jasny\Twig;
4 4
 
5 5
 
6
-class PcreExtensionTest extends \PHPUnit_Framework_TestCase  {
6
+class PcreExtensionTest extends \PHPUnit_Framework_TestCase {
7 7
 
8 8
     private function buildEnv($template) {
9 9
         $loader = new \Twig_Loader_Array(array(
Please login to merge, or discard this patch.
src/Jasny/Twig/DateExtension.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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, \IntlTimeZone::getGMT(), $calendar)->getPattern());
79 79
     }
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
             $format_time = 'short';
148 148
             
149 149
             extract((array)$format, EXTR_PREFIX_ALL, 'format');
150
-            return $this->localDate($date, $format_date, $calendar) . ' ' . $this->localTime($date, $format_time, $calendar);
150
+            return $this->localDate($date, $format_date, $calendar).' '.$this->localTime($date, $format_time, $calendar);
151 151
         }
152 152
         
153 153
         list($format, $pattern) = $this->getFormat($format, $calendar);
@@ -199,18 +199,18 @@  discard block
 block discarded – undo
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
-        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];
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];
214 214
         
215 215
         return trim($duration, $seperator);
216 216
     }
Please login to merge, or discard this patch.
src/Jasny/Twig/TextExtension.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     public function paragraph($value)
33 33
     {
34 34
         if (!isset($value)) return null;
35
-        return '<p>' . preg_replace(array('~\n(\s*)\n\s*~', '~(?<!</p>)\n\s*~'), array("</p>\n\$1<p>", "<br>\n"), trim($value)) . '</p>';
35
+        return '<p>'.preg_replace(array('~\n(\s*)\n\s*~', '~(?<!</p>)\n\s*~'), array("</p>\n\$1<p>", "<br>\n"), trim($value)).'</p>';
36 36
     }
37 37
 
38 38
     /**
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
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
     /**
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         if (!isset($value)) return null;
64 64
         
65 65
         $pos = stripos($value, $break);
66
-        return $pos === false ? $value : substr($value, 0, $pos) . $replace;
66
+        return $pos === false ? $value : substr($value, 0, $pos).$replace;
67 67
     }
68 68
 
69 69
     /**
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     public function truncate($value, $length, $replace = '...')
78 78
     {
79 79
         if (!isset($value)) return null;
80
-        return strlen($value) <= $length ? $value : substr($value, 0, $length - strip_tags($replace)) . $replace;
80
+        return strlen($value) <= $length ? $value : substr($value, 0, $length - strip_tags($replace)).$replace;
81 81
     }
82 82
     
83 83
     /**
@@ -96,30 +96,30 @@  discard block
 block discarded – undo
96 96
         // Link attributes
97 97
         $attr = '';
98 98
         foreach ($attributes as $key => $val) {
99
-            $attr .= ' ' . $key . '="' . htmlentities($val) . '"';
99
+            $attr .= ' '.$key.'="'.htmlentities($val).'"';
100 100
         }
101 101
         
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
     /**
Please login to merge, or discard this patch.
src/Jasny/Twig/ArrayExtension.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@
 block discarded – undo
98 98
             if (!isset($value) || $value === false) continue;
99 99
             
100 100
             if ($value === true) $value = $key;
101
-            $str .= ' ' . $key . '="' . addcslashes($value, '"') . '"';
101
+            $str .= ' '.$key.'="'.addcslashes($value, '"').'"';
102 102
         }
103 103
         return trim($str);
104 104
     }
Please login to merge, or discard this patch.