Completed
Push — master ( 4a7f99...ceaa03 )
by Stefano
03:53
created
classes/Map.php 2 patches
Spacing   +24 added lines, -24 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,18 +130,18 @@  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,'.');
135
-        if ( $create ) {
136
-            $value =& $this->fields;
133
+    public function & find($path, $create = false, callable $operation = null) {
134
+        $tok = strtok($path, '.');
135
+        if ($create) {
136
+            $value = & $this->fields;
137 137
         } else {
138 138
             $value = $this->fields;
139 139
         }
140
-        while ( $tok !== false ){
141
-            $value =& $value[$tok];
140
+        while ($tok !== false) {
141
+            $value = & $value[$tok];
142 142
             $tok = strtok('.');
143 143
         }
144
-        if ( is_callable($operation) ) $operation($value);
144
+        if (is_callable($operation)) $operation($value);
145 145
         return $value;
146 146
     }
147 147
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      *
153 153
      * @return string        The json object
154 154
      */
155
-    public function jsonSerialize(){
155
+    public function jsonSerialize() {
156 156
       return $this->fields;
157 157
     }
158 158
 
Please login to merge, or discard this patch.
Braces   +22 added lines, -16 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) {
@@ -137,11 +141,13 @@  discard block
 block discarded – undo
137 141
         } else {
138 142
             $value = $this->fields;
139 143
         }
140
-        while ( $tok !== false ){
144
+        while ( $tok !== false ) {
141 145
             $value =& $value[$tok];
142 146
             $tok = strtok('.');
143 147
         }
144
-        if ( is_callable($operation) ) $operation($value);
148
+        if ( is_callable($operation) ) {
149
+          $operation($value);
150
+        }
145 151
         return $value;
146 152
     }
147 153
 
@@ -152,7 +158,7 @@  discard block
 block discarded – undo
152 158
      *
153 159
      * @return string        The json object
154 160
      */
155
-    public function jsonSerialize(){
161
+    public function jsonSerialize() {
156 162
       return $this->fields;
157 163
     }
158 164
 
Please login to merge, or discard this patch.
classes/Hash.php 5 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -110,6 +110,9 @@
 block discarded – undo
110 110
 		}
111 111
 	}
112 112
 
113
+  /**
114
+   * @param string $key
115
+   */
113 116
   public static function murmur($key, $seed = 0, $as_integer=false) {
114 117
 		$key = (string) $key;
115 118
 		$klen = strlen($key);
Please login to merge, or discard this patch.
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -11,151 +11,151 @@
 block discarded – undo
11 11
  */
12 12
 
13 13
 class Hash {
14
-	use Module;
15
-
16
-	/**
17
-	 * Create ah hash for payload
18
-	 * @param  mixed $payload The payload string/object/array
19
-	 * @param  integer $method  The hashing method, default is "md5"
20
-	 * @return string          The hash string
21
-	 */
22
-	public static function make($payload, $method = 'md5') {
23
-		return $method == 'murmur' ? static::murmur(serialize($payload)) : hash($method, serialize($payload));
24
-	}
25
-
26
-	/**
27
-	 * Verify if given payload matches hash
28
-	 * @param  mixed $payload  The payload string/object/array
29
-	 * @param  string $hash    The hash string
30
-	 * @param  integer $method The hashing method
31
-	 * @return bool            Returns `true` if payload matches hash
32
-	 */
33
-	public static function verify($payload, $hash, $method = 'md5') {
34
-		return static::make($payload, $method) == $hash;
35
-	}
36
-
37
-	/**
38
-	 * List registered hashing algorithms
39
-	 *
40
-	 * @method methods
41
-	 *
42
-	 * @return array   Array containing the list of supported hashing algorithms.
43
-	 */
44
-	public static function methods() {
14
+  use Module;
15
+
16
+  /**
17
+   * Create ah hash for payload
18
+   * @param  mixed $payload The payload string/object/array
19
+   * @param  integer $method  The hashing method, default is "md5"
20
+   * @return string          The hash string
21
+   */
22
+  public static function make($payload, $method = 'md5') {
23
+    return $method == 'murmur' ? static::murmur(serialize($payload)) : hash($method, serialize($payload));
24
+  }
25
+
26
+  /**
27
+   * Verify if given payload matches hash
28
+   * @param  mixed $payload  The payload string/object/array
29
+   * @param  string $hash    The hash string
30
+   * @param  integer $method The hashing method
31
+   * @return bool            Returns `true` if payload matches hash
32
+   */
33
+  public static function verify($payload, $hash, $method = 'md5') {
34
+    return static::make($payload, $method) == $hash;
35
+  }
36
+
37
+  /**
38
+   * List registered hashing algorithms
39
+   *
40
+   * @method methods
41
+   *
42
+   * @return array   Array containing the list of supported hashing algorithms.
43
+   */
44
+  public static function methods() {
45 45
     // Merge PHP provided algos with ours (murmur)
46
-		return array_merge(hash_algos(), ['murmur','murmurhash3']);
47
-	}
48
-
49
-	/**
50
-	 * Check if an alghoritm is registered in current PHP
51
-	 *
52
-	 * @method can
53
-	 *
54
-	 * @param  string $algo The hashing algorithm name
55
-	 *
56
-	 * @return bool
57
-	 */
58
-	public static function can($algo) {
46
+    return array_merge(hash_algos(), ['murmur','murmurhash3']);
47
+  }
48
+
49
+  /**
50
+   * Check if an alghoritm is registered in current PHP
51
+   *
52
+   * @method can
53
+   *
54
+   * @param  string $algo The hashing algorithm name
55
+   *
56
+   * @return bool
57
+   */
58
+  public static function can($algo) {
59 59
     // Faster than : in_array(explode(',',implode(',',static::methods())))
60
-		return strpos(implode(',',static::methods()).',', "$algo,") !== false;
61
-	}
62
-
63
-	/**
64
-	 * Static magic for creating hashes with a specified algorithm.
65
-	 *
66
-	 * See [hash-algos](http://php.net/manual/it/function.hash-algos.php) for a list of algorithms
67
-	 */
68
-	public static function __callStatic($method, $params) {
69
-		return self::make(current($params), $method);
70
-	}
71
-
72
-	public static function uuid($type = 4, $namespace = '', $name = '') {
73
-		switch ($type) {
74
-		case 3:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
75
-				'[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
76
-				return false;
77
-			}
78
-
79
-			$nhex = str_replace(array('-', '{', '}'), '', $namespace);
80
-			$nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
81
-				$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
82
-			}
83
-
84
-			$hash = md5($nstr . $name);
85
-			return sprintf('%08s-%04s-%04x-%04x-%12s',
86
-				substr($hash, 0, 8), substr($hash, 8, 4),
87
-				(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
88
-				(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
89
-				substr($hash, 20, 12));
90
-		case 5:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
91
-				'[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
92
-				return false;
93
-			}
94
-
95
-			$nhex = str_replace(array('-', '{', '}'), '', $namespace);
96
-			$nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
97
-				$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
98
-			}
99
-
100
-			$hash = sha1($nstr . $name);
101
-			return sprintf('%08s-%04s-%04x-%04x-%12s',
102
-				substr($hash, 0, 8), substr($hash, 8, 4),
103
-				(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
104
-				(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
105
-				substr($hash, 20, 12));
106
-		default:case 4:return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
107
-				mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
108
-				mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
109
-				mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
110
-		}
111
-	}
60
+    return strpos(implode(',',static::methods()).',', "$algo,") !== false;
61
+  }
62
+
63
+  /**
64
+   * Static magic for creating hashes with a specified algorithm.
65
+   *
66
+   * See [hash-algos](http://php.net/manual/it/function.hash-algos.php) for a list of algorithms
67
+   */
68
+  public static function __callStatic($method, $params) {
69
+    return self::make(current($params), $method);
70
+  }
71
+
72
+  public static function uuid($type = 4, $namespace = '', $name = '') {
73
+    switch ($type) {
74
+    case 3:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
75
+        '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
76
+        return false;
77
+      }
78
+
79
+      $nhex = str_replace(array('-', '{', '}'), '', $namespace);
80
+      $nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
81
+        $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
82
+      }
83
+
84
+      $hash = md5($nstr . $name);
85
+      return sprintf('%08s-%04s-%04x-%04x-%12s',
86
+        substr($hash, 0, 8), substr($hash, 8, 4),
87
+        (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
88
+        (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
89
+        substr($hash, 20, 12));
90
+    case 5:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
91
+        '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
92
+        return false;
93
+      }
94
+
95
+      $nhex = str_replace(array('-', '{', '}'), '', $namespace);
96
+      $nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
97
+        $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
98
+      }
99
+
100
+      $hash = sha1($nstr . $name);
101
+      return sprintf('%08s-%04s-%04x-%04x-%12s',
102
+        substr($hash, 0, 8), substr($hash, 8, 4),
103
+        (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
104
+        (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
105
+        substr($hash, 20, 12));
106
+    default:case 4:return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
107
+        mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
108
+        mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
109
+        mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
110
+    }
111
+  }
112 112
 
113 113
   public static function murmur($key, $seed = 0, $as_integer=false) {
114
-		$key = (string) $key;
115
-		$klen = strlen($key);
116
-		$h1 = $seed;
117
-		for ($i = 0, $bytes = $klen - ($remainder = $klen & 3); $i < $bytes;) {
118
-			$k1 = ((ord($key[$i]) & 0xff))
119
-			 | ((ord($key[++$i]) & 0xff) << 8)
120
-			 | ((ord($key[++$i]) & 0xff) << 16)
121
-			 | ((ord($key[++$i]) & 0xff) << 24);
122
-			++$i;
123
-			$k1 = (((($k1 & 0xffff) * 0xcc9e2d51)
124
-				 + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000)) * 0xcc9e2d51) & 0xffff) << 16)))
125
-			 & 0xffffffff;
126
-			$k1 = $k1 << 15 | ($k1 >= 0 ? $k1 >> 17 : (($k1 & 0x7fffffff) >> 17) | 0x4000);
127
-			$k1 = (((($k1 & 0xffff) * 0x1b873593) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
128
-				 * 0x1b873593) & 0xffff) << 16))) & 0xffffffff;
129
-			$h1 ^= $k1;
130
-			$h1 = $h1 << 13 | ($h1 >= 0 ? $h1 >> 19 : (($h1 & 0x7fffffff) >> 19) | 0x1000);
131
-			$h1b = (((($h1 & 0xffff) * 5) + ((((($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000)) * 5)
132
-				 & 0xffff) << 16))) & 0xffffffff;
133
-			$h1 = ((($h1b & 0xffff) + 0x6b64) + ((((($h1b >= 0 ? $h1b >> 16 : (($h1b & 0x7fffffff) >> 16) | 0x8000))
134
-				 + 0xe654) & 0xffff) << 16));
135
-		}
136
-		$k1 = 0;
137
-		switch ($remainder) {
138
-		case 3:$k1 ^= (ord($key[$i + 2]) & 0xff) << 16;
139
-		case 2:$k1 ^= (ord($key[$i + 1]) & 0xff) << 8;
140
-		case 1:$k1 ^= (ord($key[$i]) & 0xff);
141
-			$k1 = ((($k1 & 0xffff) * 0xcc9e2d51) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
142
-				 * 0xcc9e2d51) & 0xffff) << 16)) & 0xffffffff;
143
-			$k1 = $k1 << 15 | ($k1 >= 0 ? $k1 >> 17 : (($k1 & 0x7fffffff) >> 17) | 0x4000);
144
-			$k1 = ((($k1 & 0xffff) * 0x1b873593) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
145
-				 * 0x1b873593) & 0xffff) << 16)) & 0xffffffff;
146
-			$h1 ^= $k1;
147
-		}
148
-		$h1 ^= $klen;
149
-		$h1 ^= ($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000);
150
-		$h1 = ((($h1 & 0xffff) * 0x85ebca6b) + ((((($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000))
151
-			 * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;
152
-		$h1 ^= ($h1 >= 0 ? $h1 >> 13 : (($h1 & 0x7fffffff) >> 13) | 0x40000);
153
-		$h1 = (((($h1 & 0xffff) * 0xc2b2ae35) + ((((($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000))
154
-			 * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;
155
-		$h1 ^= ($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000);
156
-
157
-		return $as_integer ? $h1 : base_convert($h1 ,10, 32);
158
-	}
114
+    $key = (string) $key;
115
+    $klen = strlen($key);
116
+    $h1 = $seed;
117
+    for ($i = 0, $bytes = $klen - ($remainder = $klen & 3); $i < $bytes;) {
118
+      $k1 = ((ord($key[$i]) & 0xff))
119
+        | ((ord($key[++$i]) & 0xff) << 8)
120
+        | ((ord($key[++$i]) & 0xff) << 16)
121
+        | ((ord($key[++$i]) & 0xff) << 24);
122
+      ++$i;
123
+      $k1 = (((($k1 & 0xffff) * 0xcc9e2d51)
124
+         + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000)) * 0xcc9e2d51) & 0xffff) << 16)))
125
+        & 0xffffffff;
126
+      $k1 = $k1 << 15 | ($k1 >= 0 ? $k1 >> 17 : (($k1 & 0x7fffffff) >> 17) | 0x4000);
127
+      $k1 = (((($k1 & 0xffff) * 0x1b873593) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
128
+         * 0x1b873593) & 0xffff) << 16))) & 0xffffffff;
129
+      $h1 ^= $k1;
130
+      $h1 = $h1 << 13 | ($h1 >= 0 ? $h1 >> 19 : (($h1 & 0x7fffffff) >> 19) | 0x1000);
131
+      $h1b = (((($h1 & 0xffff) * 5) + ((((($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000)) * 5)
132
+          & 0xffff) << 16))) & 0xffffffff;
133
+      $h1 = ((($h1b & 0xffff) + 0x6b64) + ((((($h1b >= 0 ? $h1b >> 16 : (($h1b & 0x7fffffff) >> 16) | 0x8000))
134
+         + 0xe654) & 0xffff) << 16));
135
+    }
136
+    $k1 = 0;
137
+    switch ($remainder) {
138
+    case 3:$k1 ^= (ord($key[$i + 2]) & 0xff) << 16;
139
+    case 2:$k1 ^= (ord($key[$i + 1]) & 0xff) << 8;
140
+    case 1:$k1 ^= (ord($key[$i]) & 0xff);
141
+      $k1 = ((($k1 & 0xffff) * 0xcc9e2d51) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
142
+         * 0xcc9e2d51) & 0xffff) << 16)) & 0xffffffff;
143
+      $k1 = $k1 << 15 | ($k1 >= 0 ? $k1 >> 17 : (($k1 & 0x7fffffff) >> 17) | 0x4000);
144
+      $k1 = ((($k1 & 0xffff) * 0x1b873593) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
145
+         * 0x1b873593) & 0xffff) << 16)) & 0xffffffff;
146
+      $h1 ^= $k1;
147
+    }
148
+    $h1 ^= $klen;
149
+    $h1 ^= ($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000);
150
+    $h1 = ((($h1 & 0xffff) * 0x85ebca6b) + ((((($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000))
151
+       * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;
152
+    $h1 ^= ($h1 >= 0 ? $h1 >> 13 : (($h1 & 0x7fffffff) >> 13) | 0x40000);
153
+    $h1 = (((($h1 & 0xffff) * 0xc2b2ae35) + ((((($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000))
154
+       * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;
155
+    $h1 ^= ($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000);
156
+
157
+    return $as_integer ? $h1 : base_convert($h1 ,10, 32);
158
+  }
159 159
 
160 160
   public static function random($bytes=9){
161 161
     return strtr(base64_encode(random_bytes($bytes)),'+/=','-_');
Please login to merge, or discard this patch.
Switch Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -71,42 +71,42 @@  discard block
 block discarded – undo
71 71
 
72 72
 	public static function uuid($type = 4, $namespace = '', $name = '') {
73 73
 		switch ($type) {
74
-		case 3:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
75
-				'[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
76
-				return false;
77
-			}
78
-
79
-			$nhex = str_replace(array('-', '{', '}'), '', $namespace);
80
-			$nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
81
-				$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
82
-			}
83
-
84
-			$hash = md5($nstr . $name);
85
-			return sprintf('%08s-%04s-%04x-%04x-%12s',
86
-				substr($hash, 0, 8), substr($hash, 8, 4),
87
-				(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
88
-				(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
89
-				substr($hash, 20, 12));
90
-		case 5:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
91
-				'[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
92
-				return false;
93
-			}
94
-
95
-			$nhex = str_replace(array('-', '{', '}'), '', $namespace);
96
-			$nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
97
-				$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
98
-			}
99
-
100
-			$hash = sha1($nstr . $name);
101
-			return sprintf('%08s-%04s-%04x-%04x-%12s',
102
-				substr($hash, 0, 8), substr($hash, 8, 4),
103
-				(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
104
-				(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
105
-				substr($hash, 20, 12));
106
-		default:case 4:return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
107
-				mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
108
-				mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
109
-				mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
74
+		  case 3:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
75
+				  '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
76
+				  return false;
77
+			  }
78
+
79
+			  $nhex = str_replace(array('-', '{', '}'), '', $namespace);
80
+			  $nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
81
+				  $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
82
+			  }
83
+
84
+			  $hash = md5($nstr . $name);
85
+			  return sprintf('%08s-%04s-%04x-%04x-%12s',
86
+				  substr($hash, 0, 8), substr($hash, 8, 4),
87
+				  (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
88
+				  (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
89
+				  substr($hash, 20, 12));
90
+		  case 5:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
91
+				  '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
92
+				  return false;
93
+			  }
94
+
95
+			  $nhex = str_replace(array('-', '{', '}'), '', $namespace);
96
+			  $nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
97
+				  $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
98
+			  }
99
+
100
+			  $hash = sha1($nstr . $name);
101
+			  return sprintf('%08s-%04s-%04x-%04x-%12s',
102
+				  substr($hash, 0, 8), substr($hash, 8, 4),
103
+				  (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
104
+				  (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
105
+				  substr($hash, 20, 12));
106
+		  default:case 4:return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
107
+				  mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
108
+				  mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
109
+				  mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
110 110
 		}
111 111
 	}
112 112
 
@@ -135,15 +135,15 @@  discard block
 block discarded – undo
135 135
 		}
136 136
 		$k1 = 0;
137 137
 		switch ($remainder) {
138
-		case 3:$k1 ^= (ord($key[$i + 2]) & 0xff) << 16;
139
-		case 2:$k1 ^= (ord($key[$i + 1]) & 0xff) << 8;
140
-		case 1:$k1 ^= (ord($key[$i]) & 0xff);
141
-			$k1 = ((($k1 & 0xffff) * 0xcc9e2d51) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
142
-				 * 0xcc9e2d51) & 0xffff) << 16)) & 0xffffffff;
143
-			$k1 = $k1 << 15 | ($k1 >= 0 ? $k1 >> 17 : (($k1 & 0x7fffffff) >> 17) | 0x4000);
144
-			$k1 = ((($k1 & 0xffff) * 0x1b873593) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
145
-				 * 0x1b873593) & 0xffff) << 16)) & 0xffffffff;
146
-			$h1 ^= $k1;
138
+		  case 3:$k1 ^= (ord($key[$i + 2]) & 0xff) << 16;
139
+		  case 2:$k1 ^= (ord($key[$i + 1]) & 0xff) << 8;
140
+		  case 1:$k1 ^= (ord($key[$i]) & 0xff);
141
+			  $k1 = ((($k1 & 0xffff) * 0xcc9e2d51) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
142
+				   * 0xcc9e2d51) & 0xffff) << 16)) & 0xffffffff;
143
+			  $k1 = $k1 << 15 | ($k1 >= 0 ? $k1 >> 17 : (($k1 & 0x7fffffff) >> 17) | 0x4000);
144
+			  $k1 = ((($k1 & 0xffff) * 0x1b873593) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000))
145
+				   * 0x1b873593) & 0xffff) << 16)) & 0xffffffff;
146
+			  $h1 ^= $k1;
147 147
 		}
148 148
 		$h1 ^= $klen;
149 149
 		$h1 ^= ($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000);
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public static function methods() {
45 45
     // Merge PHP provided algos with ours (murmur)
46
-		return array_merge(hash_algos(), ['murmur','murmurhash3']);
46
+		return array_merge(hash_algos(), ['murmur', 'murmurhash3']);
47 47
 	}
48 48
 
49 49
 	/**
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public static function can($algo) {
59 59
     // Faster than : in_array(explode(',',implode(',',static::methods())))
60
-		return strpos(implode(',',static::methods()).',', "$algo,") !== false;
60
+		return strpos(implode(',', static::methods()).',', "$algo,") !== false;
61 61
 	}
62 62
 
63 63
 	/**
@@ -71,33 +71,33 @@  discard block
 block discarded – undo
71 71
 
72 72
 	public static function uuid($type = 4, $namespace = '', $name = '') {
73 73
 		switch ($type) {
74
-		case 3:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
74
+		case 3:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
75 75
 				'[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
76 76
 				return false;
77 77
 			}
78 78
 
79 79
 			$nhex = str_replace(array('-', '{', '}'), '', $namespace);
80
-			$nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
81
-				$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
80
+			$nstr = '';for ($i = 0;$i < strlen($nhex);$i += 2) {
81
+				$nstr .= chr(hexdec($nhex[$i].$nhex[$i + 1]));
82 82
 			}
83 83
 
84
-			$hash = md5($nstr . $name);
84
+			$hash = md5($nstr.$name);
85 85
 			return sprintf('%08s-%04s-%04x-%04x-%12s',
86 86
 				substr($hash, 0, 8), substr($hash, 8, 4),
87 87
 				(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
88 88
 				(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
89 89
 				substr($hash, 20, 12));
90
-		case 5:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
90
+		case 5:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
91 91
 				'[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) {
92 92
 				return false;
93 93
 			}
94 94
 
95 95
 			$nhex = str_replace(array('-', '{', '}'), '', $namespace);
96
-			$nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) {
97
-				$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
96
+			$nstr = '';for ($i = 0;$i < strlen($nhex);$i += 2) {
97
+				$nstr .= chr(hexdec($nhex[$i].$nhex[$i + 1]));
98 98
 			}
99 99
 
100
-			$hash = sha1($nstr . $name);
100
+			$hash = sha1($nstr.$name);
101 101
 			return sprintf('%08s-%04s-%04x-%04x-%12s',
102 102
 				substr($hash, 0, 8), substr($hash, 8, 4),
103 103
 				(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
 		}
111 111
 	}
112 112
 
113
-  public static function murmur($key, $seed = 0, $as_integer=false) {
113
+  public static function murmur($key, $seed = 0, $as_integer = false) {
114 114
 		$key = (string) $key;
115 115
 		$klen = strlen($key);
116 116
 		$h1 = $seed;
117
-		for ($i = 0, $bytes = $klen - ($remainder = $klen & 3); $i < $bytes;) {
117
+		for ($i = 0, $bytes = $klen - ($remainder = $klen & 3);$i < $bytes;) {
118 118
 			$k1 = ((ord($key[$i]) & 0xff))
119 119
 			 | ((ord($key[++$i]) & 0xff) << 8)
120 120
 			 | ((ord($key[++$i]) & 0xff) << 16)
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 			 * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;
155 155
 		$h1 ^= ($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000);
156 156
 
157
-		return $as_integer ? $h1 : base_convert($h1 ,10, 32);
157
+		return $as_integer ? $h1 : base_convert($h1, 10, 32);
158 158
 	}
159 159
 
160
-  public static function random($bytes=9){
161
-    return strtr(base64_encode(random_bytes($bytes)),'+/=','-_');
160
+  public static function random($bytes = 9) {
161
+    return strtr(base64_encode(random_bytes($bytes)), '+/=', '-_');
162 162
   }
163 163
 
164 164
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -157,7 +157,7 @@
 block discarded – undo
157 157
 		return $as_integer ? $h1 : base_convert($h1 ,10, 32);
158 158
 	}
159 159
 
160
-  public static function random($bytes=9){
160
+  public static function random($bytes=9) {
161 161
     return strtr(base64_encode(random_bytes($bytes)),'+/=','-_');
162 162
   }
163 163
 
Please login to merge, or discard this patch.