Passed
Push — master ( 74b590...6f1b8a )
by Dmitry
01:56
created
src/Provider31/Request/General.php 3 patches
Indentation   +169 added lines, -169 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,82 +205,82 @@  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
         }
210
-    }
211 211
 
212
-    public function validate_element($name)
213
-    {
212
+        public function validate_element($name)
213
+        {
214 214
         if ( ! isset($this->$name))
215 215
         {
216
-            throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57);
216
+                throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57);
217
+        }
217 218
         }
218
-    }
219
-
220
-    /**
221
-     *      Verify signature of request
222
-     *
223
-     *      @param array $options
224
-     *      @throws Exception\Runtime
225
-     *      @throws Exception\Sign
226
-     */
227
-    public function verify_sign($options)
228
-    {
219
+
220
+        /**
221
+         *      Verify signature of request
222
+         *
223
+         *      @param array $options
224
+         *      @throws Exception\Runtime
225
+         *      @throws Exception\Sign
226
+         */
227
+        public function verify_sign($options)
228
+        {
229 229
         if (!isset($options['UseSign']) || ($options['UseSign'] === false))
230 230
         {
231
-            return null;
231
+                return null;
232 232
         }
233 233
         if ( ! isset($options['EasySoftPKey']))
234 234
         {
235
-            throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94);
235
+                throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94);
236 236
         }
237 237
         $pkeyid = (new Key())->get($options['EasySoftPKey'], 'public');
238 238
 
239 239
         $pub_key = openssl_pkey_get_public($pkeyid);
240 240
         if ($pub_key === FALSE)
241 241
         {
242
-            throw new Exception\Runtime('Can not extract the public key from certificate!', -97);
242
+                throw new Exception\Runtime('Can not extract the public key from certificate!', -97);
243 243
         }
244 244
         $bin_sign = pack("H*", $this->Sign);
245 245
         $xml = str_replace($this->Sign, '', $this->raw_request);
246 246
         $check = openssl_verify($xml, $bin_sign, $pub_key);
247 247
         if ($check == -1)
248 248
         {
249
-            throw new Exception\Sign('Error verify signature of request!', -96);
249
+                throw new Exception\Sign('Error verify signature of request!', -96);
250 250
         }
251 251
         elseif ($check == 0)
252 252
         {
253
-            throw new Exception\Sign('Signature of request is incorrect!', -95);
253
+                throw new Exception\Sign('Signature of request is incorrect!', -95);
254
+        }
254 255
         }
255
-    }
256
-
257
-    /**
258
-     *      Selects nodes by name
259
-     *
260
-     *      @param \DOMDocument $dom
261
-     *      @param string $name
262
-     *      @param array $ret
263
-     *
264
-     *      @return array nodes with the name
265
-     */
266
-    protected function getNodes($dom, $name, $ret=array())
267
-    {
256
+
257
+        /**
258
+         *      Selects nodes by name
259
+         *
260
+         *      @param \DOMDocument $dom
261
+         *      @param string $name
262
+         *      @param array $ret
263
+         *
264
+         *      @return array nodes with the name
265
+         */
266
+        protected function getNodes($dom, $name, $ret=array())
267
+        {
268 268
         foreach($dom->childNodes as $child)
269 269
         {
270
-            if ($child->nodeName == $name)
271
-            {
270
+                if ($child->nodeName == $name)
271
+                {
272 272
                 array_push($ret, $child);
273
-            }
274
-            else
275
-            {
273
+                }
274
+                else
275
+                {
276 276
                 if (count($child->childNodes) > 0)
277 277
                 {
278
-                    $ret = $this->getNodes($child, $name, $ret);
278
+                        $ret = $this->getNodes($child, $name, $ret);
279
+                }
279 280
                 }
280
-            }
281 281
         }
282 282
 
283 283
         return $ret;
284
-    }
284
+        }
285 285
 
286 286
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 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);
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      */
227 227
     public function verify_sign($options)
228 228
     {
229
-        if (!isset($options['UseSign']) || ($options['UseSign'] === false))
229
+        if ( ! isset($options['UseSign']) || ($options['UseSign'] === false))
230 230
         {
231 231
             return null;
232 232
         }
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
      *
264 264
      *      @return array nodes with the name
265 265
      */
266
-    protected function getNodes($dom, $name, $ret=array())
266
+    protected function getNodes($dom, $name, $ret = array())
267 267
     {
268
-        foreach($dom->childNodes as $child)
268
+        foreach ($dom->childNodes as $child)
269 269
         {
270 270
             if ($child->nodeName == $name)
271 271
             {
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -134,18 +134,15 @@  discard block
 block discarded – undo
134 134
             if ($child->nodeName == 'DateTime')
135 135
             {
136 136
                 $this->parse_request_node($child, 'DateTime');
137
-            }
138
-            elseif ($child->nodeName == 'Sign')
137
+            } elseif ($child->nodeName == 'Sign')
139 138
             {
140 139
                 $this->parse_request_node($child, 'Sign');
141
-            }
142
-            elseif (in_array($child->nodeName, $this->operations))
140
+            } elseif (in_array($child->nodeName, $this->operations))
143 141
             {
144 142
                 if ( ! isset($this->Operation))
145 143
                 {
146 144
                     $this->Operation = $child->nodeName;
147
-                }
148
-                else
145
+                } else
149 146
                 {
150 147
                     throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53);
151 148
                 }
@@ -182,8 +179,7 @@  discard block
 block discarded – undo
182 179
         if ( ! isset($this->$name))
183 180
         {
184 181
             $this->$name = $n->nodeValue;
185
-        }
186
-        else
182
+        } else
187 183
         {
188 184
             throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56);
189 185
         }
@@ -247,8 +243,7 @@  discard block
 block discarded – undo
247 243
         if ($check == -1)
248 244
         {
249 245
             throw new Exception\Sign('Error verify signature of request!', -96);
250
-        }
251
-        elseif ($check == 0)
246
+        } elseif ($check == 0)
252 247
         {
253 248
             throw new Exception\Sign('Signature of request is incorrect!', -95);
254 249
         }
@@ -270,8 +265,7 @@  discard block
 block discarded – undo
270 265
             if ($child->nodeName == $name)
271 266
             {
272 267
                 array_push($ret, $child);
273
-            }
274
-            else
268
+            } else
275 269
             {
276 270
                 if (count($child->childNodes) > 0)
277 271
                 {
Please login to merge, or discard this patch.