GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#19)
by
unknown
02:49
created

SoapManager::extractResponseProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 1
cp 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Behat\SoapExtension\Utils;
6
7
/**
8
 * Trait SoapManager.
9
 *
10
 * @package Behat\SoapExtension\Utils
11
 */
12
trait SoapManager
13
{
14
    use ArrayManager;
15
16
    /**
17
     * URL of WSDL service to consume.
18
     *
19
     * @var string|null $wsdl
20
     */
21
    private $wsdl;
22
    /**
23
     * Set of options for SOAP request.
24
     *
25
     * @var array
26
     */
27
    private $options = [];
28
    /**
29
     * Response of SOAP method.
30
     *
31
     * @var mixed
32
     */
33
    private $response = [];
34
    /**
35
     * Last SOAP response.
36
     *
37
     * @var string
38
     */
39
    private $rawResponse = '';
40
    /**
41
     * The URIs of the namespaces.
42
     *
43
     * @var string[]
44
     */
45
    private $namespaces = [];
46
    /**
47
     * Latest exception thrown out during SOAP call.
48
     *
49
     * @var null|\SoapFault
50
     */
51
    private $exception;
52
53
    /**
54
     * Set of headers for SOAP request.
55
     *
56
     * @var array
57
     */
58
    private $headers = [];
59
60
    /**
61
     * Make SOAP call to a function with params.
62
     *
63
     * @link http://php.net/manual/en/soapclient.getlastrequest.php#example-5896
64
     *
65
     * @param string $function
66
     *   SOAP function name to execute. Use MethodNameIsIgnored if function name is in the XML body.
67
     * @param array $arguments
68
     *   Arguments array to pass to soap call function.
69
     */
70
    public function sendRequest($function, array $arguments)
71
    {
72
        // These values can be easily overridden inside of configuration file.
73
        $this->options += [
74
            // Important for raw response steps.
75
            'trace' => 1,
76
            'exceptions' => true,
77
            'cache_wsdl' => WSDL_CACHE_NONE,
78
            'uri' => 'http://www.drms.local/app_api_test.php/soap/globalws'
79
        ];
80
81
        $this->rawResponse =  $this->options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->options of type array<string,integer|boo...teger","uri":"string"}> is incompatible with the declared type string of property $rawResponse.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
82
83
        try {
84
            $client = new \SoapClient($this->wsdl, $this->options);
85
86
            var_dump($this->wsdl);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($this->wsdl); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
87
88
            $this->rawResponse = $this->options;
89
90
            echo "test headers";
91
            if ($this->headers) {
92
                echo "test headers";
93
                $client->__setSoapHeaders($this->headers);
94
            }
95
            var_dump($function);
96
            var_dump($arguments);
97
            $this->response = $client->__soapCall($function, $arguments);
98
            //$this->rawResponse = $client->__getLastResponse();
99
        } catch (\SoapFault $e) {
100
            $this->exception = $e;
101
        }
102
    }
103
104
    /**
105
     * Extracts first value matching provided XPATH expression.
106
     *
107
     * @param string $query
108
     *   XPATH expression used to extract value from $this->rawResponse
109
     *
110
     * @return \DOMNode|bool
111 4
     */
112
    protected function extractResponseValueMatchingXPATH($query)
113
    {
114 4
        // @todo: Allow users to ignore namespaces via config or steps.
115
        // @example: $this->rawResponse = str_replace('xmlns=', 'ns=', $this->rawResponse);
116 4
        $dom = new \DOMDocument();
117
        $dom->loadXML($this->rawResponse);
118
        $xpath = new \DOMXpath($dom);
119 4
120 4
        foreach ($this->namespaces as $prefix => $uri) {
121
            $xpath->registerNamespace($prefix, $uri);
122 4
        }
123
124
        $nodeList = $xpath->query($query);
125
126
        return $nodeList->length > 0 ? $nodeList->item(0)->nodeValue : false;
127
    }
128
129
    /**
130
     * Helper to extract a property value from the response.
131
     *
132
     * @param string $property
133
     *
134
     * @return mixed
135
     */
136
    protected function extractResponseProperty($property)
137
    {
138
        return static::arrayValue(static::objectToArray($this->response), explode('][', $property));
139
    }
140
141
    /**
142
     * @return null|\SoapFault
143
     */
144
    protected function getException()
145
    {
146
        // When this method was called, this means thrown exception was read and won't be available anymore.
147
        $exception = $this->exception;
148
        // Reset the exception.
149
        $this->exception = null;
150
151
        return $exception;
152
    }
153
154
    /**
155
     * @param string $wsdl
156
     */
157
    protected function setWSDL($wsdl)
158
    {
159
        // Allow "null" and valid URLs.
160
        $isWsdlValid = null === $wsdl || filter_var($wsdl, FILTER_VALIDATE_URL);
161
        // Set the URL if it is validated.
162
        $this->wsdl = $isWsdlValid ? $wsdl : null;
163
164
165
        $this->wsdl = $wsdl;
166
        // Throw deferred exception when WSDL was reset due to it invalidation.
167
        if (!$isWsdlValid) {
168
            throw new \InvalidArgumentException(sprintf('You must pass a correct WSDL or null to %s.', __METHOD__));
169
        }
170
    }
171
172
    /**
173
     * @param array $options
174
     */
175
    protected function setOptions(array $options = null)
176
    {
177
        if (null === $options) {
178
            $this->options = [];
179
        } else {
180
            foreach ($options as $option => $value) {
181
                $this->setOption($option, $value);
182
            }
183
        }
184
    }
185
    /**
186
    * @param array $headers
187
    */
188
    protected function setHeaders(array $headers = null)
189
    {
190
        if (null === $headers) {
191
            $this->headers = [];
192
        } else {
193
            $this->headers = $headers;
194
        }
195
    }
196
197
    /**
198
     * @param string $option
199
     * @param mixed $value
200
     */
201
    protected function setOption($option, $value)
202
    {
203
        $this->options[$option] = is_string($value) && defined($value) ? constant($value) : $value;
204
    }
205
206
    /**
207
     * @param array $namespaces
208
     */
209
    protected function setNamespaces(array $namespaces = null)
210
    {
211
        if (null === $namespaces) {
212
            $this->namespaces = [];
213
        } else {
214
            foreach ($namespaces as $prefix => $uri) {
215
                $this->setNamespace($prefix, $uri);
216
            }
217
        }
218
    }
219
220
    /**
221
     * @param string $prefix
222
     * @param string $uri
223
     */
224
    protected function setNamespace($prefix, $uri)
225
    {
226
        $this->namespaces[$prefix] = $uri;
227
    }
228
229
    /**
230
     * @return mixed
231
     */
232
    public function getResponse()
233
    {
234
        return $this->response;
235
    }
236
237
    /**
238
     * @return string
239
     */
240
    public function getRawResponse()
241
    {
242
        return $this->rawResponse;
243
    }
244
}
245