Completed
Pull Request — master (#3)
by thomas
17:25 queued 15:04
created
src/Request/RequestFactory.php 2 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,9 +12,8 @@  discard block
 block discarded – undo
12 12
     private $nonces = [];
13 13
 
14 14
     /**
15
-     * @param $method
15
+     * @param string $method
16 16
      * @param array $params
17
-     * @param bool $id
18 17
      * @return Request
19 18
      */
20 19
     public function create($method, $params = array())
@@ -27,7 +26,7 @@  discard block
 block discarded – undo
27 26
     }
28 27
 
29 28
     /**
30
-     * @param $string
29
+     * @param string $string
31 30
      * @return Response|Request
32 31
      * @throws \Exception
33 32
      */
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     /**
10 10
      * @var array
11 11
      */
12
-    private $nonces = [];
12
+    private $nonces = [ ];
13 13
 
14 14
     /**
15 15
      * @param $method
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
         $decoded = json_decode(trim($string), true);
37 37
 
38 38
         if (json_last_error() === JSON_ERROR_NONE) {
39
-            $id = isset($decoded['id']) ? $decoded['id'] : null;
40
-
41
-            if (isset($decoded['error'])) {
42
-                throw new ApiError($id, $decoded['error']);
43
-            } elseif (isset($decoded['method']) && isset($decoded['params'])) {
44
-                return new Request($id, $decoded['method'], $decoded['params']);
45
-            } elseif (isset($decoded['result'])) {
46
-                return new Response($id, $decoded['result']);
39
+            $id = isset($decoded[ 'id' ]) ? $decoded[ 'id' ] : null;
40
+
41
+            if (isset($decoded[ 'error' ])) {
42
+                throw new ApiError($id, $decoded[ 'error' ]);
43
+            } elseif (isset($decoded[ 'method' ]) && isset($decoded[ 'params' ])) {
44
+                return new Request($id, $decoded[ 'method' ], $decoded[ 'params' ]);
45
+            } elseif (isset($decoded[ 'result' ])) {
46
+                return new Response($id, $decoded[ 'result' ]);
47 47
             }
48 48
 
49 49
             throw new \Exception('Response missing error/params/result');
Please login to merge, or discard this patch.
src/Api/ElectrumClient.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function getServerVersion($clientVersion, $protocolVersion)
50 50
     {
51
-        return $this->conn->request(self::SERVER_VERSION, [$clientVersion, $protocolVersion]);
51
+        return $this->conn->request(self::SERVER_VERSION, [ $clientVersion, $protocolVersion ]);
52 52
     }
53 53
 
54 54
     /**
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      */
98 98
     public function subscribeAddress($address)
99 99
     {
100
-        return $this->conn->request(self::ADDRESS_SUBSCRIBE, [$address]);
100
+        return $this->conn->request(self::ADDRESS_SUBSCRIBE, [ $address ]);
101 101
     }
102 102
 
103 103
     /**
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function transactionBroadcast($hex)
108 108
     {
109
-        return $this->conn->request(self::TRANSACTION_BROADCAST, [$hex]);
109
+        return $this->conn->request(self::TRANSACTION_BROADCAST, [ $hex ]);
110 110
     }
111 111
 
112 112
     /**
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function transactionGetMerkle($txid, $height)
118 118
     {
119
-        return $this->conn->request(self::TRANSACTION_GET_MERKLE, [$txid, $height]);
119
+        return $this->conn->request(self::TRANSACTION_GET_MERKLE, [ $txid, $height ]);
120 120
     }
121 121
 
122 122
     /**
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      */
126 126
     public function transactionGet($txid)
127 127
     {
128
-        return $this->conn->request(self::TRANSACTION_GET, [$txid]);
128
+        return $this->conn->request(self::TRANSACTION_GET, [ $txid ]);
129 129
     }
130 130
 
131 131
     /**
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     public function addressGetHistory($address)
136 136
     {
137
-        return $this->conn->request(self::ADDRESS_GET_HISTORY, [$address]);
137
+        return $this->conn->request(self::ADDRESS_GET_HISTORY, [ $address ]);
138 138
     }
139 139
 
140 140
     /**
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function addressGetBalance($address)
145 145
     {
146
-        return $this->conn->request(self::ADDRESS_GET_BALANCE, [$address]);
146
+        return $this->conn->request(self::ADDRESS_GET_BALANCE, [ $address ]);
147 147
     }
148 148
 
149 149
     /**
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function addressGetProof($address)
154 154
     {
155
-        return $this->conn->request(self::ADDRESS_GET_PROOF, [$address]);
155
+        return $this->conn->request(self::ADDRESS_GET_PROOF, [ $address ]);
156 156
     }
157 157
 
158 158
     /**
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      */
162 162
     public function addressListUnspent($address)
163 163
     {
164
-        return $this->conn->request(self::ADDRESS_LIST_UNSPENT, [$address]);
164
+        return $this->conn->request(self::ADDRESS_LIST_UNSPENT, [ $address ]);
165 165
     }
166 166
 
167 167
     /**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function addressGetMempool($address)
172 172
     {
173
-        return $this->conn->request(self::ADDRESS_GET_MEMPOOL, [$address]);
173
+        return $this->conn->request(self::ADDRESS_GET_MEMPOOL, [ $address ]);
174 174
     }
175 175
 
176 176
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function utxoGetAddress($txid, $nOutput)
182 182
     {
183
-        return $this->conn->request(self::UTXO_GET_ADDRESS, [$txid, $nOutput]);
183
+        return $this->conn->request(self::UTXO_GET_ADDRESS, [ $txid, $nOutput ]);
184 184
     }
185 185
 
186 186
     /**
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
     public function blockGetHeader($blockHeight)
207 207
     {
208
-        return $this->conn->request(self::BLOCK_GET_HEADER, [$blockHeight]);
208
+        return $this->conn->request(self::BLOCK_GET_HEADER, [ $blockHeight ]);
209 209
     }
210 210
 
211 211
     /**
@@ -214,6 +214,6 @@  discard block
 block discarded – undo
214 214
      */
215 215
     public function blockGetChunk($blockHeight)
216 216
     {
217
-        return $this->conn->request(self::BLOCK_GET_CHUNK, [$blockHeight]);
217
+        return $this->conn->request(self::BLOCK_GET_CHUNK, [ $blockHeight ]);
218 218
     }
219 219
 }
Please login to merge, or discard this patch.
src/Api/MiningClient.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function authorize($user, $password)
43 43
     {
44
-        return $this->conn->request(self::AUTHORIZE, [$user, $password]);
44
+        return $this->conn->request(self::AUTHORIZE, [ $user, $password ]);
45 45
     }
46 46
 
47 47
     /**
@@ -54,6 +54,6 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function submit($worker_name, $job_id, $extranonce2, $ntime, $nonce)
56 56
     {
57
-        return $this->conn->request(self::SUBMIT, [$worker_name, $job_id, $extranonce2, $ntime, $nonce]);
57
+        return $this->conn->request(self::SUBMIT, [ $worker_name, $job_id, $extranonce2, $ntime, $nonce ]);
58 58
     }
59 59
 }
Please login to merge, or discard this patch.
src/Connection.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     /**
32 32
      * @var Deferred[]
33 33
      */
34
-    private $deferred = [];
34
+    private $deferred = [ ];
35 35
 
36 36
     /**
37 37
      * @var string
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     {
48 48
         $this->factory = $requestFactory;
49 49
         $this->stream = $stream;
50
-        $this->stream->on('data', [$this, 'onData']);
50
+        $this->stream->on('data', [ $this, 'onData' ]);
51 51
     }
52 52
 
53 53
     public function close()
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      * @param array $params
61 61
      * @return \React\Promise\Promise|\React\Promise\PromiseInterface
62 62
      */
63
-    public function request($method, array $params = [])
63
+    public function request($method, array $params = [ ])
64 64
     {
65 65
         $request = $this->factory->create($method, $params);
66 66
         return $this->send($request);
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     public function send(Request $request)
83 83
     {
84 84
         $result = new Deferred();
85
-        $this->deferred[$request->getId()] = $result;
85
+        $this->deferred[ $request->getId() ] = $result;
86 86
         $this->stream->write($request->write());
87 87
 
88 88
         return $result->promise();
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function onData($data)
95 95
     {
96
-        $buffer = $this->streamBuffer . $data;
96
+        $buffer = $this->streamBuffer.$data;
97 97
 
98 98
         while (($nextPos = strpos($buffer, "\n"))) {
99 99
             $msg = substr($buffer, 0, $nextPos);
@@ -119,54 +119,54 @@  discard block
 block discarded – undo
119 119
     public function onMessage($data)
120 120
     {
121 121
         $response = $this->factory->response($data);
122
-        if (isset($this->deferred[$response->getId()])) {
123
-            $this->deferred[$response->getId()]->resolve($response);
122
+        if (isset($this->deferred[ $response->getId() ])) {
123
+            $this->deferred[ $response->getId() ]->resolve($response);
124 124
         } else {
125
-            $this->emit('message', [$response]);
125
+            $this->emit('message', [ $response ]);
126 126
 
127 127
             if ($response instanceof Request) {
128 128
                 $params = $response->getParams();
129 129
 
130 130
                 switch ($response->getMethod()) {
131 131
                     case ElectrumClient::HEADERS_SUBSCRIBE;
132
-                        if (!isset($params[0])) {
132
+                        if (!isset($params[ 0 ])) {
133 133
                             throw new \RuntimeException('Headers notification missing body');
134 134
                         }
135 135
                         
136
-                        $header = $params[0];
136
+                        $header = $params[ 0 ];
137 137
                         if (count($header) !== 8) {
138 138
                             throw new \RuntimeException('Headers notification missing parameter');
139 139
                         }
140 140
 
141
-                        $this->emit(ElectrumClient::HEADERS_SUBSCRIBE, [new HeadersNotification($header[0], $header[1], $header[2], $header[3], $header[4], $header[5], $header[6], $header[7])]);
141
+                        $this->emit(ElectrumClient::HEADERS_SUBSCRIBE, [ new HeadersNotification($header[ 0 ], $header[ 1 ], $header[ 2 ], $header[ 3 ], $header[ 4 ], $header[ 5 ], $header[ 6 ], $header[ 7 ]) ]);
142 142
                         break;
143 143
                     case ElectrumClient::ADDRESS_SUBSCRIBE;
144
-                        if (!isset($params[0]) || !isset($params[1])) {
144
+                        if (!isset($params[ 0 ]) || !isset($params[ 1 ])) {
145 145
                             throw new \RuntimeException('Address notification missing address/txid');
146 146
                         }
147 147
 
148
-                        $this->emit(ElectrumClient::ADDRESS_SUBSCRIBE, [new AddressNotification($params[0], $params[1])]);
148
+                        $this->emit(ElectrumClient::ADDRESS_SUBSCRIBE, [ new AddressNotification($params[ 0 ], $params[ 1 ]) ]);
149 149
                         break;
150 150
                     case ElectrumClient::NUMBLOCKS_SUBSCRIBE;
151
-                        if (!isset($params[0])) {
151
+                        if (!isset($params[ 0 ])) {
152 152
                             throw new \RuntimeException('Missing notification parameter: height');
153 153
                         }
154 154
 
155
-                        $this->emit(ElectrumClient::NUMBLOCKS_SUBSCRIBE, [new NumBlocksNotification($params[0])]);
155
+                        $this->emit(ElectrumClient::NUMBLOCKS_SUBSCRIBE, [ new NumBlocksNotification($params[ 0 ]) ]);
156 156
                         break;
157 157
                     case MiningClient::SET_DIFFICULTY;
158 158
                         if (count($params) !== 1) {
159 159
                             throw new \RuntimeException('Missing mining difficulty notification parameter');
160 160
                         }
161 161
 
162
-                        $this->emit(MiningClient::SET_DIFFICULTY, [new SetDifficultyNotification($params[0])]);
162
+                        $this->emit(MiningClient::SET_DIFFICULTY, [ new SetDifficultyNotification($params[ 0 ]) ]);
163 163
                         break;
164 164
                     case MiningClient::NOTIFY;
165 165
                         if (count($params) !== 9) {
166 166
                             throw new \RuntimeException('Missing mining notification parameter');
167 167
                         }
168 168
 
169
-                        $this->emit(MiningClient::NOTIFY, [new MiningNotification($params[0], $params[1], $params[2], $params[3], $params[4], $params[5], $params[6], $params[7], $params[8])]);
169
+                        $this->emit(MiningClient::NOTIFY, [ new MiningNotification($params[ 0 ], $params[ 1 ], $params[ 2 ], $params[ 3 ], $params[ 4 ], $params[ 5 ], $params[ 6 ], $params[ 7 ], $params[ 8 ]) ]);
170 170
                         break;
171 171
                 }
172 172
             }
Please login to merge, or discard this patch.
src/Request/Response.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,6 +48,6 @@
 block discarded – undo
48 48
         return json_encode([
49 49
             'id' => $this->id,
50 50
             'result' => $this->result
51
-        ]) . "\n";
51
+        ])."\n";
52 52
     }
53 53
 }
Please login to merge, or discard this patch.
src/Client.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@
 block discarded – undo
30 30
      */
31 31
     public function connect(ConnectorInterface $connector, $host, $port)
32 32
     {
33
-        return $connector->create($host, $port)->then(function (Stream $stream) {
33
+        return $connector->create($host, $port)->then(function(Stream $stream) {
34 34
             return new Connection($stream, $this->requestFactory);
35
-        }, function (\Exception $e) {
35
+        }, function(\Exception $e) {
36 36
             throw $e;
37 37
         });
38 38
     }
Please login to merge, or discard this patch.
src/Notification/NumBlocksNotification.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,6 +34,6 @@
 block discarded – undo
34 34
      */
35 35
     public function toRequest()
36 36
     {
37
-        return new Request(null, ElectrumClient::NUMBLOCKS_SUBSCRIBE, [$this->height]);
37
+        return new Request(null, ElectrumClient::NUMBLOCKS_SUBSCRIBE, [ $this->height ]);
38 38
     }
39 39
 }
Please login to merge, or discard this patch.
src/Notification/HeadersNotification.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -139,10 +139,10 @@
 block discarded – undo
139 139
      */
140 140
     public function toRequest()
141 141
     {
142
-        return new Request(null, ElectrumClient::HEADERS_SUBSCRIBE, [[
142
+        return new Request(null, ElectrumClient::HEADERS_SUBSCRIBE, [ [
143 143
             $this->nonce, $this->prevBlock, $this->timestamp,
144 144
             $this->merkleRoot, $this->height, $this->utxoRoot,
145 145
             $this->version, $this->bits
146
-        ]]);
146
+        ] ]);
147 147
     }
148 148
 }
Please login to merge, or discard this patch.
src/Notification/AddressNotification.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,6 +49,6 @@
 block discarded – undo
49 49
      */
50 50
     public function toRequest()
51 51
     {
52
-        return new Request(null, ElectrumClient::ADDRESS_SUBSCRIBE, [$this->address, $this->txid]);
52
+        return new Request(null, ElectrumClient::ADDRESS_SUBSCRIBE, [ $this->address, $this->txid ]);
53 53
     }
54 54
 }
Please login to merge, or discard this patch.