Passed
Push — master ( 49cefa...361424 )
by Dmitry
01:56
created
src/Provider31/Request/General.php 2 patches
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -17,108 +17,108 @@  discard block
 block discarded – undo
17 17
 
18 18
 class General
19 19
 {
20
-    /**
21
-     *      @var string raw request
22
-     */
23
-    protected $raw_request;
24
-
25
-    /**
26
-     *      @var string 'DateTime' node
27
-     */
28
-    protected $DateTime;
29
-
30
-    /**
31
-     *      @var string 'Sign' node
32
-     */
33
-    protected $Sign;
34
-
35
-    /**
36
-     *      @var string 'Operation' type
37
-     */
38
-    protected $Operation;
39
-
40
-    /**
41
-     *      @var string 'ServiceId' node
42
-     */
43
-    protected $ServiceId;
44
-
45
-    /**
46
-     *      @var array list of possible operations
47
-     */
48
-    protected $operations = array('Check','Payment','Confirm','Cancel');
49
-
50
-    /**
51
-     *      General constructor
52
-     *
53
-     *      @param string $raw Raw request data
54
-     */
55
-    public function __construct($raw)
56
-    {
20
+        /**
21
+         *      @var string raw request
22
+         */
23
+        protected $raw_request;
24
+
25
+        /**
26
+         *      @var string 'DateTime' node
27
+         */
28
+        protected $DateTime;
29
+
30
+        /**
31
+         *      @var string 'Sign' node
32
+         */
33
+        protected $Sign;
34
+
35
+        /**
36
+         *      @var string 'Operation' type
37
+         */
38
+        protected $Operation;
39
+
40
+        /**
41
+         *      @var string 'ServiceId' node
42
+         */
43
+        protected $ServiceId;
44
+
45
+        /**
46
+         *      @var array list of possible operations
47
+         */
48
+        protected $operations = array('Check','Payment','Confirm','Cancel');
49
+
50
+        /**
51
+         *      General constructor
52
+         *
53
+         *      @param string $raw Raw request data
54
+         */
55
+        public function __construct($raw)
56
+        {
57 57
         $this->raw_request = strval($raw);
58 58
 
59 59
         $this->parse_request_data();
60
-    }
61
-
62
-    /**
63
-     *      Get DateTime
64
-     *
65
-     *      @return string
66
-     */
67
-    public function DateTime()
68
-    {
60
+        }
61
+
62
+        /**
63
+         *      Get DateTime
64
+         *
65
+         *      @return string
66
+         */
67
+        public function DateTime()
68
+        {
69 69
         return $this->DateTime;
70
-    }
71
-
72
-    /**
73
-     *      Get Sign
74
-     *
75
-     *      @return string
76
-     */
77
-    public function Sign()
78
-    {
70
+        }
71
+
72
+        /**
73
+         *      Get Sign
74
+         *
75
+         *      @return string
76
+         */
77
+        public function Sign()
78
+        {
79 79
         return $this->Sign;
80
-    }
81
-
82
-    /**
83
-     *      Get Operation type
84
-     *
85
-     *      @return string
86
-     */
87
-    public function Operation()
88
-    {
80
+        }
81
+
82
+        /**
83
+         *      Get Operation type
84
+         *
85
+         *      @return string
86
+         */
87
+        public function Operation()
88
+        {
89 89
         return $this->Operation;
90
-    }
91
-
92
-    /**
93
-     *      Get ServiceId
94
-     *
95
-     *      @return string
96
-     */
97
-    public function ServiceId()
98
-    {
90
+        }
91
+
92
+        /**
93
+         *      Get ServiceId
94
+         *
95
+         *      @return string
96
+         */
97
+        public function ServiceId()
98
+        {
99 99
         return $this->ServiceId;
100
-    }
101
-
102
-    /**
103
-     *      Parse xml-request, which was previously "extracted" from the body of the http request
104
-     *
105
-     *      @throws Exception\Structure
106
-     */
107
-    protected function parse_request_data()
108
-    {
100
+        }
101
+
102
+        /**
103
+         *      Parse xml-request, which was previously "extracted" from the body of the http request
104
+         *
105
+         *      @throws Exception\Structure
106
+         */
107
+        protected function parse_request_data()
108
+        {
109 109
         if (empty($this->raw_request))
110 110
         {
111
-            throw new Exception\Structure('An empty xml request', -50);
111
+                throw new Exception\Structure('An empty xml request', -50);
112 112
         }
113 113
 
114 114
         libxml_use_internal_errors(true);
115 115
         $doc = new \DOMDocument();
116 116
         if ( ! $doc->loadXML($this->raw_request))
117 117
         {
118
-            foreach(libxml_get_errors() as $e){
118
+                foreach(libxml_get_errors() as $e){
119 119
                 Log::instance()->error($e->message);
120
-            }
121
-            throw new Exception\Structure('The wrong XML is received', -51);
120
+                }
121
+                throw new Exception\Structure('The wrong XML is received', -51);
122 122
         }
123 123
 
124 124
         // process <Request> group
@@ -126,35 +126,35 @@  discard block
 block discarded – undo
126 126
 
127 127
         if (count($r) < 1)
128 128
         {
129
-            throw new Exception\Structure('The xml-query does not contain any element Request!', -52);
129
+                throw new Exception\Structure('The xml-query does not contain any element Request!', -52);
130 130
         }
131 131
 
132 132
         foreach ($r[0]->childNodes as $child)
133 133
         {
134
-            if ($child->nodeName == 'DateTime')
135
-            {
134
+                if ($child->nodeName == 'DateTime')
135
+                {
136 136
                 $this->parse_request_node($child, 'DateTime');
137
-            }
138
-            elseif ($child->nodeName == 'Sign')
139
-            {
137
+                }
138
+                elseif ($child->nodeName == 'Sign')
139
+                {
140 140
                 $this->parse_request_node($child, 'Sign');
141
-            }
142
-            elseif (in_array($child->nodeName, $this->operations))
143
-            {
141
+                }
142
+                elseif (in_array($child->nodeName, $this->operations))
143
+                {
144 144
                 if ( ! isset($this->Operation))
145 145
                 {
146
-                    $this->Operation = $child->nodeName;
146
+                        $this->Operation = $child->nodeName;
147 147
                 }
148 148
                 else
149 149
                 {
150
-                    throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53);
150
+                        throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53);
151
+                }
151 152
                 }
152
-            }
153 153
         }
154 154
 
155 155
         if ( ! isset($this->Operation))
156 156
         {
157
-            throw new Exception\Structure('There is no Operation type element in the xml request!', -55);
157
+                throw new Exception\Structure('There is no Operation type element in the xml request!', -55);
158 158
         }
159 159
 
160 160
         // process <Operation> group
@@ -162,42 +162,42 @@  discard block
 block discarded – undo
162 162
 
163 163
         foreach ($r[0]->childNodes as $child)
164 164
         {
165
-            if ($child->nodeName == 'ServiceId')
166
-            {
165
+                if ($child->nodeName == 'ServiceId')
166
+                {
167 167
                 $this->parse_request_node($child, 'ServiceId');
168
-            }
168
+                }
169
+        }
169 170
         }
170
-    }
171
-
172
-    /**
173
-     *      Parse node of request
174
-     *
175
-     *      @param \DOMNode $n
176
-     *      @param string $name
177
-     *
178
-     *      @throws Exception\Structure
179
-     */
180
-    protected function parse_request_node($n, $name)
181
-    {
171
+
172
+        /**
173
+         *      Parse node of request
174
+         *
175
+         *      @param \DOMNode $n
176
+         *      @param string $name
177
+         *
178
+         *      @throws Exception\Structure
179
+         */
180
+        protected function parse_request_node($n, $name)
181
+        {
182 182
         if ( ! isset($this->$name))
183 183
         {
184
-            $this->$name = $n->nodeValue;
184
+                $this->$name = $n->nodeValue;
185 185
         }
186 186
         else
187 187
         {
188
-            throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56);
188
+                throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56);
189
+        }
189 190
         }
190
-    }
191
-
192
-    /**
193
-     *      "Rough" validation of the received xml request
194
-     *
195
-     *      @param array $options
196
-     *      @throws Exception\Data
197
-     *      @throws Exception\Structure
198
-     */
199
-    public function validate_request($options)
200
-    {
191
+
192
+        /**
193
+         *      "Rough" validation of the received xml request
194
+         *
195
+         *      @param array $options
196
+         *      @throws Exception\Data
197
+         *      @throws Exception\Structure
198
+         */
199
+        public function validate_request($options)
200
+        {
201 201
         $this->validate_element('DateTime');
202 202
         $this->validate_element('Sign');
203 203
         $this->validate_element('ServiceId');
@@ -205,132 +205,132 @@  discard block
 block discarded – undo
205 205
         // compare received value ServiceId with option ServiceId
206 206
         if (intval($options['ServiceId']) != intval($this->ServiceId))
207 207
         {
208
-            throw new Exception\Data('This request is not for our ServiceId!', -58);
208
+                throw new Exception\Data('This request is not for our ServiceId!', -58);
209 209
         }
210
-    }
211
-
212
-    /**
213
-     *      Validation of xml-element
214
-     *
215
-     *      @param string $name
216
-     */
217
-    public function validate_element($name)
218
-    {
210
+        }
211
+
212
+        /**
213
+         *      Validation of xml-element
214
+         *
215
+         *      @param string $name
216
+         */
217
+        public function validate_element($name)
218
+        {
219 219
         if ( ! isset($this->$name))
220 220
         {
221
-            throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57);
221
+                throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57);
222
+        }
222 223
         }
223
-    }
224
-
225
-    /**
226
-     *      Verify signature of request
227
-     *
228
-     *      @param array $options
229
-     */
230
-    public function verify_sign($options)
231
-    {
224
+
225
+        /**
226
+         *      Verify signature of request
227
+         *
228
+         *      @param array $options
229
+         */
230
+        public function verify_sign($options)
231
+        {
232 232
         if (isset($options['UseSign']) && ($options['UseSign'] === true))
233 233
         {
234
-            $this->openssl_verify_sign($options);
234
+                $this->openssl_verify_sign($options);
235 235
         }
236
-    }
237
-
238
-    /**
239
-     *      openssl get public key
240
-     *
241
-     *      @param array $options
242
-     *      @throws Exception\Runtime
243
-     *      @return resource
244
-     */
245
-    protected function openssl_get_pub_key($options)
246
-    {
236
+        }
237
+
238
+        /**
239
+         *      openssl get public key
240
+         *
241
+         *      @param array $options
242
+         *      @throws Exception\Runtime
243
+         *      @return resource
244
+         */
245
+        protected function openssl_get_pub_key($options)
246
+        {
247 247
         $pub_key = openssl_pkey_get_public($this->get_pub_key($options));
248 248
         if ($pub_key === FALSE)
249 249
         {
250
-            throw new Exception\Runtime('Can not extract the public key from certificate!', -97);
250
+                throw new Exception\Runtime('Can not extract the public key from certificate!', -97);
251 251
         }
252 252
 
253 253
         return $pub_key;
254
-    }
255
-
256
-    /**
257
-     *      load file with easysoft public key
258
-     *
259
-     *      @param array $options
260
-     *      @throws Exception\Runtime
261
-     *      @return string
262
-     */
263
-    protected function get_pub_key($options)
264
-    {
254
+        }
255
+
256
+        /**
257
+         *      load file with easysoft public key
258
+         *
259
+         *      @param array $options
260
+         *      @throws Exception\Runtime
261
+         *      @return string
262
+         */
263
+        protected function get_pub_key($options)
264
+        {
265 265
         if ( ! isset($options['EasySoftPKey']))
266 266
         {
267
-            throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94);
267
+                throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94);
268 268
         }
269 269
 
270 270
         return (new Key())->get($options['EasySoftPKey'], 'public');
271
-    }
272
-
273
-    /**
274
-     *      openssl verify signature of request
275
-     *
276
-     *      @param array $options
277
-     *      @return integer result of checking
278
-     */
279
-    protected function openssl_verify($options)
280
-    {
271
+        }
272
+
273
+        /**
274
+         *      openssl verify signature of request
275
+         *
276
+         *      @param array $options
277
+         *      @return integer result of checking
278
+         */
279
+        protected function openssl_verify($options)
280
+        {
281 281
         $bin_sign = pack("H*", $this->Sign);
282 282
         $xml = str_replace($this->Sign, '', $this->raw_request);
283 283
 
284 284
         return openssl_verify($xml, $bin_sign, $this->openssl_get_pub_key($options));
285
-    }
286
-
287
-    /**
288
-     *      check openssl verify signature of request
289
-     *
290
-     *      @param array $options
291
-     *      @throws Exception\Sign
292
-     */
293
-    protected function openssl_verify_sign($options)
294
-    {
285
+        }
286
+
287
+        /**
288
+         *      check openssl verify signature of request
289
+         *
290
+         *      @param array $options
291
+         *      @throws Exception\Sign
292
+         */
293
+        protected function openssl_verify_sign($options)
294
+        {
295 295
         $check = $this->openssl_verify($options);
296 296
 
297 297
         if ($check == -1)
298 298
         {
299
-            throw new Exception\Sign('Error verify signature of request!', -96);
299
+                throw new Exception\Sign('Error verify signature of request!', -96);
300 300
         }
301 301
         elseif ($check == 0)
302 302
         {
303
-            throw new Exception\Sign('Signature of request is incorrect!', -95);
303
+                throw new Exception\Sign('Signature of request is incorrect!', -95);
304
+        }
304 305
         }
305
-    }
306
-
307
-    /**
308
-     *      Selects nodes by name
309
-     *
310
-     *      @param \DOMDocument $dom
311
-     *      @param string $name
312
-     *      @param array $ret
313
-     *
314
-     *      @return array nodes with the name
315
-     */
316
-    protected function getNodes($dom, $name, $ret=array())
317
-    {
306
+
307
+        /**
308
+         *      Selects nodes by name
309
+         *
310
+         *      @param \DOMDocument $dom
311
+         *      @param string $name
312
+         *      @param array $ret
313
+         *
314
+         *      @return array nodes with the name
315
+         */
316
+        protected function getNodes($dom, $name, $ret=array())
317
+        {
318 318
         foreach($dom->childNodes as $child)
319 319
         {
320
-            if ($child->nodeName == $name)
321
-            {
320
+                if ($child->nodeName == $name)
321
+                {
322 322
                 array_push($ret, $child);
323
-            }
324
-            else
325
-            {
323
+                }
324
+                else
325
+                {
326 326
                 if (count($child->childNodes) > 0)
327 327
                 {
328
-                    $ret = $this->getNodes($child, $name, $ret);
328
+                        $ret = $this->getNodes($child, $name, $ret);
329
+                }
329 330
                 }
330
-            }
331 331
         }
332 332
 
333 333
         return $ret;
334
-    }
334
+        }
335 335
 
336 336
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     /**
46 46
      *      @var array list of possible operations
47 47
      */
48
-    protected $operations = array('Check','Payment','Confirm','Cancel');
48
+    protected $operations = array('Check', 'Payment', 'Confirm', 'Cancel');
49 49
 
50 50
     /**
51 51
      *      General constructor
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         $doc = new \DOMDocument();
116 116
         if ( ! $doc->loadXML($this->raw_request))
117 117
         {
118
-            foreach(libxml_get_errors() as $e){
118
+            foreach (libxml_get_errors() as $e) {
119 119
                 Log::instance()->error($e->message);
120 120
             }
121 121
             throw new Exception\Structure('The wrong XML is received', -51);
@@ -313,9 +313,9 @@  discard block
 block discarded – undo
313 313
      *
314 314
      *      @return array nodes with the name
315 315
      */
316
-    protected function getNodes($dom, $name, $ret=array())
316
+    protected function getNodes($dom, $name, $ret = array())
317 317
     {
318
-        foreach($dom->childNodes as $child)
318
+        foreach ($dom->childNodes as $child)
319 319
         {
320 320
             if ($child->nodeName == $name)
321 321
             {
Please login to merge, or discard this patch.