Completed
Push — master ( 0cd027...19e79a )
by Stefano
03:00
created
classes/Map.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
      * @param  mixed $default (optional) The default value. If is a callable it will executed and the return value will be used.
30 30
      * @return mixed The value of the key or the default (resolved) value if the key not existed.
31 31
      */
32
-    public function get($key, $default=null){
33
-        if ($ptr =& $this->find($key,false)){
32
+    public function get($key, $default = null) {
33
+        if ($ptr = & $this->find($key, false)) {
34 34
             return $ptr;
35 35
         } else {
36
-            if ($default !== null){
36
+            if ($default !== null) {
37 37
                 return $this->set($key, is_callable($default) ? call_user_func($default) : $default);
38 38
             } else {
39 39
                 return null;
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
      * @param  mixed $value (optional) The value. If is a callable it will executed and the return value will be used.
48 48
      * @return mixed The value of the key or the default (resolved) value if the key not existed.
49 49
      */
50
-    public function set($key, $value=null){
50
+    public function set($key, $value = null) {
51 51
         if (is_array($key)) {
52 52
             return $this->merge($key);
53 53
         } else {
54
-            $ptr =& $this->find($key, true);
54
+            $ptr = & $this->find($key, true);
55 55
             return $ptr = $value;
56 56
         }
57 57
     }
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param  string $key The key path in dot notation
62 62
      * @param  boolean $compact (optional) Compact map removing empty paths.
63 63
      */
64
-    public function delete($key, $compact=true){
64
+    public function delete($key, $compact = true) {
65 65
         $this->set($key, null);
66 66
         if ($compact) $this->compact();
67 67
     }
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
      * @param  string $key The key path in dot notation
72 72
      * @return boolean
73 73
      */
74
-    public function exists($key){
74
+    public function exists($key) {
75 75
         return null !== $this->find($key, false);
76 76
     }
77 77
 
78 78
     /**
79 79
      * Clear all key path in map.
80 80
      */
81
-    public function clear(){
81
+    public function clear() {
82 82
         $this->fields = [];
83 83
     }
84 84
 
85
-    public function __construct($fields=null){
85
+    public function __construct($fields = null) {
86 86
         $this->load($fields);
87 87
     }
88 88
 
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
      * Load an associative array/object as the map source.
91 91
      * @param  string $fields The array to merge
92 92
      */
93
-    public function load($fields){
94
-        if ($fields) $this->fields = (array)$fields;
93
+    public function load($fields) {
94
+        if ($fields) $this->fields = (array) $fields;
95 95
     }
96 96
 
97 97
     /**
@@ -99,17 +99,17 @@  discard block
 block discarded – undo
99 99
      * @param  array   $array The array to merge
100 100
      * @param  boolean $merge_back If `true` merge the map over the $array, if `false` (default) the reverse.
101 101
      */
102
-    public function merge($array, $merge_back=false){
102
+    public function merge($array, $merge_back = false) {
103 103
         $this->fields = $merge_back
104
-            ? array_replace_recursive((array)$array, $this->fields)
105
-            : array_replace_recursive($this->fields, (array)$array);
104
+            ? array_replace_recursive((array) $array, $this->fields)
105
+            : array_replace_recursive($this->fields, (array) $array);
106 106
     }
107 107
 
108 108
     /**
109 109
      * Compact map removing empty paths
110 110
      */
111 111
 
112
-    public function compact(){
112
+    public function compact() {
113 113
 
114 114
         $array_filter_rec = function($input, $callback = null) use (&$array_filter_rec) {
115 115
             foreach ($input as &$value) {
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             return array_filter($input, $callback);
121 121
         };
122 122
 
123
-        $this->fields = $array_filter_rec($this->fields,function($a){ return $a !== null; });
123
+        $this->fields = $array_filter_rec($this->fields, function($a) { return $a !== null;});
124 124
     }
125 125
 
126 126
     /**
@@ -130,17 +130,17 @@  discard block
 block discarded – undo
130 130
      * @param  callable  If passed this callback will be applied to the founded value.
131 131
      * @return mixed The founded value.
132 132
      */
133
-    public function & find($path, $create=false, callable $operation=null) {
134
-        $tok = strtok($path,'.');
133
+    public function & find($path, $create = false, callable $operation = null) {
134
+        $tok = strtok($path, '.');
135 135
 
136
-        if($create){
137
-            $value =& $this->fields;
136
+        if ($create) {
137
+            $value = & $this->fields;
138 138
         } else {
139 139
             $value = $this->fields;
140 140
         }
141 141
 
142
-        while($tok !== false){
143
-            $value =& $value[$tok];
142
+        while ($tok !== false) {
143
+            $value = & $value[$tok];
144 144
             $tok = strtok('.');
145 145
         }
146 146
         if (is_callable($operation)) $operation($value);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      *
155 155
      * @return string        The json object
156 156
      */
157
-    public function jsonSerialize(){
157
+    public function jsonSerialize() {
158 158
       return $this->fields;
159 159
     }
160 160
 
Please login to merge, or discard this patch.
Braces   +23 added lines, -17 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
      * @param  mixed $default (optional) The default value. If is a callable it will executed and the return value will be used.
30 30
      * @return mixed The value of the key or the default (resolved) value if the key not existed.
31 31
      */
32
-    public function get($key, $default=null){
33
-        if ($ptr =& $this->find($key,false)){
32
+    public function get($key, $default=null) {
33
+        if ($ptr =& $this->find($key,false)) {
34 34
             return $ptr;
35 35
         } else {
36
-            if ($default !== null){
36
+            if ($default !== null) {
37 37
                 return $this->set($key, is_callable($default) ? call_user_func($default) : $default);
38 38
             } else {
39 39
                 return null;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * @param  mixed $value (optional) The value. If is a callable it will executed and the return value will be used.
48 48
      * @return mixed The value of the key or the default (resolved) value if the key not existed.
49 49
      */
50
-    public function set($key, $value=null){
50
+    public function set($key, $value=null) {
51 51
         if (is_array($key)) {
52 52
             return $this->merge($key);
53 53
         } else {
@@ -61,9 +61,11 @@  discard block
 block discarded – undo
61 61
      * @param  string $key The key path in dot notation
62 62
      * @param  boolean $compact (optional) Compact map removing empty paths.
63 63
      */
64
-    public function delete($key, $compact=true){
64
+    public function delete($key, $compact=true) {
65 65
         $this->set($key, null);
66
-        if ($compact) $this->compact();
66
+        if ($compact) {
67
+          $this->compact();
68
+        }
67 69
     }
68 70
 
69 71
     /**
@@ -71,18 +73,18 @@  discard block
 block discarded – undo
71 73
      * @param  string $key The key path in dot notation
72 74
      * @return boolean
73 75
      */
74
-    public function exists($key){
76
+    public function exists($key) {
75 77
         return null !== $this->find($key, false);
76 78
     }
77 79
 
78 80
     /**
79 81
      * Clear all key path in map.
80 82
      */
81
-    public function clear(){
83
+    public function clear() {
82 84
         $this->fields = [];
83 85
     }
84 86
 
85
-    public function __construct($fields=null){
87
+    public function __construct($fields=null) {
86 88
         $this->load($fields);
87 89
     }
88 90
 
@@ -90,8 +92,10 @@  discard block
 block discarded – undo
90 92
      * Load an associative array/object as the map source.
91 93
      * @param  string $fields The array to merge
92 94
      */
93
-    public function load($fields){
94
-        if ($fields) $this->fields = (array)$fields;
95
+    public function load($fields) {
96
+        if ($fields) {
97
+          $this->fields = (array)$fields;
98
+        }
95 99
     }
96 100
 
97 101
     /**
@@ -99,7 +103,7 @@  discard block
 block discarded – undo
99 103
      * @param  array   $array The array to merge
100 104
      * @param  boolean $merge_back If `true` merge the map over the $array, if `false` (default) the reverse.
101 105
      */
102
-    public function merge($array, $merge_back=false){
106
+    public function merge($array, $merge_back=false) {
103 107
         $this->fields = $merge_back
104 108
             ? array_replace_recursive((array)$array, $this->fields)
105 109
             : array_replace_recursive($this->fields, (array)$array);
@@ -109,7 +113,7 @@  discard block
 block discarded – undo
109 113
      * Compact map removing empty paths
110 114
      */
111 115
 
112
-    public function compact(){
116
+    public function compact() {
113 117
 
114 118
         $array_filter_rec = function($input, $callback = null) use (&$array_filter_rec) {
115 119
             foreach ($input as &$value) {
@@ -133,17 +137,19 @@  discard block
 block discarded – undo
133 137
     public function & find($path, $create=false, callable $operation=null) {
134 138
         $tok = strtok($path,'.');
135 139
 
136
-        if($create){
140
+        if($create) {
137 141
             $value =& $this->fields;
138 142
         } else {
139 143
             $value = $this->fields;
140 144
         }
141 145
 
142
-        while($tok !== false){
146
+        while($tok !== false) {
143 147
             $value =& $value[$tok];
144 148
             $tok = strtok('.');
145 149
         }
146
-        if (is_callable($operation)) $operation($value);
150
+        if (is_callable($operation)) {
151
+          $operation($value);
152
+        }
147 153
         return $value;
148 154
     }
149 155
 
@@ -154,7 +160,7 @@  discard block
 block discarded – undo
154 160
      *
155 161
      * @return string        The json object
156 162
      */
157
-    public function jsonSerialize(){
163
+    public function jsonSerialize() {
158 164
       return $this->fields;
159 165
     }
160 166
 
Please login to merge, or discard this patch.
classes/Filter.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 
16 16
     protected static $_modders = [];
17 17
 
18
-    public static function add($name,callable $modder = null){
19
-        if( is_array($name) ) {
18
+    public static function add($name, callable $modder = null) {
19
+        if (is_array($name)) {
20 20
             foreach ($name as $key => $value) {
21 21
                 static::$_modders[$key][] = $value;
22 22
             }
@@ -25,26 +25,26 @@  discard block
 block discarded – undo
25 25
         }
26 26
     }
27 27
 
28
-    public static function single($name,callable $modder){
28
+    public static function single($name, callable $modder) {
29 29
         static::$_modders[$name] = [$modder];
30 30
     }
31 31
 
32
-    public static function remove($name,callable $modder = null){
33
-        if($modder === null) {
32
+    public static function remove($name, callable $modder = null) {
33
+        if ($modder === null) {
34 34
             unset(static::$_modders[$name]);
35 35
         } else {
36
-            if ($idx = array_search($modder,static::$_modders[$name],true))
36
+            if ($idx = array_search($modder, static::$_modders[$name], true))
37 37
                 unset(static::$_modders[$name][$idx]);
38 38
         }
39 39
     }
40 40
 
41
-    public static function with($names, $default){
42
-      foreach ((array)$names as $name) {
41
+    public static function with($names, $default) {
42
+      foreach ((array) $names as $name) {
43 43
         if (!empty(static::$_modders[$name])) {
44 44
             $value = $default;
45
-            $args = array_slice( func_get_args(), 2 );
45
+            $args = array_slice(func_get_args(), 2);
46 46
             foreach (static::$_modders[$name] as $modder) {
47
-                $value = call_user_func( $modder,$value,$args );
47
+                $value = call_user_func($modder, $value, $args);
48 48
             }
49 49
             return $value;
50 50
         }
Please login to merge, or discard this patch.
Braces   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
     protected static $_modders = [];
17 17
 
18
-    public static function add($name,callable $modder = null){
18
+    public static function add($name,callable $modder = null) {
19 19
         if( is_array($name) ) {
20 20
             foreach ($name as $key => $value) {
21 21
                 static::$_modders[$key][] = $value;
@@ -25,20 +25,21 @@  discard block
 block discarded – undo
25 25
         }
26 26
     }
27 27
 
28
-    public static function single($name,callable $modder){
28
+    public static function single($name,callable $modder) {
29 29
         static::$_modders[$name] = [$modder];
30 30
     }
31 31
 
32
-    public static function remove($name,callable $modder = null){
32
+    public static function remove($name,callable $modder = null) {
33 33
         if($modder === null) {
34 34
             unset(static::$_modders[$name]);
35 35
         } else {
36
-            if ($idx = array_search($modder,static::$_modders[$name],true))
37
-                unset(static::$_modders[$name][$idx]);
36
+            if ($idx = array_search($modder,static::$_modders[$name],true)) {
37
+                            unset(static::$_modders[$name][$idx]);
38
+            }
38 39
         }
39 40
     }
40 41
 
41
-    public static function with($names, $default){
42
+    public static function with($names, $default) {
42 43
       foreach ((array)$names as $name) {
43 44
         if (!empty(static::$_modders[$name])) {
44 45
             $value = $default;
Please login to merge, or discard this patch.
classes/Text.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
    * @param mixed $t  The text template
27 27
    * @param mixed $v (default: null)  The array of values exposed in template.
28 28
    * @return string
29
-  */
29
+   */
30 30
   public static function render($t,$v=null){
31 31
     if (empty($v)) return preg_replace('/{{[^}]+}}/','',$t);
32 32
     for(  // Init
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -27,19 +27,19 @@  discard block
 block discarded – undo
27 27
    * @param mixed $v (default: null)  The array of values exposed in template.
28 28
    * @return string
29 29
   */
30
-  public static function render($t,$v=null){
31
-    if (empty($v)) return preg_replace('/{{[^}]+}}/','',$t);
32
-    for(  // Init
30
+  public static function render($t, $v = null) {
31
+    if (empty($v)) return preg_replace('/{{[^}]+}}/', '', $t);
32
+    for (  // Init
33 33
           $r = $ox = $x = false;
34 34
           // While
35
-          false !== ($x = $y = strpos($t,'{{',$x));
35
+          false !== ($x = $y = strpos($t, '{{', $x));
36 36
           // Do
37
-          $r .= substr($t, $ox, $x-$ox),
38
-          $c  = substr($t, $x += 2, $l = ( $y = strpos($t,'}}', $x) ) - $x),
37
+          $r .= substr($t, $ox, $x - $ox),
38
+          $c  = substr($t, $x += 2, $l = ($y = strpos($t, '}}', $x)) - $x),
39 39
           $ox = $x += $l + 2,
40
-          $r .= Object::fetch(trim($c),$v)?:''
40
+          $r .= Object::fetch(trim($c), $v) ?: ''
41 41
     );
42
-    return $r===false ? $t : $r.substr($t,$ox);
42
+    return $r === false ? $t : $r.substr($t, $ox);
43 43
   }
44 44
 
45 45
   /**
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
    * @param  string $text The text to slugify
55 55
    * @return string       The slug.
56 56
    */
57
-  public static function slugify($text){
57
+  public static function slugify($text) {
58 58
     return preg_replace(
59
-      ['(\s+)','([^a-z0-9-])i','(-+)'],['-','','-'],
59
+      ['(\s+)', '([^a-z0-9-])i', '(-+)'], ['-', '', '-'],
60 60
       strtolower(self::removeAccents($text)));
61 61
   }
62 62
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
    * @param  string $text The text to translit
73 73
    * @return string       The translited text
74 74
    */
75
-  public static function removeAccents($text){
75
+  public static function removeAccents($text) {
76 76
     static $diac;
77 77
     return strtr(
78 78
       utf8_decode($text),
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,8 +27,10 @@  discard block
 block discarded – undo
27 27
    * @param mixed $v (default: null)  The array of values exposed in template.
28 28
    * @return string
29 29
   */
30
-  public static function render($t,$v=null){
31
-    if (empty($v)) return preg_replace('/{{[^}]+}}/','',$t);
30
+  public static function render($t,$v=null) {
31
+    if (empty($v)) {
32
+      return preg_replace('/{{[^}]+}}/','',$t);
33
+    }
32 34
     for(  // Init
33 35
           $r = $ox = $x = false;
34 36
           // While
@@ -54,7 +56,7 @@  discard block
 block discarded – undo
54 56
    * @param  string $text The text to slugify
55 57
    * @return string       The slug.
56 58
    */
57
-  public static function slugify($text){
59
+  public static function slugify($text) {
58 60
     return preg_replace(
59 61
       ['(\s+)','([^a-z0-9-])i','(-+)'],['-','','-'],
60 62
       strtolower(self::removeAccents($text)));
@@ -72,7 +74,7 @@  discard block
 block discarded – undo
72 74
    * @param  string $text The text to translit
73 75
    * @return string       The translited text
74 76
    */
75
-  public static function removeAccents($text){
77
+  public static function removeAccents($text) {
76 78
     static $diac;
77 79
     return strtr(
78 80
       utf8_decode($text),
Please login to merge, or discard this patch.