Passed
Push — master ( 419110...a41d9b )
by Dmitry
02:04
created
src/Request.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      *      @var array
18 18
      */
19
-    protected $jwt=array(
19
+    protected $jwt = array(
20 20
         'using'         => false,
21 21
         'UAPAY_pubkey'  => '',
22 22
         'our_privkey'   => '',
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     public function __construct($options)
37 37
     {
38 38
         // api_url
39
-        if ( ! isset($options['api_uri']))
39
+        if (!isset($options['api_uri']))
40 40
         {
41 41
             throw new Exception\Data('parameter api_uri is not specified');
42 42
         }
@@ -44,21 +44,21 @@  discard block
 block discarded – undo
44 44
         if (isset($options['jwt']))
45 45
         {
46 46
             // using
47
-            if ( ! isset($options['jwt']['using']))
47
+            if (!isset($options['jwt']['using']))
48 48
             {
49 49
                 throw new Exception\Data('parameter jwt/using is not specified');
50 50
             }
51
-            if ( ! is_bool($options['jwt']['using']))
51
+            if (!is_bool($options['jwt']['using']))
52 52
             {
53 53
                 throw new Exception\Data('parameter jwt/using is incorrect');
54 54
             }
55 55
             // using
56
-            if ( ! isset($options['jwt']['UAPAY_pubkey']))
56
+            if (!isset($options['jwt']['UAPAY_pubkey']))
57 57
             {
58 58
                 throw new Exception\Data('parameter jwt/UAPAY_pubkey is not specified');
59 59
             }
60 60
             // using
61
-            if ( ! isset($options['jwt']['our_privkey']))
61
+            if (!isset($options['jwt']['our_privkey']))
62 62
             {
63 63
                 throw new Exception\Data('parameter jwt/our_privkey is not specified');
64 64
             }
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      *      @param array $value
80 80
      *      @return array
81 81
      */
82
-    public function data($value=null)
82
+    public function data($value = null)
83 83
     {
84 84
         if ($value !== null)
85 85
         {
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
      *      @param mixed $value
96 96
      *      @return string
97 97
      */
98
-    protected function as_string($value=null)
98
+    protected function as_string($value = null)
99 99
     {
100
-        return (is_scalar($value))?((is_bool($value))?(($value)?'true':'false'):"$value"):null;
100
+        return (is_scalar($value)) ? ((is_bool($value)) ? (($value) ? 'true' : 'false') : "$value") : null;
101 101
     }
102 102
 
103 103
     /**
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
      *      @param mixed $value
107 107
      *      @return integer
108 108
      */
109
-    protected function as_int($value=null)
109
+    protected function as_int($value = null)
110 110
     {
111
-        return (is_int($value))?$value:null;
111
+        return (is_int($value)) ? $value : null;
112 112
     }
113 113
 
114 114
     /**
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
      *      @param mixed $value
118 118
      *      @return array
119 119
      */
120
-    protected function as_array($value=null)
120
+    protected function as_array($value = null)
121 121
     {
122
-        return (is_array($value))?$value:null;
122
+        return (is_array($value)) ? $value : null;
123 123
     }
124 124
 
125 125
     /**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     protected function own_private_key()
182 182
     {
183 183
         // check private key file
184
-        if ( ! file_exists($this->jwt['our_privkey']))
184
+        if (!file_exists($this->jwt['our_privkey']))
185 185
         {
186 186
             throw new Exception\Runtime('The file with the private key was not find!');
187 187
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -162,7 +162,9 @@  discard block
 block discarded – undo
162 162
             $payload['iat'] = $this->get_param_iat();
163 163
             $ar['token'] = $this->token_encode($payload);
164 164
 
165
-            if (isset($ar['data'])) unset($ar['data']);
165
+            if (isset($ar['data'])) {
166
+                unset($ar['data']);
167
+            }
166 168
         }
167 169
         $json = json_encode($ar, JSON_UNESCAPED_SLASHES);
168 170
 
@@ -216,8 +218,7 @@  discard block
 block discarded – undo
216 218
         try
217 219
         {
218 220
             $token = JWT::encode($payload, $this->own_private_key(), 'RS512');
219
-        }
220
-        catch (\Exception $e)
221
+        } catch (\Exception $e)
221 222
         {
222 223
             Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString());
223 224
             throw new Exception\JSON('unable to create JWT token', $e);
@@ -247,8 +248,7 @@  discard block
 block discarded – undo
247 248
             $body = $httpresponse->getBody()->getContents();
248 249
             Log::instance()->debug('got response:'.PHP_EOL.$body);
249 250
             $response = new $this->response_class($body, $this->jwt);
250
-        }
251
-        catch (\GuzzleHttp\Exception\TransferException $e)
251
+        } catch (\GuzzleHttp\Exception\TransferException $e)
252 252
         {
253 253
             Log::instance()->debug('request:'.PHP_EOL.\GuzzleHttp\Psr7\str($e->getRequest()));
254 254
             if ($e->hasResponse()) {
Please login to merge, or discard this patch.
src/Response.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      *      @var array
18 18
      */
19
-    protected $jwt=array(
19
+    protected $jwt = array(
20 20
         'using'         => false,
21 21
         'UAPAY_pubkey'  => '',
22 22
         'our_privkey'   => '',
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      *      @param array $json_string JSON string
34 34
      *      @param array $jwt_options array of options
35 35
      */
36
-    public function __construct($json_string, $jwt_options=null)
36
+    public function __construct($json_string, $jwt_options = null)
37 37
     {
38 38
         if (isset($jwt_options) && is_array($jwt_options))
39 39
         {
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         {
72 72
             throw new Exception\JSON('json response contain an error message!');
73 73
         }
74
-        if ( ! isset($this->json['status']))
74
+        if (!isset($this->json['status']))
75 75
         {
76 76
             throw new Exception\JSON('invalid json response!');
77 77
         }
@@ -81,14 +81,14 @@  discard block
 block discarded – undo
81 81
         }
82 82
         $this->status = $this->json['status'];
83 83
 
84
-        if ( ! isset($this->json['data']) || !is_array($this->json['data']))
84
+        if (!isset($this->json['data']) || !is_array($this->json['data']))
85 85
         {
86 86
             throw new Exception\JSON('json does not contain the data field!');
87 87
         }
88 88
 
89 89
         if ($this->jwt['using'] === true)
90 90
         {
91
-            if ( ! isset($this->json['data']['token']))
91
+            if (!isset($this->json['data']['token']))
92 92
             {
93 93
                 throw new Exception\JSON('data does not contain the token field!');
94 94
             }
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
     protected function uapay_public_key()
107 107
     {
108 108
         // check public key file
109
-        if ( ! file_exists($this->jwt['UAPAY_pubkey']))
109
+        if (!file_exists($this->jwt['UAPAY_pubkey']))
110 110
         {
111 111
             throw new Exception\Runtime('The file with the public key was not find!');
112 112
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -139,8 +139,7 @@
 block discarded – undo
139 139
         try
140 140
         {
141 141
             $decoded = (array) JWT::decode($token, $this->uapay_public_key(), array('RS512'));
142
-        }
143
-        catch (\Exception $e)
142
+        } catch (\Exception $e)
144 143
         {
145 144
             Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString());
146 145
             throw new Exception\JSON('unable to decode JWT token', $e);
Please login to merge, or discard this patch.