Completed
Push — master ( 6647db...0cc2fc )
by thomas
7s
created
src/Connection.php 1 patch
Spacing   +18 added lines, -18 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()
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     public function sendRequest(Request $request)
81 81
     {
82 82
         $result = new Deferred();
83
-        $this->deferred[$request->getId()] = $result;
83
+        $this->deferred[ $request->getId() ] = $result;
84 84
         $this->sendData($request->write());
85 85
         return $result->promise();
86 86
     }
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      * @param array $params
91 91
      * @return \React\Promise\Promise|\React\Promise\PromiseInterface
92 92
      */
93
-    public function request($method, array $params = [])
93
+    public function request($method, array $params = [ ])
94 94
     {
95 95
         $request = $this->factory->create($method, $params);
96 96
         return $this->sendRequest($request);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function onData($data)
103 103
     {
104
-        $buffer = $this->streamBuffer . $data;
104
+        $buffer = $this->streamBuffer.$data;
105 105
 
106 106
         while (($nextPos = strpos($buffer, "\n"))) {
107 107
             $msg = substr($buffer, 0, $nextPos);
@@ -127,54 +127,54 @@  discard block
 block discarded – undo
127 127
     public function onMessage($data)
128 128
     {
129 129
         $response = $this->factory->response($data);
130
-        if (isset($this->deferred[$response->getId()])) {
131
-            $this->deferred[$response->getId()]->resolve($response);
130
+        if (isset($this->deferred[ $response->getId() ])) {
131
+            $this->deferred[ $response->getId() ]->resolve($response);
132 132
         } else {
133
-            $this->emit('message', [$response]);
133
+            $this->emit('message', [ $response ]);
134 134
 
135 135
             if ($response instanceof Request) {
136 136
                 $params = $response->getParams();
137 137
 
138 138
                 switch ($response->getMethod()) {
139 139
                     case ElectrumClient::HEADERS_SUBSCRIBE:
140
-                        if (!isset($params[0])) {
140
+                        if (!isset($params[ 0 ])) {
141 141
                             throw new \RuntimeException('Headers notification missing body');
142 142
                         }
143 143
                         
144
-                        $header = $params[0];
144
+                        $header = $params[ 0 ];
145 145
                         if (count($header) !== 8) {
146 146
                             throw new \RuntimeException('Headers notification missing parameter');
147 147
                         }
148 148
 
149
-                        $this->emit(ElectrumClient::HEADERS_SUBSCRIBE, [new HeadersNotification($header[0], $header[1], $header[2], $header[3], $header[4], $header[5], $header[6], $header[7])]);
149
+                        $this->emit(ElectrumClient::HEADERS_SUBSCRIBE, [ new HeadersNotification($header[ 0 ], $header[ 1 ], $header[ 2 ], $header[ 3 ], $header[ 4 ], $header[ 5 ], $header[ 6 ], $header[ 7 ]) ]);
150 150
                         break;
151 151
                     case ElectrumClient::ADDRESS_SUBSCRIBE:
152
-                        if (!isset($params[0]) || !isset($params[1])) {
152
+                        if (!isset($params[ 0 ]) || !isset($params[ 1 ])) {
153 153
                             throw new \RuntimeException('Address notification missing address/txid');
154 154
                         }
155 155
 
156
-                        $this->emit(ElectrumClient::ADDRESS_SUBSCRIBE, [new AddressNotification($params[0], $params[1])]);
156
+                        $this->emit(ElectrumClient::ADDRESS_SUBSCRIBE, [ new AddressNotification($params[ 0 ], $params[ 1 ]) ]);
157 157
                         break;
158 158
                     case ElectrumClient::NUMBLOCKS_SUBSCRIBE:
159
-                        if (!isset($params[0])) {
159
+                        if (!isset($params[ 0 ])) {
160 160
                             throw new \RuntimeException('Missing notification parameter: height');
161 161
                         }
162 162
 
163
-                        $this->emit(ElectrumClient::NUMBLOCKS_SUBSCRIBE, [new NumBlocksNotification($params[0])]);
163
+                        $this->emit(ElectrumClient::NUMBLOCKS_SUBSCRIBE, [ new NumBlocksNotification($params[ 0 ]) ]);
164 164
                         break;
165 165
                     case MiningClient::SET_DIFFICULTY:
166
-                        if (!isset($params[0])) {
166
+                        if (!isset($params[ 0 ])) {
167 167
                             throw new \RuntimeException('Missing mining difficulty notification parameter');
168 168
                         }
169 169
 
170
-                        $this->emit(MiningClient::SET_DIFFICULTY, [new SetDifficultyNotification($params[0])]);
170
+                        $this->emit(MiningClient::SET_DIFFICULTY, [ new SetDifficultyNotification($params[ 0 ]) ]);
171 171
                         break;
172 172
                     case MiningClient::NOTIFY:
173 173
                         if (count($params) !== 9) {
174 174
                             throw new \RuntimeException('Missing mining notification parameter');
175 175
                         }
176 176
 
177
-                        $this->emit(MiningClient::NOTIFY, [new MiningNotification($params[0], $params[1], $params[2], $params[3], $params[4], $params[5], $params[6], $params[7], $params[8])]);
177
+                        $this->emit(MiningClient::NOTIFY, [ new MiningNotification($params[ 0 ], $params[ 1 ], $params[ 2 ], $params[ 3 ], $params[ 4 ], $params[ 5 ], $params[ 6 ], $params[ 7 ], $params[ 8 ]) ]);
178 178
                         break;
179 179
                 }
180 180
             }
Please login to merge, or discard this patch.
src/Exception/ApiError.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/Request/RequestFactory.php 1 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 string $method
@@ -35,14 +35,14 @@  discard block
 block discarded – undo
35 35
         $decoded = json_decode(trim($string), true);
36 36
 
37 37
         if (json_last_error() === JSON_ERROR_NONE) {
38
-            $id = isset($decoded['id']) ? $decoded['id'] : null;
39
-
40
-            if (isset($decoded['error'])) {
41
-                return new ApiError($id, $decoded['error']);
42
-            } elseif (isset($decoded['method']) && isset($decoded['params'])) {
43
-                return new Request($id, $decoded['method'], $decoded['params']);
44
-            } elseif (isset($decoded['result'])) {
45
-                return new Response($id, $decoded['result']);
38
+            $id = isset($decoded[ 'id' ]) ? $decoded[ 'id' ] : null;
39
+
40
+            if (isset($decoded[ 'error' ])) {
41
+                return new ApiError($id, $decoded[ 'error' ]);
42
+            } elseif (isset($decoded[ 'method' ]) && isset($decoded[ 'params' ])) {
43
+                return new Request($id, $decoded[ 'method' ], $decoded[ 'params' ]);
44
+            } elseif (isset($decoded[ 'result' ])) {
45
+                return new Response($id, $decoded[ 'result' ]);
46 46
             }
47 47
 
48 48
             throw new \Exception('Response missing error/params/result');
Please login to merge, or discard this patch.