Issues (3541)

SoapClient/SoapClient.php (4 issues)

1
<?php
2
3
namespace SoapClient;
4
5
/**
6
 * This class can be overridden at your will.
7
 * Its only purpose is to show you how you can use your own SoapClient client.
8
 */
9
class SoapClient extends \SoapClient
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $lastModifiedRequest;
15
    /**
16
     * @param string $request
17
     * @param string $location
18
     * @param string $action
19
     * @param string $version
20
     * @param number $one_way
21
     * @return mixed
22
     */
23
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
24
    {
25
        $this->removeEmptyTags($request);
26
        return parent::__doRequest($this->__getLastRequest(), $location, $action, $version, $one_way);
0 ignored issues
show
$version of type string is incompatible with the type integer expected by parameter $version of SoapClient::__doRequest(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        return parent::__doRequest($this->__getLastRequest(), $location, $action, /** @scrutinizer ignore-type */ $version, $one_way);
Loading history...
It seems like $one_way can also be of type double; however, parameter $oneWay of SoapClient::__doRequest() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        return parent::__doRequest($this->__getLastRequest(), $location, $action, $version, /** @scrutinizer ignore-type */ $one_way);
Loading history...
27
    }
28
    /**
29
     * Returns last request
30
     * @see SoapClient::__getLastRequest()
31
     * @return string
32
     */
33
    public function __getLastRequest()
34
    {
35
        return $this->lastModifiedRequest;
36
    }
37
    /**
38
     * Sets last request values
39
     * @param string $_lastRequest
40
     * @return string
41
     */
42
    public function __setLastRequest($lastRequest)
43
    {
44
        return ($this->lastModifiedRequest = $lastRequest);
45
    }
46
    /**
47
     * Removes empty tags from XML
48
     * @param string $xml
49
     * @param array $exceptTags
50
     * @return string
51
     */
52
    private function removeEmptyTags($xml, $exceptTags = array())
53
    {
54
        if (!empty($xml)) {
55
            $dom = new \DOMDocument('1.0', 'UTF-8');
56
            $dom->formatOutput = true;
57
            if ($dom->loadXML($xml) && $dom->hasChildNodes()) {
58
                $mainNode = $dom->childNodes->item(0);
59
                self::removeEmptyTagsFromDomNode($mainNode, $exceptTags);
60
                $xml = $dom->saveXML($mainNode);
61
            }
62
        }
63
        return $this->__setLastRequest($xml);
64
    }
65
    /**
66
     * Removes empty tags from \DOMNode
67
     * @uses RemoveEmptyRequestTags::removeEmptyTagsFromDomNode()
68
     * @param \DOMNode $domNode
69
     * @return void
70
     */
71
    private static function removeEmptyTagsFromDomNode(\DOMNode &$domNode, $exceptTags = array())
72
    {
73
        if ($domNode->hasChildNodes()) {
74
            foreach ($domNode->childNodes as $childNode) {
75
                self::removeEmptyTagsFromDomNode($childNode, $exceptTags);
76
            }
77
        } elseif (trim($domNode->nodeValue) === '' && !in_array($domNode->nodeName, $exceptTags) && $domNode->attributes->length === 0) {
78
            /**
79
             * As the parent might not have returned an empty value as it contained this child
80
             * we go process back the parent to be sure that he validated as not empty
81
             */
82
            $parentNode = $domNode->parentNode;
83
            $domNode->parentNode->removeChild($domNode);
0 ignored issues
show
The method removeChild() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
            $domNode->parentNode->/** @scrutinizer ignore-call */ 
84
                                  removeChild($domNode);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
            self::removeEmptyTagsFromDomNode($parentNode, $exceptTags);
0 ignored issues
show
It seems like $parentNode can also be of type null; however, parameter $domNode of SoapClient\SoapClient::r...eEmptyTagsFromDomNode() does only seem to accept DOMNode, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

84
            self::removeEmptyTagsFromDomNode(/** @scrutinizer ignore-type */ $parentNode, $exceptTags);
Loading history...
85
        }
86
    }
87
}
88