Completed
Branch master (f7498d)
by Tomasz
07:06
created
src/Gendoria/CruftFlake/Generator.php 2 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -159,6 +159,11 @@  discard block
 block discarded – undo
159 159
         return new GeneratorStatus($this->machine, $this->lastTime, $this->sequence, (PHP_INT_SIZE === 4));
160 160
     }
161 161
 
162
+    /**
163
+     * @param double $timestamp
164
+     * @param integer $machine
165
+     * @param integer $sequence
166
+     */
162 167
     private function mintId32($timestamp, $machine, $sequence)
163 168
     {
164 169
         $hi = (int) ($timestamp / pow(2, 10));
@@ -175,6 +180,11 @@  discard block
 block discarded – undo
175 180
         return (string) $value;
176 181
     }
177 182
 
183
+    /**
184
+     * @param double $timestamp
185
+     * @param integer $machine
186
+     * @param integer $sequence
187
+     */
178 188
     private function mintId64($timestamp, $machine, $sequence)
179 189
     {
180 190
         $timestamp = (int) $timestamp;
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Like the Twitter one.
4
- * 
5
- * 64 bits:
6
- * 
7
- * time - 41 bits (millisecond precision w/ a custom epoch gives us 69 years)
8
- * configured machine id - 10 bits - gives us up to 1024 machines
9
- * sequence number - 12 bits - rolls over every 4096 per machine (with protection to avoid rollover in the same ms)
10
- * 
11
- * 32 bits + 9 = 41 bits of time
12
- * 2199023255552 < milliseconds = 2199023255 seconds
13
- *                                2147483647 < max 31 bit int (signed)
14
- *
15
- * @author @davegardnerisme
16
- */
3
+     * Like the Twitter one.
4
+     * 
5
+     * 64 bits:
6
+     * 
7
+     * time - 41 bits (millisecond precision w/ a custom epoch gives us 69 years)
8
+     * configured machine id - 10 bits - gives us up to 1024 machines
9
+     * sequence number - 12 bits - rolls over every 4096 per machine (with protection to avoid rollover in the same ms)
10
+     * 
11
+     * 32 bits + 9 = 41 bits of time
12
+     * 2199023255552 < milliseconds = 2199023255 seconds
13
+     *                                2147483647 < max 31 bit int (signed)
14
+     *
15
+     * @author @davegardnerisme
16
+     */
17 17
 
18 18
 namespace Gendoria\CruftFlake;
19 19
 
Please login to merge, or discard this patch.
Tests/GeneratorTest.php 3 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -27,12 +27,19 @@
 block discarded – undo
27 27
         return new Generator($this->config, $this->timer);
28 28
     }
29 29
     
30
+    /**
31
+     * @param string $id
32
+     */
30 33
     private function assertId($id)
31 34
     {
32 35
         $this->assertTrue(is_string($id));
33 36
         $this->assertTrue(ctype_digit($id));
34 37
     }
35 38
     
39
+    /**
40
+     * @param string $v1
41
+     * @param string $v2
42
+     */
36 43
     private function assertReallyNotEquals($v1, $v2)
37 44
     {
38 45
         $this->assertTrue($v1 !== $v2);
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@
 block discarded – undo
22 22
     private function buildSystemUnderTest()
23 23
     {
24 24
         $this->config->expects($this->once())
25
-                     ->method('getMachine')
26
-                     ->will($this->returnValue($this->machineId));
25
+                        ->method('getMachine')
26
+                        ->will($this->returnValue($this->machineId));
27 27
         return new Generator($this->config, $this->timer);
28 28
     }
29 29
     
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         $cf = $this->buildSystemUnderTest();
179 179
         
180 180
         $ids = array();
181
-        for ($i=0; $i<4095; $i++) {
181
+        for ($i = 0; $i < 4095; $i++) {
182 182
             $id = $cf->generate();
183 183
             $ids[$id] = 1;
184 184
         }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         $cf = $this->buildSystemUnderTest();
195 195
         
196 196
         $ids = array();
197
-        for ($i=0; $i<4096; $i++) {
197
+        for ($i = 0; $i < 4096; $i++) {
198 198
             $id = $cf->generate();
199 199
             $ids[$id] = 1;
200 200
         }
Please login to merge, or discard this patch.
Tests/bootstrap.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 call_user_func(function() {
3
-    if ( ! is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
3
+    if (!is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
4 4
         throw new \LogicException('Could not find vendor/autoload.php. Did you forget to run "composer install --dev"?');
5 5
     }
6 6
     require $autoloadFile;
Please login to merge, or discard this patch.
examples/client.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 require __DIR__.'/../vendor/autoload.php';
13 13
 
14 14
 $opts = getopt('n:p:');
15
-$n    = isset($opts['n']) ? (int)$opts['n'] : 1;
15
+$n    = isset($opts['n']) ? (int) $opts['n'] : 1;
16 16
 $n    = $n < 0 ? 1 : $n;
17 17
 $port = isset($opts['p']) ? $opts['p'] : 5599;
18 18
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 $socket  = new \ZMQSocket($context, \ZMQ::SOCKET_REQ);
21 21
 $cf = new Gendoria\CruftFlake\Zmq\ZmqClient($context, $socket);
22 22
 
23
-for ($i=0; $i<$n; $i++) {
23
+for ($i = 0; $i < $n; $i++) {
24 24
     $id = $cf->generateId();
25
-    echo $id . "\n";
25
+    echo $id."\n";
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
examples/server.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1 1
 #!/usr/bin/php
2 2
 <?php
3 3
 /**
4
- * Cruft flake - simple ZMQ req/rep loop
5
- *
6
- * Usage:
7
- *
8
- *  -p      ZeroMQ port to bind to, default 5599
9
- *  -z      ZooKeeper hostname:port to connect to, eg: localhost:2181
10
- *  -m      Specify a particular machine ID
11
- */
4
+     * Cruft flake - simple ZMQ req/rep loop
5
+     *
6
+     * Usage:
7
+     *
8
+     *  -p      ZeroMQ port to bind to, default 5599
9
+     *  -z      ZooKeeper hostname:port to connect to, eg: localhost:2181
10
+     *  -m      Specify a particular machine ID
11
+     */
12 12
 
13 13
 require __DIR__.'/../vendor/autoload.php';
14 14
 
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Config/ConfigInterface.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Cruft flake config interface.
4
- * 
5
- * Implement this if you want some other way to configure machines.
6
- * 
7
- * @author @davegardnerisme
8
- */
3
+     * Cruft flake config interface.
4
+     * 
5
+     * Implement this if you want some other way to configure machines.
6
+     * 
7
+     * @author @davegardnerisme
8
+     */
9 9
 
10 10
 namespace Gendoria\CruftFlake\Config;
11 11
 
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Config/FixedConfig.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Fixed configuration.
4
- * 
5
- * This is designed to be used where each machine **knows** what its machine
6
- * ID is - eg: via some kind of automatically deployed configuration
7
- * (puppet etc.)
8
- * 
9
- * @author @davegardnerisme
10
- */
3
+     * Fixed configuration.
4
+     * 
5
+     * This is designed to be used where each machine **knows** what its machine
6
+     * ID is - eg: via some kind of automatically deployed configuration
7
+     * (puppet etc.)
8
+     * 
9
+     * @author @davegardnerisme
10
+     */
11 11
 
12 12
 namespace Gendoria\CruftFlake\Config;
13 13
 
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Config/ZooKeeperConfig.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
         for ($i = 0; $i < 1024, $machineId === null; ++$i) {
103 103
             $machineNode = $this->machineToNode($i);
104 104
             if (in_array($machineNode, $children)) {
105
-                continue;   // already used
105
+                continue; // already used
106 106
             }
107 107
 
108 108
             // attempt to claim
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Timer/Timer.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Cruft flake timer.
4
- * 
5
- * @author @davegardnerisme
6
- */
3
+     * Cruft flake timer.
4
+     * 
5
+     * @author @davegardnerisme
6
+     */
7 7
 
8 8
 namespace Gendoria\CruftFlake\Timer;
9 9
 
Please login to merge, or discard this patch.