Conditions | 20 |
Paths | > 20000 |
Total Lines | 46 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | } |
||
159 | |||
165 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.