Completed
Branch master (00e474)
by Michael
05:07
created

nusoap.php ➔ iso8601_to_timestamp()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 32
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 25
nc 5
nop 1
dl 0
loc 32
rs 8.439
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 85 and the first side effect is on line 74.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
$Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
5
6
NuSOAP - Web Services Toolkit for PHP
7
8
Copyright (c) 2002 NuSphere Corporation
9
10
This library is free software; you can redistribute it and/or
11
modify it under the terms of the GNU Lesser General Public
12
License as published by the Free Software Foundation; either
13
version 2.1 of the License, or (at your option) any later version.
14
15
This library is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
Lesser General Public License for more details.
19
20
You should have received a copy of the GNU Lesser General Public
21
License along with this library; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
The NuSOAP project home is:
25
http://sourceforge.net/projects/nusoap/
26
27
The primary support for NuSOAP is the Help forum on the project home page.
28
29
If you have any questions or comments, please email:
30
31
Dietrich Ayala
32
[email protected]
33
http://dietrich.ganx4.com/nusoap
34
35
NuSphere Corporation
36
http://www.nusphere.com
37
38
*/
39
40
/*
41
 *	Some of the standards implmented in whole or part by NuSOAP:
42
 *
43
 *	SOAP 1.1 (http://www.w3.org/TR/2000/NOTE-SOAP-20000508/)
44
 *	WSDL 1.1 (http://www.w3.org/TR/2001/NOTE-wsdl-20010315)
45
 *	SOAP Messages With Attachments (http://www.w3.org/TR/SOAP-attachments)
46
 *	XML 1.0 (http://www.w3.org/TR/2006/REC-xml-20060816/)
47
 *	Namespaces in XML 1.0 (http://www.w3.org/TR/2006/REC-xml-names-20060816/)
48
 *	XML Schema 1.0 (http://www.w3.org/TR/xmlschema-0/)
49
 *	RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
50
 *	RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1
51
 *	RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
52
 */
53
54
/* load classes
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
56
// necessary classes
57
require_once('class.soapclient.php');
58
require_once('class.soap_val.php');
59
require_once('class.soap_parser.php');
60
require_once('class.soap_fault.php');
61
62
// transport classes
63
require_once('class.soap_transport_http.php');
64
65
// optional add-on classes
66
require_once('class.xmlschema.php');
67
require_once('class.wsdl.php');
68
69
// server class
70
require_once('class.soap_server.php');*/
71
72
// class variable emulation
73
// cf. http://www.webkreator.com/php/techniques/php-static-class-variables.html
74
$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = 9;
75
76
/**
77
*
78
* nusoap_base
79
*
80
* @author   Dietrich Ayala <[email protected]>
81
* @author   Scott Nichol <[email protected]>
82
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
83
* @access   public
84
*/
85
class nusoap_base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
86
    /**
87
     * Identification for HTTP headers.
88
     *
89
     * @var string
90
     * @access private
91
     */
92
    var $title = 'NuSOAP';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $title.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
93
    /**
94
     * Version for HTTP headers.
95
     *
96
     * @var string
97
     * @access private
98
     */
99
    var $version = '0.9.5';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $version.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
100
    /**
101
     * CVS revision for HTTP headers.
102
     *
103
     * @var string
104
     * @access private
105
     */
106
    var $revision = '$Revision: 1.123 $';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $revision.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
107
    /**
108
     * Current error string (manipulated by getError/setError)
109
     *
110
     * @var string
111
     * @access private
112
     */
113
    var $error_str = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $error_str.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
114
    /**
115
     * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
116
     *
117
     * @var string
118
     * @access private
119
     */
120
    var $debug_str = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $debug_str.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
121
    /**
122
     * toggles automatic encoding of special characters as entities
123
     * (should always be true, I think)
124
     *
125
     * @var boolean
126
     * @access private
127
     */
128
    var $charencoding = true;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $charencoding.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
129
    /**
130
     * the debug level for this instance
131
     *
132
     * @var integer
133
     * @access private
134
     */
135
    var $debugLevel;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $debugLevel.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
136
137
    /**
138
    * set schema version
139
    *
140
    * @var      string
141
    * @access   public
142
    */
143
    var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $XMLSchemaVersion.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
144
145
    /**
146
    * charset encoding for outgoing messages
147
    *
148
    * @var      string
149
    * @access   public
150
    */
151
    var $soap_defencoding = 'ISO-8859-1';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $soap_defencoding.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
152
    //var $soap_defencoding = 'UTF-8';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
153
154
    /**
155
    * namespaces in an array of prefix => uri
156
    *
157
    * this is "seeded" by a set of constants, but it may be altered by code
158
    *
159
    * @var      array
160
    * @access   public
161
    */
162
    var $namespaces = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $namespaces.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
163
        'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
164
        'xsd' => 'http://www.w3.org/2001/XMLSchema',
165
        'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
166
        'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
167
        );
168
169
    /**
170
    * namespaces used in the current context, e.g. during serialization
171
    *
172
    * @var      array
173
    * @access   private
174
    */
175
    var $usedNamespaces = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $usedNamespaces.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
176
177
    /**
178
    * XML Schema types in an array of uri => (array of xml type => php type)
179
    * is this legacy yet?
180
    * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
181
    * @var      array
182
    * @access   public
183
    */
184
    var $typemap = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $typemap.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
185
    'http://www.w3.org/2001/XMLSchema' => array(
186
        'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
187
        'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
188
        'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
189
        // abstract "any" types
190
        'anyType'=>'string','anySimpleType'=>'string',
191
        // derived datatypes
192
        'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
193
        'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
194
        'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
195
        'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
196
    'http://www.w3.org/2000/10/XMLSchema' => array(
197
        'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
198
        'float'=>'double','dateTime'=>'string',
199
        'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
200
    'http://www.w3.org/1999/XMLSchema' => array(
201
        'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
202
        'float'=>'double','dateTime'=>'string',
203
        'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
204
    'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
205
    'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
206
    'http://xml.apache.org/xml-soap' => array('Map')
207
    );
208
209
    /**
210
    * XML entities to convert
211
    *
212
    * @var      array
213
    * @access   public
214
    * @deprecated
215
    * @see	expandEntities
216
    */
217
    var $xmlEntities = array('quot' => '"','amp' => '&',
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $xmlEntities.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
218
        'lt' => '<','gt' => '>','apos' => "'");
219
220
    /**
221
    * constructor
222
    *
223
    * @access	public
224
    */
225
    function nusoap_base() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
nusoap_base uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
226
        $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
227
    }
228
229
    /**
230
    * gets the global debug level, which applies to future instances
231
    *
232
    * @return	integer	Debug level 0-9, where 0 turns off
233
    * @access	public
234
    */
235
    function getGlobalDebugLevel() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
getGlobalDebugLevel uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
236
        return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
237
    }
238
239
    /**
240
    * sets the global debug level, which applies to future instances
241
    *
242
    * @param	int	$level	Debug level 0-9, where 0 turns off
243
    * @access	public
244
    */
245
    function setGlobalDebugLevel($level) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
setGlobalDebugLevel uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
246
        $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
247
    }
248
249
    /**
250
    * gets the debug level for this instance
251
    *
252
    * @return	int	Debug level 0-9, where 0 turns off
253
    * @access	public
254
    */
255
    function getDebugLevel() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
256
        return $this->debugLevel;
257
    }
258
259
    /**
260
    * sets the debug level for this instance
261
    *
262
    * @param	int	$level	Debug level 0-9, where 0 turns off
263
    * @access	public
264
    */
265
    function setDebugLevel($level) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
266
        $this->debugLevel = $level;
267
    }
268
269
    /**
270
    * adds debug data to the instance debug string with formatting
271
    *
272
    * @param    string $string debug data
273
    * @access   private
274
    */
275
    function debug($string){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
276
        if ($this->debugLevel > 0) {
277
            $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
278
        }
279
    }
280
281
    /**
282
    * adds debug data to the instance debug string without formatting
283
    *
284
    * @param    string $string debug data
285
    * @access   public
286
    */
287
    function appendDebug($string){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
288
        if ($this->debugLevel > 0) {
289
            // it would be nice to use a memory stream here to use
290
            // memory more efficiently
291
            $this->debug_str .= $string;
292
        }
293
    }
294
295
    /**
296
    * clears the current debug data for this instance
297
    *
298
    * @access   public
299
    */
300
    function clearDebug() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
301
        // it would be nice to use a memory stream here to use
302
        // memory more efficiently
303
        $this->debug_str = '';
304
    }
305
306
    /**
307
    * gets the current debug data for this instance
308
    *
309
    * @return   debug data
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
310
    * @access   public
311
    */
312
    function &getDebug() {
313
        // it would be nice to use a memory stream here to use
314
        // memory more efficiently
315
        return $this->debug_str;
316
    }
317
318
    /**
319
    * gets the current debug data for this instance as an XML comment
320
    * this may change the contents of the debug data
321
    *
322
    * @return   debug data as an XML comment
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
323
    * @access   public
324
    */
325
    function &getDebugAsXMLComment() {
326
        // it would be nice to use a memory stream here to use
327
        // memory more efficiently
328
        while (strpos($this->debug_str, '--')) {
329
            $this->debug_str = str_replace('--', '- -', $this->debug_str);
330
        }
331
        $ret = "<!--\n" . $this->debug_str . "\n-->";
332
333
        return $ret;
334
    }
335
336
    /**
337
    * expands entities, e.g. changes '<' to '&lt;'.
338
    *
339
    * @param	string	$val	The string in which to expand entities.
340
    * @access	private
341
    */
342
    function expandEntities($val) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
343
        if ($this->charencoding) {
344
            $val = str_replace('&', '&amp;', $val);
345
            $val = str_replace("'", '&apos;', $val);
346
            $val = str_replace('"', '&quot;', $val);
347
            $val = str_replace('<', '&lt;', $val);
348
            $val = str_replace('>', '&gt;', $val);
349
        }
350
351
        return $val;
352
    }
353
354
    /**
355
    * returns error string if present
356
    *
357
    * @return   mixed error string or false
358
    * @access   public
359
    */
360
    function getError(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
361
        if ($this->error_str != '') {
362
            return $this->error_str;
363
        }
364
365
        return false;
366
    }
367
368
    /**
369
    * sets error string
370
    *
371
    * @return   boolean $string error string
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
372
    * @access   private
373
    */
374
    function setError($str){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
375
        $this->error_str = $str;
376
    }
377
378
    /**
379
    * detect if array is a simple array or a struct (associative array)
380
    *
381
    * @param	mixed	$val	The PHP array
382
    * @return	string	(arraySimple|arrayStruct)
383
    * @access	private
384
    */
385
    function isArraySimpleOrStruct($val) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
386
        $keyList = array_keys($val);
387
        foreach ($keyList as $keyListValue) {
388
            if (!is_int($keyListValue)) {
389
                return 'arrayStruct';
390
            }
391
        }
392
393
        return 'arraySimple';
394
    }
395
396
    /**
397
    * serializes PHP values in accordance w/ section 5. Type information is
398
    * not serialized if $use == 'literal'.
399
    *
400
    * @param	mixed	$val	The value to serialize
401
    * @param	string	$name	The name (local part) of the XML element
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
402
    * @param	string	$type	The XML schema type (local part) for the element
0 ignored issues
show
Documentation introduced by
Should the type for parameter $type not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
403
    * @param	string	$name_ns	The namespace for the name of the XML element
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name_ns not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
404
    * @param	string	$type_ns	The namespace for the type of the element
0 ignored issues
show
Documentation introduced by
Should the type for parameter $type_ns not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
405
    * @param	array	$attributes	The attributes to serialize as name=>value pairs
0 ignored issues
show
Documentation introduced by
Should the type for parameter $attributes not be false|array?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
406
    * @param	string	$use	The WSDL "use" (encoded|literal)
407
    * @param	boolean	$soapval	Whether this is called from soapval.
408
    * @return	string	The serialized element, possibly with child elements
409
    * @access	public
410
    */
411
    function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
412
        $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
413
        $this->appendDebug('value=' . $this->varDump($val));
414
        $this->appendDebug('attributes=' . $this->varDump($attributes));
415
416
        if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) {
417
            $this->debug("serialize_val: serialize soapval");
418
            $xml = $val->serialize($use);
419
            $this->appendDebug($val->getDebug());
420
            $val->clearDebug();
421
            $this->debug("serialize_val of soapval returning $xml");
422
423
            return $xml;
424
        }
425
        // force valid name if necessary
426
        if (is_numeric($name)) {
427
            $name = '__numeric_' . $name;
428
        } elseif (! $name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type false|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
429
            $name = 'noname';
430
        }
431
        // if name has ns, add ns prefix to name
432
        $xmlns = '';
433
        if ($name_ns) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name_ns of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
434
            $prefix = 'nu'.rand(1000,9999);
435
            $name = $prefix.':'.$name;
436
            $xmlns .= " xmlns:$prefix=\"$name_ns\"";
437
        }
438
        // if type is prefixed, create type prefix
439
        if ($type_ns != '' && $type_ns == $this->namespaces['xsd']) {
440
            // need to fix this. shouldn't default to xsd if no ns specified
441
            // w/o checking against typemap
442
            $type_prefix = 'xsd';
443
        } elseif ($type_ns) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $type_ns of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
444
            $type_prefix = 'ns'.rand(1000,9999);
445
            $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
446
        }
447
        // serialize attributes if present
448
        $atts = '';
449
        if ($attributes) {
450
            foreach ($attributes as $k => $v) {
451
                $atts .= " $k=\"".$this->expandEntities($v).'"';
452
            }
453
        }
454
        // serialize null value
455
        if (is_null($val)) {
456
            $this->debug("serialize_val: serialize null");
457
            if ($use == 'literal') {
458
                // TODO: depends on minOccurs
459
                $xml = "<$name$xmlns$atts/>";
460
                $this->debug("serialize_val returning $xml");
461
462
                return $xml;
463
            } else {
464
                if (isset($type) && isset($type_prefix)) {
465
                    $type_str = " xsi:type=\"$type_prefix:$type\"";
466
                } else {
467
                    $type_str = '';
468
                }
469
                $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
470
                $this->debug("serialize_val returning $xml");
471
472
                return $xml;
473
            }
474
        }
475
        // serialize if an xsd built-in primitive type
476
        if ($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])) {
477
            $this->debug("serialize_val: serialize xsd built-in primitive type");
478
            if (is_bool($val)) {
479 View Code Duplication
                if ($type == 'boolean') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
480
                    $val = $val ? 'true' : 'false';
481
                } elseif (! $val) {
482
                    $val = 0;
483
                }
484
            } else if (is_string($val)) {
485
                $val = $this->expandEntities($val);
486
            }
487
            if ($use == 'literal') {
488
                $xml = "<$name$xmlns$atts>$val</$name>";
489
                $this->debug("serialize_val returning $xml");
490
491
                return $xml;
492
            } else {
493
                $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
494
                $this->debug("serialize_val returning $xml");
495
496
                return $xml;
497
            }
498
        }
499
        // detect type and serialize
500
        $xml = '';
501
        switch (true) {
502
            case (is_bool($val) || $type == 'boolean'):
503
                $this->debug("serialize_val: serialize boolean");
504 View Code Duplication
                if ($type == 'boolean') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
505
                    $val = $val ? 'true' : 'false';
506
                } elseif (! $val) {
507
                    $val = 0;
508
                }
509
                if ($use == 'literal') {
510
                    $xml .= "<$name$xmlns$atts>$val</$name>";
511
                } else {
512
                    $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
513
                }
514
                break;
515 View Code Duplication
            case (is_int($val) || is_long($val) || $type == 'int'):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
516
                $this->debug("serialize_val: serialize int");
517
                if ($use == 'literal') {
518
                    $xml .= "<$name$xmlns$atts>$val</$name>";
519
                } else {
520
                    $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
521
                }
522
                break;
523 View Code Duplication
            case (is_float($val)|| is_double($val) || $type == 'float'):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
524
                $this->debug("serialize_val: serialize float");
525
                if ($use == 'literal') {
526
                    $xml .= "<$name$xmlns$atts>$val</$name>";
527
                } else {
528
                    $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
529
                }
530
                break;
531 View Code Duplication
            case (is_string($val) || $type == 'string'):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
532
                $this->debug("serialize_val: serialize string");
533
                $val = $this->expandEntities($val);
0 ignored issues
show
Bug introduced by
It seems like $val can also be of type array or object; however, nusoap_base::expandEntities() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
534
                if ($use == 'literal') {
535
                    $xml .= "<$name$xmlns$atts>$val</$name>";
536
                } else {
537
                    $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
538
                }
539
                break;
540
            case is_object($val):
541
                $this->debug("serialize_val: serialize object");
542
                if (get_class($val) == 'soapval') {
543
                    $this->debug("serialize_val: serialize soapval object");
544
                    $pXml = $val->serialize($use);
545
                    $this->appendDebug($val->getDebug());
546
                    $val->clearDebug();
547
                } else {
548
                    if (! $name) {
549
                        $name = get_class($val);
550
                        $this->debug("In serialize_val, used class name $name as element name");
551
                    } else {
552
                        $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
553
                    }
554
                    foreach (get_object_vars($val) as $k => $v) {
555
                        $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
556
                    }
557
                }
558
                if (isset($type) && isset($type_prefix)) {
559
                    $type_str = " xsi:type=\"$type_prefix:$type\"";
560
                } else {
561
                    $type_str = '';
562
                }
563
                if ($use == 'literal') {
564
                    $xml .= "<$name$xmlns$atts>$pXml</$name>";
0 ignored issues
show
Bug introduced by
The variable $pXml does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
565
                } else {
566
                    $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
567
                }
568
                break;
569
            break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
570
            case (is_array($val) || $type):
0 ignored issues
show
Bug Best Practice introduced by
The expression $type of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
571
                // detect if struct or array
572
                $valueType = $this->isArraySimpleOrStruct($val);
573
                if ($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)) {
574
                    $this->debug("serialize_val: serialize array");
575
                    $i = 0;
576
                    if (is_array($val) && count($val)> 0) {
577
                        foreach ($val as $v) {
578
                            if (is_object($v) && get_class($v) ==  'soapval') {
579
                                $tt_ns = $v->type_ns;
580
                                $tt = $v->type;
581
                            } elseif (is_array($v)) {
582
                                $tt = $this->isArraySimpleOrStruct($v);
583
                            } else {
584
                                $tt = gettype($v);
585
                            }
586
                            $array_types[$tt] = 1;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$array_types was never initialized. Although not strictly required by PHP, it is generally a good practice to add $array_types = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
587
                            // TODO: for literal, the name should be $name
588
                            $xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
589
                            ++$i;
590
                        }
591
                        if (count($array_types) > 1) {
0 ignored issues
show
Bug introduced by
The variable $array_types does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
592
                            $array_typename = 'xsd:anyType';
593
                        } elseif (isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
594
                            if ($tt == 'integer') {
595
                                $tt = 'int';
596
                            }
597
                            $array_typename = 'xsd:'.$tt;
598
                        } elseif (isset($tt) && $tt == 'arraySimple') {
599
                            $array_typename = 'SOAP-ENC:Array';
600
                        } elseif (isset($tt) && $tt == 'arrayStruct') {
601
                            $array_typename = 'unnamed_struct_use_soapval';
602
                        } else {
603
                            // if type is prefixed, create type prefix
604
                            if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']) {
605
                                 $array_typename = 'xsd:' . $tt;
0 ignored issues
show
Bug introduced by
The variable $tt does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
606
                            } elseif ($tt_ns) {
0 ignored issues
show
Bug introduced by
The variable $tt_ns does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
607
                                $tt_prefix = 'ns' . rand(1000, 9999);
608
                                $array_typename = "$tt_prefix:$tt";
609
                                $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
610
                            } else {
611
                                $array_typename = $tt;
612
                            }
613
                        }
614
                        $array_type = $i;
615
                        if ($use == 'literal') {
616
                            $type_str = '';
617
                        } else if (isset($type) && isset($type_prefix)) {
618
                            $type_str = " xsi:type=\"$type_prefix:$type\"";
619
                        } else {
620
                            $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
621
                        }
622
                    // empty array
623
                    } else {
624
                        if ($use == 'literal') {
625
                            $type_str = '';
626
                        } else if (isset($type) && isset($type_prefix)) {
627
                            $type_str = " xsi:type=\"$type_prefix:$type\"";
628
                        } else {
629
                            $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
630
                        }
631
                    }
632
                    // TODO: for array in literal, there is no wrapper here
633
                    $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>";
634
                } else {
635
                    // got a struct
636
                    $this->debug("serialize_val: serialize struct");
637
                    if (isset($type) && isset($type_prefix)) {
638
                        $type_str = " xsi:type=\"$type_prefix:$type\"";
639
                    } else {
640
                        $type_str = '';
641
                    }
642
                    if ($use == 'literal') {
643
                        $xml .= "<$name$xmlns$atts>";
644
                    } else {
645
                        $xml .= "<$name$xmlns$type_str$atts>";
646
                    }
647
                    foreach ($val as $k => $v) {
648
                        // Apache Map
649
                        if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
650
                            $xml .= '<item>';
651
                            $xml .= $this->serialize_val($k,'key',false,false,false,false,$use);
652
                            $xml .= $this->serialize_val($v,'value',false,false,false,false,$use);
653
                            $xml .= '</item>';
654 View Code Duplication
                        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
655
                            $xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
656
                        }
657
                    }
658
                    $xml .= "</$name>";
659
                }
660
                break;
661
            default:
662
                $this->debug("serialize_val: serialize unknown");
663
                $xml .= 'not detected, got '.gettype($val).' for '.$val;
664
                break;
665
        }
666
        $this->debug("serialize_val returning $xml");
667
668
        return $xml;
669
    }
670
671
    /**
672
    * serializes a message
673
    *
674
    * @param string $body the XML of the SOAP body
675
    * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
676
    * @param array $namespaces optional the namespaces used in generating the body and headers
677
    * @param string $style optional (rpc|document)
678
    * @param string $use optional (encoded|literal)
679
    * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
680
    * @return string the message
681
    * @access public
682
    */
683
    function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
684
    // TODO: add an option to automatically run utf8_encode on $body and $headers
685
    // if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
686
    // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
687
688
    $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
689
    $this->debug("headers:");
690
    $this->appendDebug($this->varDump($headers));
691
    $this->debug("namespaces:");
692
    $this->appendDebug($this->varDump($namespaces));
693
694
    // serialize namespaces
695
    $ns_string = '';
696
    foreach (array_merge($this->namespaces,$namespaces) as $k => $v) {
697
        $ns_string .= " xmlns:$k=\"$v\"";
698
    }
699
    if ($encodingStyle) {
700
        $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
701
    }
702
703
    // serialize headers
704
    if ($headers) {
705
        if (is_array($headers)) {
706
            $xml = '';
707
            foreach ($headers as $k => $v) {
708
                if (is_object($v) && get_class($v) == 'soapval') {
709
                    $xml .= $this->serialize_val($v, false, false, false, false, false, $use);
710 View Code Duplication
                } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
711
                    $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
712
                }
713
            }
714
            $headers = $xml;
715
            $this->debug("In serializeEnvelope, serialized array of headers to $headers");
716
        }
717
        $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
718
    }
719
    // serialize envelope
720
    return
721
    '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
722
    '<SOAP-ENV:Envelope'.$ns_string.">".
723
    $headers.
724
    "<SOAP-ENV:Body>".
725
        $body.
726
    "</SOAP-ENV:Body>".
727
    "</SOAP-ENV:Envelope>";
728
    }
729
730
    /**
731
     * formats a string to be inserted into an HTML stream
732
     *
733
     * @param  string $str The string to format
734
     * @return string The formatted string
735
     * @access public
736
     * @deprecated
737
     */
738
    function formatDump($str){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
739
        $str = htmlspecialchars($str);
740
741
        return nl2br($str);
742
    }
743
744
    /**
745
    * contracts (changes namespace to prefix) a qualified name
746
    *
747
    * @param    string $qname qname
748
    * @return	string contracted qname
749
    * @access   private
750
    */
751
    function contractQname($qname){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
752
        // get element namespace
753
        //$this->xdebug("Contract $qname");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
754
        if (strrpos($qname, ':')) {
755
            // get unqualified name
756
            $name = substr($qname, strrpos($qname, ':') + 1);
757
            // get ns
758
            $ns = substr($qname, 0, strrpos($qname, ':'));
759
            $p = $this->getPrefixFromNamespace($ns);
760
            if ($p) {
761
                return $p . ':' . $name;
762
            }
763
764
            return $qname;
765
        } else {
766
            return $qname;
767
        }
768
    }
769
770
    /**
771
    * expands (changes prefix to namespace) a qualified name
772
    *
773
    * @param    string $qname qname
774
    * @return	string expanded qname
775
    * @access   private
776
    */
777
    function expandQname($qname){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
778
        // get element prefix
779
        if (strpos($qname,':') && !preg_match('/^http:\/\//',$qname)) {
780
            // get unqualified name
781
            $name = substr(strstr($qname,':'),1);
782
            // get ns prefix
783
            $prefix = substr($qname,0,strpos($qname,':'));
784
            if (isset($this->namespaces[$prefix])) {
785
                return $this->namespaces[$prefix].':'.$name;
786
            } else {
787
                return $qname;
788
            }
789
        } else {
790
            return $qname;
791
        }
792
    }
793
794
    /**
795
    * returns the local part of a prefixed string
796
    * returns the original string, if not prefixed
797
    *
798
    * @param string $str The prefixed string
799
    * @return string The local part
800
    * @access public
801
    */
802
    function getLocalPart($str){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
803
        if ($sstr = strrchr($str,':')) {
804
            // get unqualified name
805
            return substr( $sstr, 1 );
806
        } else {
807
            return $str;
808
        }
809
    }
810
811
    /**
812
    * returns the prefix part of a prefixed string
813
    * returns false, if not prefixed
814
    *
815
    * @param string $str The prefixed string
816
    * @return mixed The prefix or false if there is no prefix
817
    * @access public
818
    */
819
    function getPrefix($str){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
820
        if ($pos = strrpos($str,':')) {
821
            // get prefix
822
            return substr($str,0,$pos);
823
        }
824
825
        return false;
826
    }
827
828
    /**
829
    * pass it a prefix, it returns a namespace
830
    *
831
    * @param string $prefix The prefix
832
    * @return mixed The namespace, false if no namespace has the specified prefix
833
    * @access public
834
    */
835
    function getNamespaceFromPrefix($prefix){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
836
        if (isset($this->namespaces[$prefix])) {
837
            return $this->namespaces[$prefix];
838
        }
839
        //$this->setError("No namespace registered for prefix '$prefix'");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
840
        return false;
841
    }
842
843
    /**
844
    * returns the prefix for a given namespace (or prefix)
845
    * or false if no prefixes registered for the given namespace
846
    *
847
    * @param string $ns The namespace
848
    * @return mixed The prefix, false if the namespace has no prefixes
849
    * @access public
850
    */
851
    function getPrefixFromNamespace($ns) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
852
        foreach ($this->namespaces as $p => $n) {
853
            if ($ns == $n || $ns == $p) {
854
                $this->usedNamespaces[$p] = $n;
855
856
                return $p;
857
            }
858
        }
859
860
        return false;
861
    }
862
863
    /**
864
    * returns the time in ODBC canonical form with microseconds
865
    *
866
    * @return string The time in ODBC canonical form with microseconds
867
    * @access public
868
    */
869
    function getmicrotime() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
870
        if (function_exists('gettimeofday')) {
871
            $tod = gettimeofday();
872
            $sec = $tod['sec'];
873
            $usec = $tod['usec'];
874
        } else {
875
            $sec = time();
876
            $usec = 0;
877
        }
878
879
        return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
880
    }
881
882
    /**
883
     * Returns a string with the output of var_dump
884
     *
885
     * @param  mixed  $data The variable to var_dump
886
     * @return string The output of var_dump
887
     * @access public
888
     */
889
    function varDump($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
890
        ob_start();
891
        var_dump($data);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($data); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
892
        $ret_val = ob_get_contents();
893
        ob_end_clean();
894
895
        return $ret_val;
896
    }
897
898
    /**
899
    * represents the object as a string
900
    *
901
    * @return	string
902
    * @access   public
903
    */
904
    function __toString() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
905
        return $this->varDump($this);
906
    }
907
}
908
909
// XML Schema Datatype Helper Functions
910
911
//xsd:dateTime helpers
912
913
/**
914
* convert unix timestamp to ISO 8601 compliant date string
915
*
916
* @param    int $timestamp Unix time stamp
917
* @param	boolean $utc Whether the time stamp is UTC or local
918
* @return	mixed ISO 8601 date string or false
919
* @access   public
920
*/
921
function timestamp_to_iso8601($timestamp,$utc=true){
922
    $datestr = date('Y-m-d\TH:i:sO',$timestamp);
923
    $pos = strrpos($datestr, "+");
924
    if ($pos === FALSE) {
925
        $pos = strrpos($datestr, "-");
926
    }
927
    if ($pos !== FALSE) {
928
        if (strlen($datestr) == $pos + 5) {
929
            $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
930
        }
931
    }
932
    if ($utc) {
933
        $pattern = '/'.
934
        '([0-9]{4})-'.    // centuries & years CCYY-
935
        '([0-9]{2})-'.    // months MM-
936
        '([0-9]{2})'.    // days DD
937
        'T'.            // separator T
938
        '([0-9]{2}):'.    // hours hh:
939
        '([0-9]{2}):'.    // minutes mm:
940
        '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
941
        '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
942
        '/';
943
944
        if (preg_match($pattern,$datestr,$regs)) {
945
            return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
946
        }
947
948
        return false;
949
    } else {
950
        return $datestr;
951
    }
952
}
953
954
/**
955
* convert ISO 8601 compliant date string to unix timestamp
956
*
957
* @param    string $datestr ISO 8601 compliant date string
958
* @return	mixed Unix timestamp (int) or false
959
* @access   public
960
*/
961
function iso8601_to_timestamp($datestr){
962
    $pattern = '/'.
963
    '([0-9]{4})-'.    // centuries & years CCYY-
964
    '([0-9]{2})-'.    // months MM-
965
    '([0-9]{2})'.    // days DD
966
    'T'.            // separator T
967
    '([0-9]{2}):'.    // hours hh:
968
    '([0-9]{2}):'.    // minutes mm:
969
    '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
970
    '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
971
    '/';
972
    if (preg_match($pattern,$datestr,$regs)) {
973
        // not utc
974
        if ($regs[8] != 'Z') {
975
            $op = substr($regs[8],0,1);
976
            $h = substr($regs[8],1,2);
977
            $m = substr($regs[8],strlen($regs[8])-2,2);
978
            if ($op == '-') {
979
                $regs[4] = $regs[4] + $h;
980
                $regs[5] = $regs[5] + $m;
981
            } elseif ($op == '+') {
982
                $regs[4] = $regs[4] - $h;
983
                $regs[5] = $regs[5] - $m;
984
            }
985
        }
986
987
        return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
988
//		return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
989
    } else {
990
        return false;
991
    }
992
}
993
994
/**
995
* sleeps some number of microseconds
996
*
997
* @param    string $usec the number of microseconds to sleep
998
* @access   public
999
* @deprecated
1000
*/
1001
function usleepWindows($usec)
1002
{
1003
    $start = gettimeofday();
1004
1005
    do
1006
    {
1007
        $stop = gettimeofday();
1008
        $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
1009
        + $stop['usec'] - $start['usec'];
1010
    }
1011
    while ($timePassed < $usec);
1012
}
1013
1014
?><?php
1015
1016
/**
1017
* Contains information for a SOAP fault.
1018
* Mainly used for returning faults from deployed functions
1019
* in a server instance.
1020
* @author   Dietrich Ayala <[email protected]>
1021
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
1022
* @access public
1023
*/
1024
class nusoap_fault extends nusoap_base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
1025
    /**
1026
     * The fault code (client|server)
1027
     * @var string
1028
     * @access private
1029
     */
1030
    var $faultcode;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $faultcode.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1031
    /**
1032
     * The fault actor
1033
     * @var string
1034
     * @access private
1035
     */
1036
    var $faultactor;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $faultactor.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1037
    /**
1038
     * The fault string, a description of the fault
1039
     * @var string
1040
     * @access private
1041
     */
1042
    var $faultstring;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $faultstring.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1043
    /**
1044
     * The fault detail, typically a string or array of string
1045
     * @var mixed
1046
     * @access private
1047
     */
1048
    var $faultdetail;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $faultdetail.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1049
1050
    /**
1051
    * constructor
1052
    *
1053
    * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
1054
    * @param string $faultactor only used when msg routed between multiple actors
1055
    * @param string $faultstring human readable error message
1056
    * @param mixed $faultdetail detail, typically a string or array of string
1057
    */
1058
    function nusoap_fault($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
1059
        parent::nusoap_base();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (nusoap_base() instead of nusoap_fault()). Are you sure this is correct? If so, you might want to change this to $this->nusoap_base().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Coding Style introduced by
PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead
Loading history...
1060
        $this->faultcode = $faultcode;
1061
        $this->faultactor = $faultactor;
1062
        $this->faultstring = $faultstring;
1063
        $this->faultdetail = $faultdetail;
1064
    }
1065
1066
    /**
1067
    * serialize a fault
1068
    *
1069
    * @return	string	The serialization of the fault instance.
1070
    * @access   public
1071
    */
1072
    function serialize(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1073
        $ns_string = '';
1074
        foreach ($this->namespaces as $k => $v) {
1075
            $ns_string .= "\n  xmlns:$k=\"$v\"";
1076
        }
1077
        $return_msg =
1078
            '<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
1079
            '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
1080
                '<SOAP-ENV:Body>'.
1081
                '<SOAP-ENV:Fault>'.
1082
                    $this->serialize_val($this->faultcode, 'faultcode').
1083
                    $this->serialize_val($this->faultactor, 'faultactor').
1084
                    $this->serialize_val($this->faultstring, 'faultstring').
1085
                    $this->serialize_val($this->faultdetail, 'detail').
1086
                '</SOAP-ENV:Fault>'.
1087
                '</SOAP-ENV:Body>'.
1088
            '</SOAP-ENV:Envelope>';
1089
1090
        return $return_msg;
1091
    }
1092
}
1093
1094
/**
1095
 * Backward compatibility
1096
 */
1097
class soap_fault extends nusoap_fault {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
1098
}
1099
1100
?><?php
1101
1102
/**
1103
* parses an XML Schema, allows access to it's data, other utility methods.
1104
* imperfect, no validation... yet, but quite functional.
1105
*
1106
* @author   Dietrich Ayala <[email protected]>
1107
* @author   Scott Nichol <[email protected]>
1108
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
1109
* @access   public
1110
*/
1111
class nusoap_xmlschema extends nusoap_base  {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
1112
1113
    // files
1114
    var $schema = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $schema.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1115
    var $xml = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $xml.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1116
    // namespaces
1117
    var $enclosingNamespaces;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $enclosingNamespaces.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1118
    // schema info
1119
    var $schemaInfo = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $schemaInfo.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1120
    var $schemaTargetNamespace = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $schemaTargetNamespace.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1121
    // types, elements, attributes defined by the schema
1122
    var $attributes = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $attributes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1123
    var $complexTypes = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $complexTypes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1124
    var $complexTypeStack = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $complexTypeStack.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1125
    var $currentComplexType = null;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentComplexType.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1126
    var $elements = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $elements.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1127
    var $elementStack = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $elementStack.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1128
    var $currentElement = null;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentElement.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1129
    var $simpleTypes = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $simpleTypes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1130
    var $simpleTypeStack = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $simpleTypeStack.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1131
    var $currentSimpleType = null;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentSimpleType.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1132
    // imports
1133
    var $imports = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $imports.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1134
    // parser vars
1135
    var $parser;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $parser.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1136
    var $position = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $position.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1137
    var $depth = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $depth.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1138
    var $depth_array = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $depth_array.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1139
    var $message = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $message.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1140
    var $defaultNamespace = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $defaultNamespace.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
1141
1142
    /**
1143
    * constructor
1144
    *
1145
    * @param    string $schema schema document URI
1146
    * @param    string $xml xml document URI
1147
    * @param	string $namespaces namespaces defined in enclosing XML
0 ignored issues
show
Documentation introduced by
Should the type for parameter $namespaces not be string|array?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1148
    * @access   public
1149
    */
1150
    function nusoap_xmlschema($schema='',$xml='',$namespaces=array()){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
1151
        parent::nusoap_base();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (nusoap_base() instead of nusoap_xmlschema()). Are you sure this is correct? If so, you might want to change this to $this->nusoap_base().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Coding Style introduced by
PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead
Loading history...
1152
        $this->debug('nusoap_xmlschema class instantiated, inside constructor');
1153
        // files
1154
        $this->schema = $schema;
1155
        $this->xml = $xml;
1156
1157
        // namespaces
1158
        $this->enclosingNamespaces = $namespaces;
1159
        $this->namespaces = array_merge($this->namespaces, $namespaces);
1160
1161
        // parse schema file
1162
        if ($schema != '') {
1163
            $this->debug('initial schema file: '.$schema);
1164
            $this->parseFile($schema, 'schema');
1165
        }
1166
1167
        // parse xml file
1168
        if ($xml != '') {
1169
            $this->debug('initial xml file: '.$xml);
1170
            $this->parseFile($xml, 'xml');
1171
        }
1172
1173
    }
1174
1175
    /**
1176
    * parse an XML file
1177
    *
1178
    * @param string $xml path/URL to XML file
1179
    * @param string $type (schema | xml)
1180
    * @return boolean
1181
    * @access public
1182
    */
1183
    function parseFile($xml,$type){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1184
        // parse xml file
1185
        if ($xml != "") {
1186
            $xmlStr = @join("",@file($xml));
1187
            if ($xmlStr == "") {
1188
                $msg = 'Error reading XML from '.$xml;
1189
                $this->setError($msg);
1190
                $this->debug($msg);
1191
1192
            return false;
1193
            } else {
1194
                $this->debug("parsing $xml");
1195
                $this->parseString($xmlStr,$type);
1196
                $this->debug("done parsing $xml");
1197
1198
            return true;
1199
            }
1200
        }
1201
1202
        return false;
1203
    }
1204
1205
    /**
1206
    * parse an XML string
1207
    *
1208
    * @param    string $xml path or URL
1209
    * @param	string $type (schema|xml)
1210
    * @access   private
1211
    */
1212
    function parseString($xml,$type){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1213
        // parse xml string
1214
        if ($xml != "") {
1215
1216
            // Create an XML parser.
1217
            $this->parser = xml_parser_create();
1218
            // Set the options for parsing the XML data.
1219
            xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
1220
1221
            // Set the object for the parser.
1222
            xml_set_object($this->parser, $this);
1223
1224
            // Set the element handlers for the parser.
1225
            if ($type == "schema") {
1226
                xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
1227
                xml_set_character_data_handler($this->parser,'schemaCharacterData');
1228
            } elseif ($type == "xml") {
1229
                xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
1230
                xml_set_character_data_handler($this->parser,'xmlCharacterData');
1231
            }
1232
1233
            // Parse the XML file.
1234 View Code Duplication
            if (!xml_parse($this->parser,$xml,true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1235
            // Display an error message.
1236
                $errstr = sprintf('XML error parsing XML schema on line %d: %s',
1237
                xml_get_current_line_number($this->parser),
1238
                xml_error_string(xml_get_error_code($this->parser))
1239
                );
1240
                $this->debug($errstr);
1241
                $this->debug("XML payload:\n" . $xml);
1242
                $this->setError($errstr);
1243
            }
1244
1245
            xml_parser_free($this->parser);
1246
        } else {
1247
            $this->debug('no xml passed to parseString()!!');
1248
            $this->setError('no xml passed to parseString()!!');
1249
        }
1250
    }
1251
1252
    /**
1253
     * gets a type name for an unnamed type
1254
     *
1255
     * @param	string	Element name
1256
     * @return string A type name for an unnamed type
1257
     * @access	private
1258
     */
1259
    function CreateTypeName($ename) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1260
        $scope = '';
1261
        for ($i = 0; $i < count($this->complexTypeStack); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
1262
            $scope .= $this->complexTypeStack[$i] . '_';
1263
        }
1264
1265
        return $scope . $ename . '_ContainedType';
1266
    }
1267
1268
    /**
1269
    * start-element handler
1270
    *
1271
    * @param    string $parser XML parser object
1272
    * @param    string $name element name
1273
    * @param    string $attrs associative array of attributes
1274
    * @access   private
1275
    */
1276
    function schemaStartElement($parser, $name, $attrs) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1277
1278
        // position in the total number of elements, starting from 0
1279
        $pos = $this->position++;
1280
        $depth = $this->depth++;
1281
        // set self as current value for this depth
1282
        $this->depth_array[$depth] = $pos;
1283
        $this->message[$pos] = array('cdata' => '');
1284
        if ($depth > 0) {
1285
            $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
1286
        } else {
1287
            $this->defaultNamespace[$pos] = false;
1288
        }
1289
1290
        // get element prefix
1291
        if ($prefix = $this->getPrefix($name)) {
1292
            // get unqualified name
1293
            $name = $this->getLocalPart($name);
1294
        } else {
1295
            $prefix = '';
1296
        }
1297
1298
        // loop thru attributes, expanding, and registering namespace declarations
1299
        if (count($attrs) > 0) {
1300
            foreach ($attrs as $k => $v) {
0 ignored issues
show
Bug introduced by
The expression $attrs of type string is not traversable.
Loading history...
1301
                // if ns declarations, add to class level array of valid namespaces
1302
                if (preg_match('/^xmlns/',$k)) {
1303
                    //$this->xdebug("$k: $v");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1304
                    //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1305
                    if ($ns_prefix = substr(strrchr($k,':'),1)) {
1306
                        //$this->xdebug("Add namespace[$ns_prefix] = $v");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1307
                        $this->namespaces[$ns_prefix] = $v;
1308
                    } else {
1309
                        $this->defaultNamespace[$pos] = $v;
1310
                        if (! $this->getPrefixFromNamespace($v)) {
1311
                            $this->namespaces['ns'.(count($this->namespaces)+1)] = $v;
1312
                        }
1313
                    }
1314 View Code Duplication
                    if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1315
                        $this->XMLSchemaVersion = $v;
1316
                        $this->namespaces['xsi'] = $v.'-instance';
1317
                    }
1318
                }
1319
            }
1320
            foreach ($attrs as $k => $v) {
0 ignored issues
show
Bug introduced by
The expression $attrs of type string is not traversable.
Loading history...
1321
                // expand each attribute
1322
                $k = strpos($k,':') ? $this->expandQname($k) : $k;
1323
                $v = strpos($v,':') ? $this->expandQname($v) : $v;
1324
                $eAttrs[$k] = $v;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$eAttrs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $eAttrs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1325
            }
1326
            $attrs = $eAttrs;
0 ignored issues
show
Bug introduced by
The variable $eAttrs does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1327
        } else {
1328
            $attrs = array();
1329
        }
1330
        // find status, register data
1331
        switch ($name) {
1332
            case 'all':            // (optional) compositor content for a complexType
1333
            case 'choice':
1334
            case 'group':
1335
            case 'sequence':
1336
                //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1337
                $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
1338
                //if ($name == 'all' || $name == 'sequence') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1339
                //	$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1340
                //}
1341
            break;
1342
            case 'attribute':    // complexType attribute
1343
                //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1344
                $this->xdebug("parsing attribute:");
1345
                $this->appendDebug($this->varDump($attrs));
1346
                if (!isset($attrs['form'])) {
1347
                    // TODO: handle globals
1348
                    $attrs['form'] = $this->schemaInfo['attributeFormDefault'];
1349
                }
1350
                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1351
                    $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1352 View Code Duplication
                    if (!strpos($v, ':')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1353
                        // no namespace in arrayType attribute value...
1354
                        if ($this->defaultNamespace[$pos]) {
1355
                            // ...so use the default
1356
                            $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1357
                        }
1358
                    }
1359
                }
1360
                if (isset($attrs['name'])) {
1361
                    $this->attributes[$attrs['name']] = $attrs;
1362
                    $aname = $attrs['name'];
1363
                } elseif (isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType') {
1364
                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1365
                        $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1366
                    } else {
1367
                        $aname = '';
1368
                    }
1369
                } elseif (isset($attrs['ref'])) {
1370
                    $aname = $attrs['ref'];
1371
                    $this->attributes[$attrs['ref']] = $attrs;
1372
                }
1373
1374
                if ($this->currentComplexType) {    // This should *always* be
1375
                    $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
0 ignored issues
show
Bug introduced by
The variable $aname does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1376
                }
1377
                // arrayType attribute
1378
                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType') {
1379
                    $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1380
                    $prefix = $this->getPrefix($aname);
0 ignored issues
show
Unused Code introduced by
$prefix is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1381
                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1382
                        $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1383
                    } else {
1384
                        $v = '';
1385
                    }
1386
                    if (strpos($v,'[,]')) {
1387
                        $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
1388
                    }
1389
                    $v = substr($v,0,strpos($v,'[')); // clip the []
1390
                    if (!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) {
1391
                        $v = $this->XMLSchemaVersion.':'.$v;
1392
                    }
1393
                    $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
1394
                }
1395
            break;
1396
            case 'complexContent':    // (optional) content for a complexType
1397
                $this->xdebug("do nothing for element $name");
1398
            break;
1399
            case 'complexType':
1400
                array_push($this->complexTypeStack, $this->currentComplexType);
1401
                if (isset($attrs['name'])) {
1402
                    // TODO: what is the scope of named complexTypes that appear
1403
                    //       nested within other c complexTypes?
1404
                    $this->xdebug('processing named complexType '.$attrs['name']);
1405
                    //$this->currentElement = false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1406
                    $this->currentComplexType = $attrs['name'];
1407
                    $this->complexTypes[$this->currentComplexType] = $attrs;
1408
                    $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
1409
                    // This is for constructs like
1410
                    //           <complexType name="ListOfString" base="soap:Array">
1411
                    //                <sequence>
1412
                    //                    <element name="string" type="xsd:string"
1413
                    //                        minOccurs="0" maxOccurs="unbounded" />
1414
                    //                </sequence>
1415
                    //            </complexType>
1416 View Code Duplication
                    if (isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1417
                        $this->xdebug('complexType is unusual array');
1418
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1419
                    } else {
1420
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1421
                    }
1422
                } else {
1423
                    $name = $this->CreateTypeName($this->currentElement);
1424
                    $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
1425
                    $this->currentComplexType = $name;
1426
                    //$this->currentElement = false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1427
                    $this->complexTypes[$this->currentComplexType] = $attrs;
1428
                    $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
1429
                    // This is for constructs like
1430
                    //           <complexType name="ListOfString" base="soap:Array">
1431
                    //                <sequence>
1432
                    //                    <element name="string" type="xsd:string"
1433
                    //                        minOccurs="0" maxOccurs="unbounded" />
1434
                    //                </sequence>
1435
                    //            </complexType>
1436 View Code Duplication
                    if (isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1437
                        $this->xdebug('complexType is unusual array');
1438
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1439
                    } else {
1440
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1441
                    }
1442
                }
1443
                $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
1444
            break;
1445
            case 'element':
1446
                array_push($this->elementStack, $this->currentElement);
1447
                if (!isset($attrs['form'])) {
1448
                    if ($this->currentComplexType) {
1449
                        $attrs['form'] = $this->schemaInfo['elementFormDefault'];
1450
                    } else {
1451
                        // global
1452
                        $attrs['form'] = 'qualified';
1453
                    }
1454
                }
1455
                if (isset($attrs['type'])) {
1456
                    $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']);
1457
                    if (! $this->getPrefix($attrs['type'])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getPrefix($attrs['type']) of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1458 View Code Duplication
                        if ($this->defaultNamespace[$pos]) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1459
                            $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
1460
                            $this->xdebug('used default namespace to make type ' . $attrs['type']);
1461
                        }
1462
                    }
1463
                    // This is for constructs like
1464
                    //           <complexType name="ListOfString" base="soap:Array">
1465
                    //                <sequence>
1466
                    //                    <element name="string" type="xsd:string"
1467
                    //                        minOccurs="0" maxOccurs="unbounded" />
1468
                    //                </sequence>
1469
                    //            </complexType>
1470 View Code Duplication
                    if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1471
                        $this->xdebug('arrayType for unusual array is ' . $attrs['type']);
1472
                        $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
1473
                    }
1474
                    $this->currentElement = $attrs['name'];
1475
                    $ename = $attrs['name'];
1476
                } elseif (isset($attrs['ref'])) {
1477
                    $this->xdebug("processing element as ref to ".$attrs['ref']);
1478
                    $this->currentElement = "ref to ".$attrs['ref'];
1479
                    $ename = $this->getLocalPart($attrs['ref']);
1480
                } else {
1481
                    $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
1482
                    $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
1483
                    $this->currentElement = $attrs['name'];
1484
                    $attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
1485
                    $ename = $attrs['name'];
1486
                }
1487
                if (isset($ename) && $this->currentComplexType) {
1488
                    $this->xdebug("add element $ename to complexType $this->currentComplexType");
1489
                    $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
1490
                } elseif (!isset($attrs['ref'])) {
1491
                    $this->xdebug("add element $ename to elements array");
1492
                    $this->elements[ $attrs['name'] ] = $attrs;
1493
                    $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
1494
                }
1495
            break;
1496
            case 'enumeration':    //	restriction value list member
1497
                $this->xdebug('enumeration ' . $attrs['value']);
1498
                if ($this->currentSimpleType) {
1499
                    $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
1500
                } elseif ($this->currentComplexType) {
1501
                    $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
1502
                }
1503
            break;
1504
            case 'extension':    // simpleContent or complexContent type extension
1505
                $this->xdebug('extension ' . $attrs['base']);
1506
                if ($this->currentComplexType) {
1507
                    $ns = $this->getPrefix($attrs['base']);
1508
                    if ($ns == '') {
1509
                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
1510
                    } else {
1511
                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
1512
                    }
1513
                } else {
1514
                    $this->xdebug('no current complexType to set extensionBase');
1515
                }
1516
            break;
1517
            case 'import':
1518
                if (isset($attrs['schemaLocation'])) {
1519
                    $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
1520
                    $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
1521
                } else {
1522
                    $this->xdebug('import namespace ' . $attrs['namespace']);
1523
                    $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
1524 View Code Duplication
                    if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1525
                        $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
1526
                    }
1527
                }
1528
            break;
1529
            case 'include':
1530
                if (isset($attrs['schemaLocation'])) {
1531
                    $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
1532
                    $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
1533
                } else {
1534
                    $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
1535
                }
1536
            break;
1537
            case 'list':    // simpleType value list
1538
                $this->xdebug("do nothing for element $name");
1539
            break;
1540
            case 'restriction':    // simpleType, simpleContent or complexContent value restriction
1541
                $this->xdebug('restriction ' . $attrs['base']);
1542
                if ($this->currentSimpleType) {
1543
                    $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
1544 View Code Duplication
                } elseif ($this->currentComplexType) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1545
                    $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
1546
                    if (strstr($attrs['base'],':') == ':Array') {
1547
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1548
                    }
1549
                }
1550
            break;
1551
            case 'schema':
1552
                $this->schemaInfo = $attrs;
1553
                $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
1554
                if (isset($attrs['targetNamespace'])) {
1555
                    $this->schemaTargetNamespace = $attrs['targetNamespace'];
1556
                }
1557
                if (!isset($attrs['elementFormDefault'])) {
1558
                    $this->schemaInfo['elementFormDefault'] = 'unqualified';
1559
                }
1560
                if (!isset($attrs['attributeFormDefault'])) {
1561
                    $this->schemaInfo['attributeFormDefault'] = 'unqualified';
1562
                }
1563
            break;
1564
            case 'simpleContent':    // (optional) content for a complexType
1565
                if ($this->currentComplexType) {    // This should *always* be
1566
                    $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
1567
                } else {
1568
                    $this->xdebug("do nothing for element $name because there is no current complexType");
1569
                }
1570
            break;
1571
            case 'simpleType':
1572
                array_push($this->simpleTypeStack, $this->currentSimpleType);
1573
                if (isset($attrs['name'])) {
1574
                    $this->xdebug("processing simpleType for name " . $attrs['name']);
1575
                    $this->currentSimpleType = $attrs['name'];
1576
                    $this->simpleTypes[ $attrs['name'] ] = $attrs;
1577
                    $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType';
1578
                    $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar';
1579
                } else {
1580
                    $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
1581
                    $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
1582
                    $this->currentSimpleType = $name;
1583
                    //$this->currentElement = false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1584
                    $this->simpleTypes[$this->currentSimpleType] = $attrs;
1585
                    $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
1586
                }
1587
            break;
1588
            case 'union':    // simpleType type list
1589
                $this->xdebug("do nothing for element $name");
1590
            break;
1591
            default:
1592
                $this->xdebug("do not have any logic to process element $name");
1593
        }
1594
    }
1595
1596
    /**
1597
    * end-element handler
1598
    *
1599
    * @param    string $parser XML parser object
1600
    * @param    string $name element name
1601
    * @access   private
1602
    */
1603
    function schemaEndElement($parser, $name) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1604
        // bring depth down a notch
1605
        $this->depth--;
1606
        // position of current element is equal to the last value left in depth_array for my depth
1607
        if (isset($this->depth_array[$this->depth])) {
1608
            $pos = $this->depth_array[$this->depth];
0 ignored issues
show
Unused Code introduced by
$pos is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1609
        }
1610
        // get element prefix
1611
        if ($prefix = $this->getPrefix($name)) {
0 ignored issues
show
Unused Code introduced by
$prefix is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1612
            // get unqualified name
1613
            $name = $this->getLocalPart($name);
1614
        } else {
1615
            $prefix = '';
0 ignored issues
show
Unused Code introduced by
$prefix is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1616
        }
1617
        // move on...
1618
        if ($name == 'complexType') {
1619
            $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)'));
1620
            $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
1621
            $this->currentComplexType = array_pop($this->complexTypeStack);
1622
            //$this->currentElement = false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1623
        }
1624
        if ($name == 'element') {
1625
            $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)'));
1626
            $this->currentElement = array_pop($this->elementStack);
1627
        }
1628
        if ($name == 'simpleType') {
1629
            $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)'));
1630
            $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
1631
            $this->currentSimpleType = array_pop($this->simpleTypeStack);
1632
        }
1633
    }
1634
1635
    /**
1636
    * element content handler
1637
    *
1638
    * @param    string $parser XML parser object
1639
    * @param    string $data element content
1640
    * @access   private
1641
    */
1642
    function schemaCharacterData($parser, $data){
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1643
        $pos = $this->depth_array[$this->depth - 1];
1644
        $this->message[$pos]['cdata'] .= $data;
1645
    }
1646
1647
    /**
1648
    * serialize the schema
1649
    *
1650
    * @access   public
1651
    */
1652
    function serializeSchema(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1653
1654
        $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
1655
        $xml = '';
1656
        // imports
1657 View Code Duplication
        if (sizeof($this->imports) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1658
            foreach ($this->imports as $ns => $list) {
1659
                foreach ($list as $ii) {
1660
                    if ($ii['location'] != '') {
1661
                        $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
1662
                    } else {
1663
                        $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
1664
                    }
1665
                }
1666
            }
1667
        }
1668
        // complex types
1669
        foreach ($this->complexTypes as $typeName => $attrs) {
1670
            $contentStr = '';
1671
            // serialize child elements
1672
            if (isset($attrs['elements']) && (count($attrs['elements']) > 0)) {
1673
                foreach ($attrs['elements'] as $element => $eParts) {
1674
                    if (isset($eParts['ref'])) {
1675
                        $contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
1676
                    } else {
1677
                        $contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
1678
                        foreach ($eParts as $aName => $aValue) {
1679
                            // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
1680
                            if ($aName != 'name' && $aName != 'type') {
1681
                                $contentStr .= " $aName=\"$aValue\"";
1682
                            }
1683
                        }
1684
                        $contentStr .= "/>\n";
1685
                    }
1686
                }
1687
                // compositor wraps elements
1688
                if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
1689
                    $contentStr = "  <$schemaPrefix:$attrs[compositor]>\n".$contentStr."  </$schemaPrefix:$attrs[compositor]>\n";
1690
                }
1691
            }
1692
            // attributes
1693
            if (isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) {
1694
                foreach ($attrs['attrs'] as $attr => $aParts) {
1695
                    $contentStr .= "    <$schemaPrefix:attribute";
1696
                    foreach ($aParts as $a => $v) {
1697
                        if ($a == 'ref' || $a == 'type') {
1698
                            $contentStr .= " $a=\"".$this->contractQName($v).'"';
1699
                        } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
1700
                            $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
1701
                            $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"';
1702
                        } else {
1703
                            $contentStr .= " $a=\"$v\"";
1704
                        }
1705
                    }
1706
                    $contentStr .= "/>\n";
1707
                }
1708
            }
1709
            // if restriction
1710
            if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') {
1711
                $contentStr = "   <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr."   </$schemaPrefix:restriction>\n";
1712
                // complex or simple content
1713
                if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) {
1714
                    $contentStr = "  <$schemaPrefix:complexContent>\n".$contentStr."  </$schemaPrefix:complexContent>\n";
1715
                }
1716
            }
1717
            // finalize complex type
1718
            if ($contentStr != '') {
1719
                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n";
1720
            } else {
1721
                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
1722
            }
1723
            $xml .= $contentStr;
1724
        }
1725
        // simple types
1726
        if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) {
1727
            foreach ($this->simpleTypes as $typeName => $eParts) {
1728
                $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n";
1729
                if (isset($eParts['enumeration'])) {
1730
                    foreach ($eParts['enumeration'] as $e) {
1731
                        $xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
1732
                    }
1733
                }
1734
                $xml .= "  </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
1735
            }
1736
        }
1737
        // elements
1738
        if (isset($this->elements) && count($this->elements) > 0) {
1739
            foreach ($this->elements as $element => $eParts) {
1740
                $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n";
1741
            }
1742
        }
1743
        // attributes
1744
        if (isset($this->attributes) && count($this->attributes) > 0) {
1745
            foreach ($this->attributes as $attr => $aParts) {
1746
                $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>";
1747
            }
1748
        }
1749
        // finish 'er up
1750
        $attr = '';
1751
        foreach ($this->schemaInfo as $k => $v) {
1752
            if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') {
1753
                $attr .= " $k=\"$v\"";
1754
            }
1755
        }
1756
        $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
1757
        foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
1758
            $el .= " xmlns:$nsp=\"$ns\"";
1759
        }
1760
        $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n";
1761
1762
        return $xml;
1763
    }
1764
1765
    /**
1766
    * adds debug data to the clas level debug string
1767
    *
1768
    * @param    string $string debug data
1769
    * @access   private
1770
    */
1771
    function xdebug($string){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1772
        $this->debug('<' . $this->schemaTargetNamespace . '> '.$string);
1773
    }
1774
1775
    /**
1776
    * get the PHP type of a user defined type in the schema
1777
    * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
1778
    * returns false if no type exists, or not w/ the given namespace
1779
    * else returns a string that is either a native php type, or 'struct'
1780
    *
1781
    * @param string $type name of defined type
1782
    * @param string $ns namespace of type
1783
    * @return mixed
1784
    * @access public
1785
    * @deprecated
1786
    */
1787
    function getPHPType($type,$ns){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1788
        if (isset($this->typemap[$ns][$type])) {
1789
            //print "found type '$type' and ns $ns in typemap<br>";
1790
            return $this->typemap[$ns][$type];
1791
        } elseif (isset($this->complexTypes[$type])) {
1792
            //print "getting type '$type' and ns $ns from complexTypes array<br>";
1793
            return $this->complexTypes[$type]['phpType'];
1794
        }
1795
1796
        return false;
1797
    }
1798
1799
    /**
1800
    * returns an associative array of information about a given type
1801
    * returns false if no type exists by the given name
1802
    *
1803
    *	For a complexType typeDef = array(
1804
    *	'restrictionBase' => '',
1805
    *	'phpType' => '',
1806
    *	'compositor' => '(sequence|all)',
1807
    *	'elements' => array(), // refs to elements array
1808
    *	'attrs' => array() // refs to attributes array
1809
    *	... and so on (see addComplexType)
1810
    *	)
1811
    *
1812
    *   For simpleType or element, the array has different keys.
1813
    *
1814
    * @param string $type
1815
    * @return mixed
1816
    * @access public
1817
    * @see addComplexType
1818
    * @see addSimpleType
1819
    * @see addElement
1820
    */
1821
    function getTypeDef($type){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1822
        //$this->debug("in getTypeDef for type $type");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1823
        if (substr($type, -1) == '^') {
1824
            $is_element = 1;
1825
            $type = substr($type, 0, -1);
1826
        } else {
1827
            $is_element = 0;
1828
        }
1829
1830
        if ((! $is_element) && isset($this->complexTypes[$type])) {
1831
            $this->xdebug("in getTypeDef, found complexType $type");
1832
1833
            return $this->complexTypes[$type];
1834
        } elseif ((! $is_element) && isset($this->simpleTypes[$type])) {
1835
            $this->xdebug("in getTypeDef, found simpleType $type");
1836
            if (!isset($this->simpleTypes[$type]['phpType'])) {
1837
                // get info for type to tack onto the simple type
1838
                // TODO: can this ever really apply (i.e. what is a simpleType really?)
1839
                $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
1840
                $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':'));
0 ignored issues
show
Unused Code introduced by
$ns is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1841
                $etype = $this->getTypeDef($uqType);
1842
                if ($etype) {
1843
                    $this->xdebug("in getTypeDef, found type for simpleType $type:");
1844
                    $this->xdebug($this->varDump($etype));
1845
                    if (isset($etype['phpType'])) {
1846
                        $this->simpleTypes[$type]['phpType'] = $etype['phpType'];
1847
                    }
1848
                    if (isset($etype['elements'])) {
1849
                        $this->simpleTypes[$type]['elements'] = $etype['elements'];
1850
                    }
1851
                }
1852
            }
1853
1854
            return $this->simpleTypes[$type];
1855
        } elseif (isset($this->elements[$type])) {
1856
            $this->xdebug("in getTypeDef, found element $type");
1857
            if (!isset($this->elements[$type]['phpType'])) {
1858
                // get info for type to tack onto the element
1859
                $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
1860
                $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
1861
                $etype = $this->getTypeDef($uqType);
1862
                if ($etype) {
1863
                    $this->xdebug("in getTypeDef, found type for element $type:");
1864
                    $this->xdebug($this->varDump($etype));
1865
                    if (isset($etype['phpType'])) {
1866
                        $this->elements[$type]['phpType'] = $etype['phpType'];
1867
                    }
1868
                    if (isset($etype['elements'])) {
1869
                        $this->elements[$type]['elements'] = $etype['elements'];
1870
                    }
1871
                    if (isset($etype['extensionBase'])) {
1872
                        $this->elements[$type]['extensionBase'] = $etype['extensionBase'];
1873
                    }
1874
                } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') {
1875
                    $this->xdebug("in getTypeDef, element $type is an XSD type");
1876
                    $this->elements[$type]['phpType'] = 'scalar';
1877
                }
1878
            }
1879
1880
            return $this->elements[$type];
1881
        } elseif (isset($this->attributes[$type])) {
1882
            $this->xdebug("in getTypeDef, found attribute $type");
1883
1884
            return $this->attributes[$type];
1885
        } elseif (preg_match('/_ContainedType$/', $type)) {
1886
            $this->xdebug("in getTypeDef, have an untyped element $type");
1887
            $typeDef['typeClass'] = 'simpleType';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$typeDef was never initialized. Although not strictly required by PHP, it is generally a good practice to add $typeDef = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1888
            $typeDef['phpType'] = 'scalar';
1889
            $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
1890
1891
            return $typeDef;
1892
        }
1893
        $this->xdebug("in getTypeDef, did not find $type");
1894
1895
        return false;
1896
    }
1897
1898
    /**
1899
    * returns a sample serialization of a given type, or false if no type by the given name
1900
    *
1901
    * @param string $type name of type
1902
    * @return mixed
1903
    * @access public
1904
    * @deprecated
1905
    */
1906
    function serializeTypeDef($type){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1907
        //print "in sTD() for type $type<br>";
1908
    if ($typeDef = $this->getTypeDef($type)) {
1909
        $str .= '<'.$type;
0 ignored issues
show
Bug introduced by
The variable $str does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1910
        if (is_array($typeDef['attrs'])) {
1911
        foreach ($typeDef['attrs'] as $attName => $data) {
1912
            $str .= " $attName=\"{type = ".$data['type']."}\"";
1913
        }
1914
        }
1915
        $str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
1916
        if (count($typeDef['elements']) > 0) {
1917
        $str .= ">";
1918
        foreach ($typeDef['elements'] as $element => $eData) {
1919
            $str .= $this->serializeTypeDef($element);
0 ignored issues
show
Deprecated Code introduced by
The method nusoap_xmlschema::serializeTypeDef() has been deprecated.

This method has been deprecated.

Loading history...
1920
        }
1921
        $str .= "</$type>";
1922
        } elseif ($typeDef['typeClass'] == 'element') {
1923
        $str .= "></$type>";
1924
        } else {
1925
        $str .= "/>";
1926
        }
1927
1928
            return $str;
1929
    }
1930
1931
        return false;
1932
    }
1933
1934
    /**
1935
    * returns HTML form elements that allow a user
1936
    * to enter values for creating an instance of the given type.
1937
    *
1938
    * @param string $name name for type instance
1939
    * @param string $type name of type
1940
    * @return string
1941
    * @access public
1942
    * @deprecated
1943
    */
1944
    function typeToForm($name,$type){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1945
        // get typedef
1946
        if ($typeDef = $this->getTypeDef($type)) {
1947
            // if struct
1948
            if ($typeDef['phpType'] == 'struct') {
1949
                $buffer .= '<table>';
0 ignored issues
show
Bug introduced by
The variable $buffer does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1950
                foreach ($typeDef['elements'] as $child => $childDef) {
1951
                    $buffer .= "
1952
                    <tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td>
1953
                    <td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>";
1954
                }
1955
                $buffer .= '</table>';
1956
            // if array
1957
            } elseif ($typeDef['phpType'] == 'array') {
1958
                $buffer .= '<table>';
1959
                for ($i=0;$i < 3; $i++) {
1960
                    $buffer .= "
1961
                    <tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
1962
                    <td><input type='text' name='parameters[".$name."][]'></td></tr>";
1963
                }
1964
                $buffer .= '</table>';
1965
            // if scalar
1966
            } else {
1967
                $buffer .= "<input type='text' name='parameters[$name]'>";
1968
            }
1969
        } else {
1970
            $buffer .= "<input type='text' name='parameters[$name]'>";
1971
        }
1972
1973
        return $buffer;
1974
    }
1975
1976
    /**
1977
    * adds a complex type to the schema
1978
    *
1979
    * example: array
1980
    *
1981
    * addType(
1982
    * 	'ArrayOfstring',
1983
    * 	'complexType',
1984
    * 	'array',
1985
    * 	'',
1986
    * 	'SOAP-ENC:Array',
1987
    * 	array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
1988
    * 	'xsd:string'
1989
    * );
1990
    *
1991
    * example: PHP associative array ( SOAP Struct )
1992
    *
1993
    * addType(
1994
    * 	'SOAPStruct',
1995
    * 	'complexType',
1996
    * 	'struct',
1997
    * 	'all',
1998
    * 	array('myVar'=> array('name'=>'myVar','type'=>'string')
1999
    * );
2000
    *
2001
    * @param name
2002
    * @param typeClass (complexType|simpleType|attribute)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $typeClass not be string|complexType|simpleType|attribute?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2003
    * @param phpType: currently supported are array and struct (php assoc array)
2004
    * @param compositor (all|sequence|choice)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $compositor not be string|all|sequence|choice?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2005
    * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2006
    * @param elements = array ( name = array(name=>'',type=>'') )
2007
    * @param attrs = array(
2008
    * 	array(
2009
    *		'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
2010
    *		"http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
2011
    * 	)
2012
    * )
2013
    * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
2014
    * @access public
2015
    * @see getTypeDef
2016
    */
2017
    function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2018
        $this->complexTypes[$name] = array(
2019
        'name'        => $name,
2020
        'typeClass'    => $typeClass,
2021
        'phpType'    => $phpType,
2022
        'compositor'=> $compositor,
2023
        'restrictionBase' => $restrictionBase,
2024
        'elements'    => $elements,
2025
        'attrs'        => $attrs,
2026
        'arrayType'    => $arrayType
2027
        );
2028
2029
        $this->xdebug("addComplexType $name:");
2030
        $this->appendDebug($this->varDump($this->complexTypes[$name]));
2031
    }
2032
2033
    /**
2034
    * adds a simple type to the schema
2035
    *
2036
    * @param string $name
2037
    * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2038
    * @param string $typeClass (should always be simpleType)
2039
    * @param string $phpType (should always be scalar)
2040
    * @param array $enumeration array of values
2041
    * @access public
2042
    * @see nusoap_xmlschema
2043
    * @see getTypeDef
2044
    */
2045
    function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2046
        $this->simpleTypes[$name] = array(
2047
        'name'            => $name,
2048
        'typeClass'        => $typeClass,
2049
        'phpType'        => $phpType,
2050
        'type'            => $restrictionBase,
2051
        'enumeration'    => $enumeration
2052
        );
2053
2054
        $this->xdebug("addSimpleType $name:");
2055
        $this->appendDebug($this->varDump($this->simpleTypes[$name]));
2056
    }
2057
2058
    /**
2059
    * adds an element to the schema
2060
    *
2061
    * @param array $attrs attributes that must include name and type
2062
    * @see nusoap_xmlschema
2063
    * @access public
2064
    */
2065
    function addElement($attrs) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2066
        if (! $this->getPrefix($attrs['type'])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getPrefix($attrs['type']) of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
2067
            $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
2068
        }
2069
        $this->elements[ $attrs['name'] ] = $attrs;
2070
        $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
2071
2072
        $this->xdebug("addElement " . $attrs['name']);
2073
        $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ]));
2074
    }
2075
}
2076
2077
/**
2078
 * Backward compatibility
2079
 */
2080
class XMLSchema extends nusoap_xmlschema {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
2081
}
2082
2083
?><?php
2084
2085
2086
/**
2087
* For creating serializable abstractions of native PHP types.  This class
2088
* allows element name/namespace, XSD type, and XML attributes to be
2089
* associated with a value.  This is extremely useful when WSDL is not
2090
* used, but is also useful when WSDL is used with polymorphic types, including
2091
* xsd:anyType and user-defined types.
2092
*
2093
* @author   Dietrich Ayala <[email protected]>
2094
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
2095
* @access   public
2096
*/
2097
class soapval extends nusoap_base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
2098
    /**
2099
     * The XML element name
2100
     *
2101
     * @var string
2102
     * @access private
2103
     */
2104
    var $name;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2105
    /**
2106
     * The XML type name (string or false)
2107
     *
2108
     * @var mixed
2109
     * @access private
2110
     */
2111
    var $type;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $type.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2112
    /**
2113
     * The PHP value
2114
     *
2115
     * @var mixed
2116
     * @access private
2117
     */
2118
    var $value;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $value.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2119
    /**
2120
     * The XML element namespace (string or false)
2121
     *
2122
     * @var mixed
2123
     * @access private
2124
     */
2125
    var $element_ns;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $element_ns.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2126
    /**
2127
     * The XML type namespace (string or false)
2128
     *
2129
     * @var mixed
2130
     * @access private
2131
     */
2132
    var $type_ns;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $type_ns.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2133
    /**
2134
     * The XML element attributes (array or false)
2135
     *
2136
     * @var mixed
2137
     * @access private
2138
     */
2139
    var $attributes;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $attributes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2140
2141
    /**
2142
    * constructor
2143
    *
2144
    * @param    string $name optional name
2145
    * @param    mixed $type optional type name
2146
    * @param	mixed $value optional value
2147
    * @param	mixed $element_ns optional namespace of value
2148
    * @param	mixed $type_ns optional namespace of type
2149
    * @param	mixed $attributes associative array of attributes to add to element serialization
2150
    * @access   public
2151
    */
2152
    function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
2153
        parent::nusoap_base();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (nusoap_base() instead of soapval()). Are you sure this is correct? If so, you might want to change this to $this->nusoap_base().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Coding Style introduced by
PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead
Loading history...
2154
        $this->name = $name;
2155
        $this->type = $type;
2156
        $this->value = $value;
2157
        $this->element_ns = $element_ns;
2158
        $this->type_ns = $type_ns;
2159
        $this->attributes = $attributes;
2160
    }
2161
2162
    /**
2163
    * return serialized value
2164
    *
2165
    * @param	string $use The WSDL use value (encoded|literal)
2166
    * @return	string XML data
2167
    * @access   public
2168
    */
2169
    function serialize($use='encoded') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2170
        return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
2171
    }
2172
2173
    /**
2174
    * decodes a soapval object into a PHP native type
2175
    *
2176
    * @return	mixed
2177
    * @access   public
2178
    */
2179
    function decode(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2180
        return $this->value;
2181
    }
2182
}
2183
2184
?><?php
2185
2186
2187
/**
2188
* transport class for sending/receiving data via HTTP and HTTPS
2189
* NOTE: PHP must be compiled with the CURL extension for HTTPS support
2190
*
2191
* @author   Dietrich Ayala <[email protected]>
2192
* @author   Scott Nichol <[email protected]>
2193
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
2194
* @access public
2195
*/
2196
class soap_transport_http extends nusoap_base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
2197
2198
    var $url = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $url.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2199
    var $uri = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $uri.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2200
    var $digest_uri = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $digest_uri.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2201
    var $scheme = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $scheme.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2202
    var $host = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $host.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2203
    var $port = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $port.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2204
    var $path = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $path.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2205
    var $request_method = 'POST';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $request_method.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2206
    var $protocol_version = '1.0';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $protocol_version.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2207
    var $encoding = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $encoding.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2208
    var $outgoing_headers = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $outgoing_headers.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2209
    var $incoming_headers = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $incoming_headers.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2210
    var $incoming_cookies = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $incoming_cookies.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2211
    var $outgoing_payload = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $outgoing_payload.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2212
    var $incoming_payload = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $incoming_payload.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2213
    var $response_status_line;    // HTTP response status line
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $response_status_line.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2214
    var $useSOAPAction = true;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $useSOAPAction.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2215
    var $persistentConnection = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $persistentConnection.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2216
    var $ch = false;    // cURL handle
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $ch.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2217
    var $ch_options = array();    // cURL custom options
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $ch_options.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2218
    var $use_curl = false;        // force cURL use
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $use_curl.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2219
    var $proxy = null;            // proxy information (associative array)
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxy.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2220
    var $username = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $username.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2221
    var $password = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $password.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2222
    var $authtype = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $authtype.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2223
    var $digestRequest = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $digestRequest.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2224
    var $certRequest = array();    // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $certRequest.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
2225
                                // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
2226
                                // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
2227
                                // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
2228
                                // passphrase: SSL key password/passphrase
2229
                                // certpassword: SSL certificate password
2230
                                // verifypeer: default is 1
2231
                                // verifyhost: default is 1
2232
2233
    /**
2234
    * constructor
2235
    *
2236
    * @param string $url The URL to which to connect
2237
    * @param array $curl_options User-specified cURL options
0 ignored issues
show
Documentation introduced by
Should the type for parameter $curl_options not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2238
    * @param boolean $use_curl Whether to try to force cURL use
2239
    * @access public
2240
    */
2241
    function soap_transport_http($url, $curl_options = NULL, $use_curl = false){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
2242
        parent::nusoap_base();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (nusoap_base() instead of soap_transport_http()). Are you sure this is correct? If so, you might want to change this to $this->nusoap_base().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Coding Style introduced by
PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead
Loading history...
2243
        $this->debug("ctor url=$url use_curl=$use_curl curl_options:");
2244
        $this->appendDebug($this->varDump($curl_options));
2245
        $this->setURL($url);
2246
        if (is_array($curl_options)) {
2247
            $this->ch_options = $curl_options;
2248
        }
2249
        $this->use_curl = $use_curl;
2250
        preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
2251
        $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')');
2252
    }
2253
2254
    /**
2255
    * sets a cURL option
2256
    *
2257
    * @param	mixed $option The cURL option (always integer?)
2258
    * @param	mixed $value The cURL option value
2259
    * @access   private
2260
    */
2261
    function setCurlOption($option, $value) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2262
        $this->debug("setCurlOption option=$option, value=");
2263
        $this->appendDebug($this->varDump($value));
2264
        curl_setopt($this->ch, $option, $value);
2265
    }
2266
2267
    /**
2268
    * sets an HTTP header
2269
    *
2270
    * @param string $name The name of the header
2271
    * @param string $value The value of the header
2272
    * @access private
2273
    */
2274
    function setHeader($name, $value) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2275
        $this->outgoing_headers[$name] = $value;
2276
        $this->debug("set header $name: $value");
2277
    }
2278
2279
    /**
2280
    * unsets an HTTP header
2281
    *
2282
    * @param string $name The name of the header
2283
    * @access private
2284
    */
2285
    function unsetHeader($name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2286
        if (isset($this->outgoing_headers[$name])) {
2287
            $this->debug("unset header $name");
2288
            unset($this->outgoing_headers[$name]);
2289
        }
2290
    }
2291
2292
    /**
2293
    * sets the URL to which to connect
2294
    *
2295
    * @param string $url The URL to which to connect
2296
    * @access private
2297
    */
2298
    function setURL($url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2299
        $this->url = $url;
2300
2301
        $u = parse_url($url);
2302
        foreach ($u as $k => $v) {
0 ignored issues
show
Bug introduced by
The expression $u of type array<string,string>|false is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
2303
            $this->debug("parsed URL $k = $v");
2304
            $this->$k = $v;
2305
        }
2306
2307
        // add any GET params to path
2308
        if (isset($u['query']) && $u['query'] != '') {
2309
            $this->path .= '?' . $u['query'];
2310
        }
2311
2312
        // set default port
2313
        if (!isset($u['port'])) {
2314
            if ($u['scheme'] == 'https') {
2315
                $this->port = 443;
0 ignored issues
show
Documentation Bug introduced by
The property $port was declared of type string, but 443 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
2316
            } else {
2317
                $this->port = 80;
0 ignored issues
show
Documentation Bug introduced by
The property $port was declared of type string, but 80 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
2318
            }
2319
        }
2320
2321
        $this->uri = $this->path;
2322
        $this->digest_uri = $this->uri;
2323
2324
        // build headers
2325
        if (!isset($u['port'])) {
2326
            $this->setHeader('Host', $this->host);
2327
        } else {
2328
            $this->setHeader('Host', $this->host.':'.$this->port);
2329
        }
2330
2331
        if (isset($u['user']) && $u['user'] != '') {
2332
            $this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
2333
        }
2334
    }
2335
2336
    /**
2337
    * gets the I/O method to use
2338
    *
2339
    * @return	string	I/O method to use (socket|curl|unknown)
2340
    * @access	private
2341
    */
2342
    function io_method() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2343
        if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm'))
2344
            return 'curl';
2345
        if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm'))
2346
            return 'socket';
2347
2348
        return 'unknown';
2349
    }
2350
2351
    /**
2352
    * establish an HTTP connection
2353
    *
2354
    * @param    integer $timeout set connection timeout in seconds
0 ignored issues
show
Documentation introduced by
There is no parameter named $timeout. Did you maybe mean $connection_timeout?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
2355
    * @param	integer $response_timeout set response timeout in seconds
2356
    * @return	boolean true if connected, false if not
2357
    * @access   private
2358
    */
2359
    function connect($connection_timeout=0,$response_timeout=30){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2360
        // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
2361
        // "regular" socket.
2362
        // TODO: disabled for now because OpenSSL must be *compiled* in (not just
2363
        //       loaded), and until PHP5 stream_get_wrappers is not available.
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2364
//	  	if ($this->scheme == 'https') {
2365
//		  	if (version_compare(phpversion(), '4.3.0') >= 0) {
2366
//		  		if (extension_loaded('openssl')) {
2367
//		  			$this->scheme = 'ssl';
2368
//		  			$this->debug('Using SSL over OpenSSL');
2369
//		  		}
2370
//		  	}
2371
//		}
2372
        $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
2373
      if ($this->io_method() == 'socket') {
2374
        if (!is_array($this->proxy)) {
2375
            $host = $this->host;
2376
            $port = $this->port;
0 ignored issues
show
Unused Code introduced by
$port is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2377
        } else {
2378
            $host = $this->proxy['host'];
2379
            $port = $this->proxy['port'];
0 ignored issues
show
Unused Code introduced by
$port is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2380
        }
2381
2382
        // use persistent connection
2383
        if ($this->persistentConnection && isset($this->fp) && is_resource($this->fp)) {
2384
            if (!feof($this->fp)) {
0 ignored issues
show
Bug introduced by
The property fp does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
2385
                $this->debug('Re-use persistent connection');
2386
2387
                return true;
2388
            }
2389
            fclose($this->fp);
2390
            $this->debug('Closed persistent connection at EOF');
2391
        }
2392
2393
        // munge host if using OpenSSL
2394
        if ($this->scheme == 'ssl') {
2395
            $host = 'ssl://' . $host;
2396
        }
2397
        $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
2398
2399
        // open socket
2400
        if ($connection_timeout > 0) {
2401
            $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout);
0 ignored issues
show
Bug introduced by
The property errno does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
2402
        } else {
2403
            $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str);
2404
        }
2405
2406
        // test pointer
2407
        if (!$this->fp) {
2408
            $msg = 'Couldn\'t open socket connection to server ' . $this->url;
2409
            if ($this->errno) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->errno of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
2410
                $msg .= ', Error ('.$this->errno.'): '.$this->error_str;
2411
            } else {
2412
                $msg .= ' prior to connect().  This is often a problem looking up the host name.';
2413
            }
2414
            $this->debug($msg);
2415
            $this->setError($msg);
2416
2417
            return false;
2418
        }
2419
2420
        // set response timeout
2421
        $this->debug('set response timeout to ' . $response_timeout);
2422
        socket_set_timeout( $this->fp, $response_timeout);
2423
2424
        $this->debug('socket connected');
2425
2426
        return true;
2427
      } else if ($this->io_method() == 'curl') {
2428
        if (!extension_loaded('curl')) {
2429
//			$this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2430
            $this->setError('The PHP cURL Extension is required for HTTPS or NLTM.  You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.');
2431
2432
            return false;
2433
        }
2434
        // Avoid warnings when PHP does not have these options
2435
        if (defined('CURLOPT_CONNECTIONTIMEOUT'))
2436
            $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
2437
        else
2438
            $CURLOPT_CONNECTIONTIMEOUT = 78;
2439
        if (defined('CURLOPT_HTTPAUTH'))
2440
            $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
2441
        else
2442
            $CURLOPT_HTTPAUTH = 107;
2443
        if (defined('CURLOPT_PROXYAUTH'))
2444
            $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
2445
        else
2446
            $CURLOPT_PROXYAUTH = 111;
2447
        if (defined('CURLAUTH_BASIC'))
2448
            $CURLAUTH_BASIC = CURLAUTH_BASIC;
2449
        else
2450
            $CURLAUTH_BASIC = 1;
2451
        if (defined('CURLAUTH_DIGEST'))
2452
            $CURLAUTH_DIGEST = CURLAUTH_DIGEST;
2453
        else
2454
            $CURLAUTH_DIGEST = 2;
2455
        if (defined('CURLAUTH_NTLM'))
2456
            $CURLAUTH_NTLM = CURLAUTH_NTLM;
2457
        else
2458
            $CURLAUTH_NTLM = 8;
2459
2460
        $this->debug('connect using cURL');
2461
        // init CURL
2462
        $this->ch = curl_init();
0 ignored issues
show
Documentation Bug introduced by
It seems like curl_init() of type resource is incompatible with the declared type boolean of property $ch.

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...
2463
        // set url
2464
        $hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
2465
        // add path
2466
        $hostURL .= $this->path;
2467
        $this->setCurlOption(CURLOPT_URL, $hostURL);
2468
        // follow location headers (re-directs)
2469
        if (ini_get('safe_mode') || ini_get('open_basedir')) {
2470
            $this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION');
2471
            $this->debug('safe_mode = ');
2472
            $this->appendDebug($this->varDump(ini_get('safe_mode')));
2473
            $this->debug('open_basedir = ');
2474
            $this->appendDebug($this->varDump(ini_get('open_basedir')));
2475
        } else {
2476
            $this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
2477
        }
2478
        // ask for headers in the response output
2479
        $this->setCurlOption(CURLOPT_HEADER, 1);
2480
        // ask for the response output as the return value
2481
        $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
2482
        // encode
2483
        // We manage this ourselves through headers and encoding
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2484
//		if (function_exists('gzuncompress')) {
2485
//			$this->setCurlOption(CURLOPT_ENCODING, 'deflate');
2486
//		}
2487
        // persistent connection
2488
        if ($this->persistentConnection) {
2489
            // I believe the following comment is now bogus, having applied to
2490
            // the code when it used CURLOPT_CUSTOMREQUEST to send the request.
2491
            // The way we send data, we cannot use persistent connections, since
2492
            // there will be some "junk" at the end of our request.
2493
            //$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2494
            $this->persistentConnection = false;
2495
            $this->setHeader('Connection', 'close');
2496
        }
2497
        // set timeouts
2498
        if ($connection_timeout != 0) {
2499
            $this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
2500
        }
2501
        if ($response_timeout != 0) {
2502
            $this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
2503
        }
2504
2505
        if ($this->scheme == 'https') {
2506
            $this->debug('set cURL SSL verify options');
2507
            // recent versions of cURL turn on peer/host checking by default,
2508
            // while PHP binaries are not compiled with a default location for the
2509
            // CA cert bundle, so disable peer/host checking.
2510
            //$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2511
            $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
2512
            $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
2513
2514
            // support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
2515
            if ($this->authtype == 'certificate') {
2516
                $this->debug('set cURL certificate options');
2517
                if (isset($this->certRequest['cainfofile'])) {
2518
                    $this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
2519
                }
2520
                if (isset($this->certRequest['verifypeer'])) {
2521
                    $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
2522
                } else {
2523
                    $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
2524
                }
2525
                if (isset($this->certRequest['verifyhost'])) {
2526
                    $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
2527
                } else {
2528
                    $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
2529
                }
2530
                if (isset($this->certRequest['sslcertfile'])) {
2531
                    $this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
2532
                }
2533
                if (isset($this->certRequest['sslkeyfile'])) {
2534
                    $this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
2535
                }
2536
                if (isset($this->certRequest['passphrase'])) {
2537
                    $this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
2538
                }
2539
                if (isset($this->certRequest['certpassword'])) {
2540
                    $this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
2541
                }
2542
            }
2543
        }
2544
        if ($this->authtype && ($this->authtype != 'certificate')) {
2545
            if ($this->username) {
2546
                $this->debug('set cURL username/password');
2547
                $this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
2548
            }
2549
            if ($this->authtype == 'basic') {
2550
                $this->debug('set cURL for Basic authentication');
2551
                $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
2552
            }
2553
            if ($this->authtype == 'digest') {
2554
                $this->debug('set cURL for digest authentication');
2555
                $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
2556
            }
2557
            if ($this->authtype == 'ntlm') {
2558
                $this->debug('set cURL for NTLM authentication');
2559
                $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
2560
            }
2561
        }
2562
        if (is_array($this->proxy)) {
2563
            $this->debug('set cURL proxy options');
2564
            if ($this->proxy['port'] != '') {
2565
                $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']);
2566
            } else {
2567
                $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
2568
            }
2569
            if ($this->proxy['username'] || $this->proxy['password']) {
2570
                $this->debug('set cURL proxy authentication options');
2571
                $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']);
2572
                if ($this->proxy['authtype'] == 'basic') {
2573
                    $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
2574
                }
2575
                if ($this->proxy['authtype'] == 'ntlm') {
2576
                    $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
2577
                }
2578
            }
2579
        }
2580
        $this->debug('cURL connection set up');
2581
2582
        return true;
2583
      } else {
2584
        $this->setError('Unknown scheme ' . $this->scheme);
2585
        $this->debug('Unknown scheme ' . $this->scheme);
2586
2587
        return false;
2588
      }
2589
    }
2590
2591
    /**
2592
    * sends the SOAP request and gets the SOAP response via HTTP[S]
2593
    *
2594
    * @param    string $data message data
2595
    * @param    integer $timeout set connection timeout in seconds
2596
    * @param	integer $response_timeout set response timeout in seconds
2597
    * @param	array $cookies cookies to send
0 ignored issues
show
Documentation introduced by
Should the type for parameter $cookies not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2598
    * @return	string data
0 ignored issues
show
Documentation introduced by
Should the return type not be false|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2599
    * @access   public
2600
    */
2601
    function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2602
2603
        $this->debug('entered send() with data of length: '.strlen($data));
2604
2605
        $this->tryagain = true;
0 ignored issues
show
Bug introduced by
The property tryagain does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
2606
        $tries = 0;
2607
        while ($this->tryagain) {
2608
            $this->tryagain = false;
2609
            if ($tries++ < 2) {
2610
                // make connnection
2611
                if (!$this->connect($timeout, $response_timeout)) {
2612
                    return false;
2613
                }
2614
2615
                // send request
2616
                if (!$this->sendRequest($data, $cookies)) {
2617
                    return false;
2618
                }
2619
2620
                // get response
2621
                $respdata = $this->getResponse();
2622
            } else {
2623
                $this->setError("Too many tries to get an OK response ($this->response_status_line)");
2624
            }
2625
        }
2626
        $this->debug('end of send()');
2627
2628
        return $respdata;
0 ignored issues
show
Bug introduced by
The variable $respdata does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2629
    }
2630
2631
    /**
2632
    * sends the SOAP request and gets the SOAP response via HTTPS using CURL
2633
    *
2634
    * @param    string $data message data
2635
    * @param    integer $timeout set connection timeout in seconds
2636
    * @param	integer $response_timeout set response timeout in seconds
2637
    * @param	array $cookies cookies to send
2638
    * @return	string data
0 ignored issues
show
Documentation introduced by
Should the return type not be false|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2639
    * @access   public
2640
    * @deprecated
2641
    */
2642
    function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2643
        return $this->send($data, $timeout, $response_timeout, $cookies);
2644
    }
2645
2646
    /**
2647
    * if authenticating, set user credentials here
2648
    *
2649
    * @param    string $username
2650
    * @param    string $password
2651
    * @param	string $authtype (basic|digest|certificate|ntlm)
2652
    * @param	array $digestRequest (keys must be nonce, nc, realm, qop)
2653
    * @param	array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
2654
    * @access   public
2655
    */
2656
    function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2657
        $this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
2658
        $this->appendDebug($this->varDump($digestRequest));
2659
        $this->debug("certRequest=");
2660
        $this->appendDebug($this->varDump($certRequest));
2661
        // cf. RFC 2617
2662
        if ($authtype == 'basic') {
2663
            $this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password));
2664
        } elseif ($authtype == 'digest') {
2665
            if (isset($digestRequest['nonce'])) {
2666
                $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
2667
2668
                // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
2669
2670
                // A1 = unq(username-value) ":" unq(realm-value) ":" passwd
2671
                $A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
2672
2673
                // H(A1) = MD5(A1)
2674
                $HA1 = md5($A1);
2675
2676
                // A2 = Method ":" digest-uri-value
2677
                $A2 = $this->request_method . ':' . $this->digest_uri;
2678
2679
                // H(A2)
2680
                $HA2 =  md5($A2);
2681
2682
                // KD(secret, data) = H(concat(secret, ":", data))
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2683
                // if qop == auth:
2684
                // request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
2685
                //                              ":" nc-value
2686
                //                              ":" unq(cnonce-value)
2687
                //                              ":" unq(qop-value)
2688
                //                              ":" H(A2)
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2689
                //                            ) <">
2690
                // if qop is missing,
2691
                // request-digest  = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
2692
2693
                $unhashedDigest = '';
0 ignored issues
show
Unused Code introduced by
$unhashedDigest is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2694
                $nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
2695
                $cnonce = $nonce;
2696
                if ($digestRequest['qop'] != '') {
2697
                    $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
2698
                } else {
2699
                    $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
2700
                }
2701
2702
                $hashedDigest = md5($unhashedDigest);
2703
2704
                $opaque = '';
2705
                if (isset($digestRequest['opaque'])) {
2706
                    $opaque = ', opaque="' . $digestRequest['opaque'] . '"';
2707
                }
2708
2709
                $this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"');
2710
            }
2711
        } elseif ($authtype == 'certificate') {
2712
            $this->certRequest = $certRequest;
2713
            $this->debug('Authorization header not set for certificate');
2714
        } elseif ($authtype == 'ntlm') {
2715
            // do nothing
2716
            $this->debug('Authorization header not set for ntlm');
2717
        }
2718
        $this->username = $username;
2719
        $this->password = $password;
2720
        $this->authtype = $authtype;
2721
        $this->digestRequest = $digestRequest;
2722
    }
2723
2724
    /**
2725
    * set the soapaction value
2726
    *
2727
    * @param    string $soapaction
2728
    * @access   public
2729
    */
2730
    function setSOAPAction($soapaction) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2731
        $this->setHeader('SOAPAction', '"' . $soapaction . '"');
2732
    }
2733
2734
    /**
2735
    * use http encoding
2736
    *
2737
    * @param    string $enc encoding style. supported values: gzip, deflate, or both
2738
    * @access   public
2739
    */
2740
    function setEncoding($enc='gzip, deflate') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2741
        if (function_exists('gzdeflate')) {
2742
            $this->protocol_version = '1.1';
2743
            $this->setHeader('Accept-Encoding', $enc);
2744
            if (!isset($this->outgoing_headers['Connection'])) {
2745
                $this->setHeader('Connection', 'close');
2746
                $this->persistentConnection = false;
2747
            }
2748
            // deprecated as of PHP 5.3.0
2749
            //set_magic_quotes_runtime(0);
2750
            $this->encoding = $enc;
2751
        }
2752
    }
2753
2754
    /**
2755
    * set proxy info here
2756
    *
2757
    * @param    string $proxyhost use an empty string to remove proxy
2758
    * @param    string $proxyport
2759
    * @param	string $proxyusername
2760
    * @param	string $proxypassword
2761
    * @param	string $proxyauthtype (basic|ntlm)
2762
    * @access   public
2763
    */
2764
    function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2765
        if ($proxyhost) {
2766
            $this->proxy = array(
2767
                'host' => $proxyhost,
2768
                'port' => $proxyport,
2769
                'username' => $proxyusername,
2770
                'password' => $proxypassword,
2771
                'authtype' => $proxyauthtype
2772
            );
2773
            if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') {
2774
                $this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword));
2775
            }
2776
        } else {
2777
            $this->debug('remove proxy');
2778
            $proxy = null;
0 ignored issues
show
Unused Code introduced by
$proxy is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2779
            unsetHeader('Proxy-Authorization');
2780
        }
2781
    }
2782
2783
    /**
2784
     * Test if the given string starts with a header that is to be skipped.
2785
     * Skippable headers result from chunked transfer and proxy requests.
2786
     *
2787
     * @param string $data The string to check.
2788
     * @returns	boolean	Whether a skippable header was found.
2789
     * @access	private
2790
     */
2791
    function isSkippableCurlHeader(&$data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2792
        $skipHeaders = array(    'HTTP/1.1 100',
2793
                                'HTTP/1.0 301',
2794
                                'HTTP/1.1 301',
2795
                                'HTTP/1.0 302',
2796
                                'HTTP/1.1 302',
2797
                                'HTTP/1.0 401',
2798
                                'HTTP/1.1 401',
2799
                                'HTTP/1.0 200 Connection established');
2800
        foreach ($skipHeaders as $hd) {
2801
            $prefix = substr($data, 0, strlen($hd));
2802
            if ($prefix == $hd) return true;
2803
        }
2804
2805
        return false;
2806
    }
2807
2808
    /**
2809
    * decode a string that is encoded w/ "chunked' transfer encoding
2810
    * as defined in RFC2068 19.4.6
2811
    *
2812
    * @param    string $buffer
2813
    * @param    string $lb
2814
    * @returns	string
2815
    * @access   public
2816
    * @deprecated
2817
    */
2818
    function decodeChunked($buffer, $lb){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2819
        // length := 0
2820
        $length = 0;
2821
        $new = '';
2822
2823
        // read chunk-size, chunk-extension (if any) and CRLF
2824
        // get the position of the linebreak
2825
        $chunkend = strpos($buffer, $lb);
2826
        if ($chunkend == FALSE) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $chunkend of type integer to the boolean FALSE. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
2827
            $this->debug('no linebreak found in decodeChunked');
2828
2829
            return $new;
2830
        }
2831
        $temp = substr($buffer,0,$chunkend);
2832
        $chunk_size = hexdec( trim($temp) );
2833
        $chunkstart = $chunkend + strlen($lb);
2834
        // while (chunk-size > 0) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2835
        while ($chunk_size > 0) {
2836
            $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
2837
            $chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size);
2838
2839
            // Just in case we got a broken connection
2840
            if ($chunkend == FALSE) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $chunkend of type integer to the boolean FALSE. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
2841
                $chunk = substr($buffer,$chunkstart);
2842
                // append chunk-data to entity-body
2843
                $new .= $chunk;
2844
                $length += strlen($chunk);
2845
                break;
2846
            }
2847
2848
            // read chunk-data and CRLF
2849
            $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
2850
            // append chunk-data to entity-body
2851
            $new .= $chunk;
2852
            // length := length + chunk-size
2853
            $length += strlen($chunk);
2854
            // read chunk-size and CRLF
2855
            $chunkstart = $chunkend + strlen($lb);
2856
2857
            $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
2858
            if ($chunkend == FALSE) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $chunkend of type integer to the boolean FALSE. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
2859
                break; //Just in case we got a broken connection
2860
            }
2861
            $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
2862
            $chunk_size = hexdec( trim($temp) );
2863
            $chunkstart = $chunkend;
2864
        }
2865
2866
        return $new;
2867
    }
2868
2869
    /**
2870
     * Writes the payload, including HTTP headers, to $this->outgoing_payload.
2871
     *
2872
     * @param  string $data       HTTP body
2873
     * @param  string $cookie_str data for HTTP Cookie header
2874
     * @return void
2875
     * @access	private
2876
     */
2877
    function buildPayload($data, $cookie_str = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2878
        // Note: for cURL connections, $this->outgoing_payload is ignored,
2879
        // as is the Content-Length header, but these are still created as
2880
        // debugging guides.
2881
2882
        // add content-length header
2883
        if ($this->request_method != 'GET') {
2884
            $this->setHeader('Content-Length', strlen($data));
2885
        }
2886
2887
        // start building outgoing payload:
2888
        if ($this->proxy) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->proxy of type array<string,string> is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2889
            $uri = $this->url;
2890
        } else {
2891
            $uri = $this->uri;
2892
        }
2893
        $req = "$this->request_method $uri HTTP/$this->protocol_version";
2894
        $this->debug("HTTP request: $req");
2895
        $this->outgoing_payload = "$req\r\n";
2896
2897
        // loop thru headers, serializing
2898
        foreach ($this->outgoing_headers as $k => $v) {
2899
            $hdr = $k.': '.$v;
2900
            $this->debug("HTTP header: $hdr");
2901
            $this->outgoing_payload .= "$hdr\r\n";
2902
        }
2903
2904
        // add any cookies
2905
        if ($cookie_str != '') {
2906
            $hdr = 'Cookie: '.$cookie_str;
2907
            $this->debug("HTTP header: $hdr");
2908
            $this->outgoing_payload .= "$hdr\r\n";
2909
        }
2910
2911
        // header/body separator
2912
        $this->outgoing_payload .= "\r\n";
2913
2914
        // add data
2915
        $this->outgoing_payload .= $data;
2916
    }
2917
2918
    /**
2919
    * sends the SOAP request via HTTP[S]
2920
    *
2921
    * @param    string $data message data
2922
    * @param	array $cookies cookies to send
0 ignored issues
show
Documentation introduced by
Should the type for parameter $cookies not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2923
    * @return	boolean	true if OK, false if problem
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2924
    * @access   private
2925
    */
2926
    function sendRequest($data, $cookies = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2927
        // build cookie string
2928
        $cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https')));
0 ignored issues
show
Bug introduced by
It seems like $cookies defined by parameter $cookies on line 2926 can also be of type null; however, soap_transport_http::getCookiesForRequest() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
2929
2930
        // build payload
2931
        $this->buildPayload($data, $cookie_str);
2932
2933
      if ($this->io_method() == 'socket') {
2934
        // send payload
2935
        if (!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
2936
            $this->setError('couldn\'t write message data to socket');
2937
            $this->debug('couldn\'t write message data to socket');
2938
2939
            return false;
2940
        }
2941
        $this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
2942
2943
        return true;
2944
      } else if ($this->io_method() == 'curl') {
2945
        // set payload
2946
        // cURL does say this should only be the verb, and in fact it
2947
        // turns out that the URI and HTTP version are appended to this, which
2948
        // some servers refuse to work with (so we no longer use this method!)
2949
        //$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2950
        $curl_headers = array();
2951
        foreach ($this->outgoing_headers as $k => $v) {
2952
            if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') {
2953
                $this->debug("Skip cURL header $k: $v");
2954
            } else {
2955
                $curl_headers[] = "$k: $v";
2956
            }
2957
        }
2958
        if ($cookie_str != '') {
2959
            $curl_headers[] = 'Cookie: ' . $cookie_str;
2960
        }
2961
        $this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
2962
        $this->debug('set cURL HTTP headers');
2963
        if ($this->request_method == "POST") {
2964
            $this->setCurlOption(CURLOPT_POST, 1);
2965
            $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
2966
            $this->debug('set cURL POST data');
2967
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
2968
        }
2969
        // insert custom user-set cURL options
2970
        foreach ($this->ch_options as $key => $val) {
2971
            $this->setCurlOption($key, $val);
2972
        }
2973
2974
        $this->debug('set cURL payload');
2975
2976
        return true;
2977
      }
2978
    }
2979
2980
    /**
2981
    * gets the SOAP response via HTTP[S]
2982
    *
2983
    * @return	string the response (also sets member variables like incoming_payload)
2984
    * @access   private
2985
    */
2986
    function getResponse(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2987
        $this->incoming_payload = '';
2988
2989
      if ($this->io_method() == 'socket') {
2990
        // loop until headers have been retrieved
2991
        $data = '';
2992
        while (!isset($lb)) {
2993
2994
            // We might EOF during header read.
2995 View Code Duplication
            if (feof($this->fp)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2996
                $this->incoming_payload = $data;
2997
                $this->debug('found no headers before EOF after length ' . strlen($data));
2998
                $this->debug("received before EOF:\n" . $data);
2999
                $this->setError('server failed to send headers');
3000
3001
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3002
            }
3003
3004
            $tmp = fgets($this->fp, 256);
3005
            $tmplen = strlen($tmp);
3006
            $this->debug("read line of $tmplen bytes: " . trim($tmp));
3007
3008 View Code Duplication
            if ($tmplen == 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3009
                $this->incoming_payload = $data;
3010
                $this->debug('socket read of headers timed out after length ' . strlen($data));
3011
                $this->debug("read before timeout: " . $data);
3012
                $this->setError('socket read of headers timed out');
3013
3014
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3015
            }
3016
3017
            $data .= $tmp;
3018
            $pos = strpos($data,"\r\n\r\n");
3019
            if ($pos > 1) {
3020
                $lb = "\r\n";
3021
            } else {
3022
                $pos = strpos($data,"\n\n");
3023
                if ($pos > 1) {
3024
                    $lb = "\n";
3025
                }
3026
            }
3027
            // remove 100 headers
3028
            if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) {
3029
                unset($lb);
3030
                $data = '';
3031
            }//
3032
        }
3033
        // store header data
3034
        $this->incoming_payload .= $data;
3035
        $this->debug('found end of headers after length ' . strlen($data));
3036
        // process headers
3037
        $header_data = trim(substr($data,0,$pos));
0 ignored issues
show
Bug introduced by
The variable $pos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3038
        $header_array = explode($lb,$header_data);
3039
        $this->incoming_headers = array();
3040
        $this->incoming_cookies = array();
3041 View Code Duplication
        foreach ($header_array as $header_line) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3042
            $arr = explode(':',$header_line, 2);
3043
            if (count($arr) > 1) {
3044
                $header_name = strtolower(trim($arr[0]));
3045
                $this->incoming_headers[$header_name] = trim($arr[1]);
3046
                if ($header_name == 'set-cookie') {
3047
                    // TODO: allow multiple cookies from parseCookie
3048
                    $cookie = $this->parseCookie(trim($arr[1]));
3049
                    if ($cookie) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cookie of type array<string,string|boolean> is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
3050
                        $this->incoming_cookies[] = $cookie;
3051
                        $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3052
                    } else {
3053
                        $this->debug('did not find cookie in ' . trim($arr[1]));
3054
                    }
3055
                }
3056
            } else if (isset($header_name)) {
3057
                // append continuation line to previous header
3058
                $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3059
            }
3060
        }
3061
3062
        // loop until msg has been received
3063
        if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
3064
            $content_length =  2147483647;    // ignore any content-length header
3065
            $chunked = true;
3066
            $this->debug("want to read chunked content");
3067
        } elseif (isset($this->incoming_headers['content-length'])) {
3068
            $content_length = $this->incoming_headers['content-length'];
3069
            $chunked = false;
3070
            $this->debug("want to read content of length $content_length");
3071
        } else {
3072
            $content_length =  2147483647;
3073
            $chunked = false;
3074
            $this->debug("want to read content to EOF");
3075
        }
3076
        $data = '';
3077
        do {
3078
            if ($chunked) {
3079
                $tmp = fgets($this->fp, 256);
3080
                $tmplen = strlen($tmp);
3081
                $this->debug("read chunk line of $tmplen bytes");
3082 View Code Duplication
                if ($tmplen == 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3083
                    $this->incoming_payload = $data;
3084
                    $this->debug('socket read of chunk length timed out after length ' . strlen($data));
3085
                    $this->debug("read before timeout:\n" . $data);
3086
                    $this->setError('socket read of chunk length timed out');
3087
3088
                    return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3089
                }
3090
                $content_length = hexdec(trim($tmp));
3091
                $this->debug("chunk length $content_length");
3092
            }
3093
            $strlen = 0;
3094
            while (($strlen < $content_length) && (!feof($this->fp))) {
3095
                $readlen = min(8192, $content_length - $strlen);
3096
                $tmp = fread($this->fp, $readlen);
3097
                $tmplen = strlen($tmp);
3098
                $this->debug("read buffer of $tmplen bytes");
3099 View Code Duplication
                if (($tmplen == 0) && (!feof($this->fp))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3100
                    $this->incoming_payload = $data;
3101
                    $this->debug('socket read of body timed out after length ' . strlen($data));
3102
                    $this->debug("read before timeout:\n" . $data);
3103
                    $this->setError('socket read of body timed out');
3104
3105
                    return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3106
                }
3107
                $strlen += $tmplen;
3108
                $data .= $tmp;
3109
            }
3110
            if ($chunked && ($content_length > 0)) {
3111
                $tmp = fgets($this->fp, 256);
3112
                $tmplen = strlen($tmp);
3113
                $this->debug("read chunk terminator of $tmplen bytes");
3114 View Code Duplication
                if ($tmplen == 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3115
                    $this->incoming_payload = $data;
3116
                    $this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
3117
                    $this->debug("read before timeout:\n" . $data);
3118
                    $this->setError('socket read of chunk terminator timed out');
3119
3120
                    return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3121
                }
3122
            }
3123
        } while ($chunked && ($content_length > 0) && (!feof($this->fp)));
3124
        if (feof($this->fp)) {
3125
            $this->debug('read to EOF');
3126
        }
3127
        $this->debug('read body of length ' . strlen($data));
3128
        $this->incoming_payload .= $data;
3129
        $this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server');
3130
3131
        // close filepointer
3132
        if(
3133
            (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
3134
            (! $this->persistentConnection) || feof($this->fp)){
3135
            fclose($this->fp);
3136
            $this->fp = false;
3137
            $this->debug('closed socket');
3138
        }
3139
3140
        // connection was closed unexpectedly
3141
        if ($this->incoming_payload == '') {
3142
            $this->setError('no response from server');
3143
3144
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3145
        }
3146
3147
        // decode transfer-encoding
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
3148
//		if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
3149
//			if (!$data = $this->decodeChunked($data, $lb)) {
3150
//				$this->setError('Decoding of chunked data failed');
3151
//				return false;
3152
//			}
3153
            //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
3154
            // set decoded payload
3155
//			$this->incoming_payload = $header_data.$lb.$lb.$data;
3156
//		}
3157
3158
      } else if ($this->io_method() == 'curl') {
3159
        // send and receive
3160
        $this->debug('send and receive with cURL');
3161
        $this->incoming_payload = curl_exec($this->ch);
3162
        $data = $this->incoming_payload;
3163
3164
        $cErr = curl_error($this->ch);
3165
        if ($cErr != '') {
3166
            $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>';
3167
            // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
3168
            foreach (curl_getinfo($this->ch) as $k => $v) {
3169
                $err .= "$k: $v<br>";
3170
            }
3171
            $this->debug($err);
3172
            $this->setError($err);
3173
            curl_close($this->ch);
3174
3175
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3176
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
3177
            //echo '<pre>';
3178
            //var_dump(curl_getinfo($this->ch));
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
3179
            //echo '</pre>';
3180
        }
3181
        // close curl
3182
        $this->debug('No cURL error, closing cURL');
3183
        curl_close($this->ch);
3184
3185
        // try removing skippable headers
3186
        $savedata = $data;
3187
        while ($this->isSkippableCurlHeader($data)) {
3188
            $this->debug("Found HTTP header to skip");
3189 View Code Duplication
            if ($pos = strpos($data,"\r\n\r\n")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3190
                $data = ltrim(substr($data,$pos));
3191
            } elseif ($pos = strpos($data,"\n\n") ) {
3192
                $data = ltrim(substr($data,$pos));
3193
            }
3194
        }
3195
3196
        if ($data == '') {
3197
            // have nothing left; just remove 100 header(s)
3198
            $data = $savedata;
3199
            while (preg_match('/^HTTP\/1.1 100/',$data)) {
3200 View Code Duplication
                if ($pos = strpos($data,"\r\n\r\n")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3201
                    $data = ltrim(substr($data,$pos));
3202
                } elseif ($pos = strpos($data,"\n\n") ) {
3203
                    $data = ltrim(substr($data,$pos));
3204
                }
3205
            }
3206
        }
3207
3208
        // separate content from HTTP headers
3209
        if ($pos = strpos($data,"\r\n\r\n")) {
3210
            $lb = "\r\n";
3211
        } elseif ( $pos = strpos($data,"\n\n")) {
3212
            $lb = "\n";
3213
        } else {
3214
            $this->debug('no proper separation of headers and document');
3215
            $this->setError('no proper separation of headers and document');
3216
3217
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3218
        }
3219
        $header_data = trim(substr($data,0,$pos));
3220
        $header_array = explode($lb,$header_data);
3221
        $data = ltrim(substr($data,$pos));
3222
        $this->debug('found proper separation of headers and document');
3223
        $this->debug('cleaned data, stringlen: '.strlen($data));
3224
        // clean headers
3225 View Code Duplication
        foreach ($header_array as $header_line) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3226
            $arr = explode(':',$header_line,2);
3227
            if (count($arr) > 1) {
3228
                $header_name = strtolower(trim($arr[0]));
3229
                $this->incoming_headers[$header_name] = trim($arr[1]);
3230
                if ($header_name == 'set-cookie') {
3231
                    // TODO: allow multiple cookies from parseCookie
3232
                    $cookie = $this->parseCookie(trim($arr[1]));
3233
                    if ($cookie) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cookie of type array<string,string|boolean> is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
3234
                        $this->incoming_cookies[] = $cookie;
3235
                        $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3236
                    } else {
3237
                        $this->debug('did not find cookie in ' . trim($arr[1]));
3238
                    }
3239
                }
3240
            } else if (isset($header_name)) {
3241
                // append continuation line to previous header
3242
                $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3243
            }
3244
        }
3245
      }
3246
3247
        $this->response_status_line = $header_array[0];
0 ignored issues
show
Bug introduced by
The variable $header_array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3248
        $arr = explode(' ', $this->response_status_line, 3);
3249
        $http_version = $arr[0];
0 ignored issues
show
Unused Code introduced by
$http_version is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3250
        $http_status = intval($arr[1]);
3251
        $http_reason = count($arr) > 2 ? $arr[2] : '';
3252
3253
        // see if we need to resend the request with http digest authentication
3254
        if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) {
3255
            $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
3256
            $this->setURL($this->incoming_headers['location']);
3257
            $this->tryagain = true;
3258
3259
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3260
        }
3261
3262
        // see if we need to resend the request with http digest authentication
3263
        if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) {
3264
            $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
3265
            if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) {
3266
                $this->debug('Server wants digest authentication');
3267
                // remove "Digest " from our elements
3268
                $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
3269
3270
                // parse elements into array
3271
                $digestElements = explode(',', $digestString);
3272
                foreach ($digestElements as $val) {
3273
                    $tempElement = explode('=', trim($val), 2);
3274
                    $digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$digestRequest was never initialized. Although not strictly required by PHP, it is generally a good practice to add $digestRequest = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
3275
                }
3276
3277
                // should have (at least) qop, realm, nonce
3278
                if (isset($digestRequest['nonce'])) {
3279
                    $this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
3280
                    $this->tryagain = true;
3281
3282
                    return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3283
                }
3284
            }
3285
            $this->debug('HTTP authentication failed');
3286
            $this->setError('HTTP authentication failed');
3287
3288
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3289
        }
3290
3291
        if (
3292
            ($http_status >= 300 && $http_status <= 307) ||
3293
            ($http_status >= 400 && $http_status <= 417) ||
3294
            ($http_status >= 501 && $http_status <= 505)
3295
           ) {
3296
            $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
3297
3298
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3299
        }
3300
3301
        // decode content-encoding
3302
        if (isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != '') {
3303
            if (strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip') {
3304
                // if decoding works, use it. else assume data wasn't gzencoded
3305
                if (function_exists('gzinflate')) {
3306
                    //$timer->setMarker('starting decoding of gzip/deflated content');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
3307
                    // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
3308
                    // this means there are no Zlib headers, although there should be
3309
                    $this->debug('The gzinflate function exists');
3310
                    $datalen = strlen($data);
0 ignored issues
show
Bug introduced by
The variable $data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3311
                    if ($this->incoming_headers['content-encoding'] == 'deflate') {
3312
                        if ($degzdata = @gzinflate($data)) {
3313
                            $data = $degzdata;
3314
                            $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
3315 View Code Duplication
                            if (strlen($data) < $datalen) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3316
                                // test for the case that the payload has been compressed twice
3317
                                $this->debug('The inflated payload is smaller than the gzipped one; try again');
3318
                                if ($degzdata = @gzinflate($data)) {
3319
                                    $data = $degzdata;
3320
                                    $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
3321
                                }
3322
                            }
3323
                        } else {
3324
                            $this->debug('Error using gzinflate to inflate the payload');
3325
                            $this->setError('Error using gzinflate to inflate the payload');
3326
                        }
3327
                    } elseif ($this->incoming_headers['content-encoding'] == 'gzip') {
3328
                        if ($degzdata = @gzinflate(substr($data, 10))) {    // do our best
3329
                            $data = $degzdata;
3330
                            $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
3331 View Code Duplication
                            if (strlen($data) < $datalen) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3332
                                // test for the case that the payload has been compressed twice
3333
                                $this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
3334
                                if ($degzdata = @gzinflate(substr($data, 10))) {
3335
                                    $data = $degzdata;
3336
                                    $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
3337
                                }
3338
                            }
3339
                        } else {
3340
                            $this->debug('Error using gzinflate to un-gzip the payload');
3341
                            $this->setError('Error using gzinflate to un-gzip the payload');
3342
                        }
3343
                    }
3344
                    //$timer->setMarker('finished decoding of gzip/deflated content');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
3345
                    //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
3346
                    // set decoded payload
3347
                    $this->incoming_payload = $header_data.$lb.$lb.$data;
0 ignored issues
show
Bug introduced by
The variable $header_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $lb does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3348
                } else {
3349
                    $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3350
                    $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3351
                }
3352
            } else {
3353
                $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3354
                $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3355
            }
3356
        } else {
3357
            $this->debug('No Content-Encoding header');
3358
        }
3359
3360
        if (strlen($data) == 0) {
3361
            $this->debug('no data after headers!');
3362
            $this->setError('no data present after HTTP headers');
3363
3364
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by soap_transport_http::getResponse of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
3365
        }
3366
3367
        return $data;
3368
    }
3369
3370
    /**
3371
     * sets the content-type for the SOAP message to be sent
3372
     *
3373
     * @param string $type    the content type, MIME style
3374
     * @param mixed  $charset character set used for encoding (or false)
3375
     * @access	public
3376
     */
3377
    function setContentType($type, $charset = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3378
        $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
3379
    }
3380
3381
    /**
3382
     * specifies that an HTTP persistent connection should be used
3383
     *
3384
     * @return boolean whether the request was honored by this method.
3385
     * @access	public
3386
     */
3387
    function usePersistentConnection(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3388
        if (isset($this->outgoing_headers['Accept-Encoding'])) {
3389
            return false;
3390
        }
3391
        $this->protocol_version = '1.1';
3392
        $this->persistentConnection = true;
3393
        $this->setHeader('Connection', 'Keep-Alive');
3394
3395
        return true;
3396
    }
3397
3398
    /**
3399
     * parse an incoming Cookie into it's parts
3400
     *
3401
     * @param  string $cookie_str content of cookie
3402
     * @return array  with data of that cookie
3403
     * @access	private
3404
     */
3405
    /*
3406
     * TODO: allow a Set-Cookie string to be parsed into multiple cookies
3407
     */
3408
    function parseCookie($cookie_str) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3409
        $cookie_str = str_replace('; ', ';', $cookie_str) . ';';
3410
        $data = preg_split('/;/', $cookie_str);
3411
        $value_str = $data[0];
3412
3413
        $cookie_param = 'domain=';
3414
        $start = strpos($cookie_str, $cookie_param);
3415 View Code Duplication
        if ($start > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3416
            $domain = substr($cookie_str, $start + strlen($cookie_param));
3417
            $domain = substr($domain, 0, strpos($domain, ';'));
3418
        } else {
3419
            $domain = '';
3420
        }
3421
3422
        $cookie_param = 'expires=';
3423
        $start = strpos($cookie_str, $cookie_param);
3424 View Code Duplication
        if ($start > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3425
            $expires = substr($cookie_str, $start + strlen($cookie_param));
3426
            $expires = substr($expires, 0, strpos($expires, ';'));
3427
        } else {
3428
            $expires = '';
3429
        }
3430
3431
        $cookie_param = 'path=';
3432
        $start = strpos($cookie_str, $cookie_param);
3433 View Code Duplication
        if ($start > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3434
            $path = substr($cookie_str, $start + strlen($cookie_param));
3435
            $path = substr($path, 0, strpos($path, ';'));
3436
        } else {
3437
            $path = '/';
3438
        }
3439
3440
        $cookie_param = ';secure;';
3441
        if (strpos($cookie_str, $cookie_param) !== FALSE) {
3442
            $secure = true;
3443
        } else {
3444
            $secure = false;
3445
        }
3446
3447
        $sep_pos = strpos($value_str, '=');
3448
3449
        if ($sep_pos) {
3450
            $name = substr($value_str, 0, $sep_pos);
3451
            $value = substr($value_str, $sep_pos + 1);
3452
            $cookie= array(    'name' => $name,
3453
                            'value' => $value,
3454
                            'domain' => $domain,
3455
                            'path' => $path,
3456
                            'expires' => $expires,
3457
                            'secure' => $secure
3458
                            );
3459
3460
            return $cookie;
3461
        }
3462
3463
        return false;
3464
    }
3465
3466
    /**
3467
     * sort out cookies for the current request
3468
     *
3469
     * @param  array   $cookies array with all cookies
3470
     * @param  boolean $secure  is the send-content secure or not?
3471
     * @return string  for Cookie-HTTP-Header
3472
     * @access	private
3473
     */
3474
    function getCookiesForRequest($cookies, $secure=false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3475
        $cookie_str = '';
3476
        if ((! is_null($cookies)) && (is_array($cookies))) {
3477
            foreach ($cookies as $cookie) {
3478
                if (! is_array($cookie)) {
3479
                    continue;
3480
                }
3481
                $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']);
3482
                if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
3483
                    if (strtotime($cookie['expires']) <= time()) {
3484
                        $this->debug('cookie has expired');
3485
                        continue;
3486
                    }
3487
                }
3488 View Code Duplication
                if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3489
                    $domain = preg_quote($cookie['domain']);
3490
                    if (! preg_match("'.*$domain$'i", $this->host)) {
3491
                        $this->debug('cookie has different domain');
3492
                        continue;
3493
                    }
3494
                }
3495 View Code Duplication
                if ((isset($cookie['path'])) && (! empty($cookie['path']))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3496
                    $path = preg_quote($cookie['path']);
3497
                    if (! preg_match("'^$path.*'i", $this->path)) {
3498
                        $this->debug('cookie is for a different path');
3499
                        continue;
3500
                    }
3501
                }
3502
                if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
3503
                    $this->debug('cookie is secure, transport is not');
3504
                    continue;
3505
                }
3506
                $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
3507
                $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
3508
            }
3509
        }
3510
3511
        return $cookie_str;
3512
  }
3513
}
3514
3515
?><?php
3516
3517
/**
3518
*
3519
* nusoap_server allows the user to create a SOAP server
3520
* that is capable of receiving messages and returning responses
3521
*
3522
* @author   Dietrich Ayala <[email protected]>
3523
* @author   Scott Nichol <[email protected]>
3524
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
3525
* @access   public
3526
*/
3527
class nusoap_server extends nusoap_base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3528
    /**
3529
     * HTTP headers of request
3530
     * @var array
3531
     * @access private
3532
     */
3533
    var $headers = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $headers.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3534
    /**
3535
     * HTTP request
3536
     * @var string
3537
     * @access private
3538
     */
3539
    var $request = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $request.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3540
    /**
3541
     * SOAP headers from request (incomplete namespace resolution; special characters not escaped) (text)
3542
     * @var string
3543
     * @access public
3544
     */
3545
    var $requestHeaders = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $requestHeaders.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3546
    /**
3547
     * SOAP Headers from request (parsed)
3548
     * @var mixed
3549
     * @access public
3550
     */
3551
    var $requestHeader = NULL;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $requestHeader.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3552
    /**
3553
     * SOAP body request portion (incomplete namespace resolution; special characters not escaped) (text)
3554
     * @var string
3555
     * @access public
3556
     */
3557
    var $document = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $document.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3558
    /**
3559
     * SOAP payload for request (text)
3560
     * @var string
3561
     * @access public
3562
     */
3563
    var $requestSOAP = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $requestSOAP.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3564
    /**
3565
     * requested method namespace URI
3566
     * @var string
3567
     * @access private
3568
     */
3569
    var $methodURI = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $methodURI.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3570
    /**
3571
     * name of method requested
3572
     * @var string
3573
     * @access private
3574
     */
3575
    var $methodname = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $methodname.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3576
    /**
3577
     * method parameters from request
3578
     * @var array
3579
     * @access private
3580
     */
3581
    var $methodparams = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $methodparams.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3582
    /**
3583
     * SOAP Action from request
3584
     * @var string
3585
     * @access private
3586
     */
3587
    var $SOAPAction = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $SOAPAction.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3588
    /**
3589
     * character set encoding of incoming (request) messages
3590
     * @var string
3591
     * @access public
3592
     */
3593
    var $xml_encoding = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $xml_encoding.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3594
    /**
3595
     * toggles whether the parser decodes element content w/ utf8_decode()
3596
     * @var boolean
3597
     * @access public
3598
     */
3599
    var $decode_utf8 = true;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $decode_utf8.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3600
3601
    /**
3602
     * HTTP headers of response
3603
     * @var array
3604
     * @access public
3605
     */
3606
    var $outgoing_headers = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $outgoing_headers.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3607
    /**
3608
     * HTTP response
3609
     * @var string
3610
     * @access private
3611
     */
3612
    var $response = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $response.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3613
    /**
3614
     * SOAP headers for response (text or array of soapval or associative array)
3615
     * @var mixed
3616
     * @access public
3617
     */
3618
    var $responseHeaders = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $responseHeaders.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3619
    /**
3620
     * SOAP payload for response (text)
3621
     * @var string
3622
     * @access private
3623
     */
3624
    var $responseSOAP = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $responseSOAP.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3625
    /**
3626
     * method return value to place in response
3627
     * @var mixed
3628
     * @access private
3629
     */
3630
    var $methodreturn = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $methodreturn.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3631
    /**
3632
     * whether $methodreturn is a string of literal XML
3633
     * @var boolean
3634
     * @access public
3635
     */
3636
    var $methodreturnisliteralxml = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $methodreturnisliteralxml.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3637
    /**
3638
     * SOAP fault for response (or false)
3639
     * @var mixed
3640
     * @access private
3641
     */
3642
    var $fault = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fault.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3643
    /**
3644
     * text indication of result (for debugging)
3645
     * @var string
3646
     * @access private
3647
     */
3648
    var $result = 'successful';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $result.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3649
3650
    /**
3651
     * assoc array of operations => opData; operations are added by the register()
3652
     * method or by parsing an external WSDL definition
3653
     * @var array
3654
     * @access private
3655
     */
3656
    var $operations = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $operations.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3657
    /**
3658
     * wsdl instance (if one)
3659
     * @var mixed
3660
     * @access private
3661
     */
3662
    var $wsdl = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $wsdl.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3663
    /**
3664
     * URL for WSDL (if one)
3665
     * @var mixed
3666
     * @access private
3667
     */
3668
    var $externalWSDLURL = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $externalWSDLURL.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3669
    /**
3670
     * whether to append debug to response as XML comment
3671
     * @var boolean
3672
     * @access public
3673
     */
3674
    var $debug_flag = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $debug_flag.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
3675
3676
    /**
3677
    * constructor
3678
    * the optional parameter is a path to a WSDL file that you'd like to bind the server instance to.
3679
    *
3680
    * @param mixed $wsdl file path or URL (string) , or wsdl instance (object)
3681
    * @access   public
3682
    */
3683
    function nusoap_server($wsdl=false){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
nusoap_server uses the super-global variable $HTTP_SERVER_VARS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
nusoap_server uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
3684
        parent::nusoap_base();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (nusoap_base() instead of nusoap_server()). Are you sure this is correct? If so, you might want to change this to $this->nusoap_base().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Coding Style introduced by
PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead
Loading history...
3685
        // turn on debugging?
3686
        global $debug;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
3687
        global $HTTP_SERVER_VARS;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
3688
3689
        if (isset($_SERVER)) {
3690
            $this->debug("_SERVER is defined:");
3691
            $this->appendDebug($this->varDump($_SERVER));
3692
        } elseif (isset($HTTP_SERVER_VARS)) {
3693
            $this->debug("HTTP_SERVER_VARS is defined:");
3694
            $this->appendDebug($this->varDump($HTTP_SERVER_VARS));
3695
        } else {
3696
            $this->debug("Neither _SERVER nor HTTP_SERVER_VARS is defined.");
3697
        }
3698
3699
        if (isset($debug)) {
3700
            $this->debug("In nusoap_server, set debug_flag=$debug based on global flag");
3701
            $this->debug_flag = $debug;
3702
        } elseif (isset($_SERVER['QUERY_STRING'])) {
3703
            $qs = explode('&', $_SERVER['QUERY_STRING']);
3704 View Code Duplication
            foreach ($qs as $v) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3705
                if (substr($v, 0, 6) == 'debug=') {
3706
                    $this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #1");
3707
                    $this->debug_flag = substr($v, 6);
0 ignored issues
show
Documentation Bug introduced by
The property $debug_flag was declared of type boolean, but substr($v, 6) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
3708
                }
3709
            }
3710
        } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3711
            $qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
3712 View Code Duplication
            foreach ($qs as $v) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3713
                if (substr($v, 0, 6) == 'debug=') {
3714
                    $this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #2");
3715
                    $this->debug_flag = substr($v, 6);
3716
                }
3717
            }
3718
        }
3719
3720
        // wsdl
3721
        if ($wsdl) {
3722
            $this->debug("In nusoap_server, WSDL is specified");
3723
            if (is_object($wsdl) && (get_class($wsdl) == 'wsdl')) {
3724
                $this->wsdl = $wsdl;
3725
                $this->externalWSDLURL = $this->wsdl->wsdl;
3726
                $this->debug('Use existing wsdl instance from ' . $this->externalWSDLURL);
3727
            } else {
3728
                $this->debug('Create wsdl from ' . $wsdl);
3729
                $this->wsdl = new wsdl($wsdl);
3730
                $this->externalWSDLURL = $wsdl;
3731
            }
3732
            $this->appendDebug($this->wsdl->getDebug());
3733
            $this->wsdl->clearDebug();
3734
            if ($err = $this->wsdl->getError()) {
3735
                die('WSDL ERROR: '.$err);
0 ignored issues
show
Coding Style Compatibility introduced by
The method nusoap_server() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
3736
            }
3737
        }
3738
    }
3739
3740
    /**
3741
    * processes request and returns response
3742
    *
3743
    * @param    string $data usually is the value of $HTTP_RAW_POST_DATA
3744
    * @access   public
3745
    */
3746
    function service($data){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
service uses the super-global variable $HTTP_SERVER_VARS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
service uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
3747
        global $HTTP_SERVER_VARS;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
3748
3749 View Code Duplication
        if (isset($_SERVER['REQUEST_METHOD'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3750
            $rm = $_SERVER['REQUEST_METHOD'];
3751
        } elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
3752
            $rm = $HTTP_SERVER_VARS['REQUEST_METHOD'];
3753
        } else {
3754
            $rm = '';
3755
        }
3756
3757 View Code Duplication
        if (isset($_SERVER['QUERY_STRING'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3758
            $qs = $_SERVER['QUERY_STRING'];
3759
        } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3760
            $qs = $HTTP_SERVER_VARS['QUERY_STRING'];
3761
        } else {
3762
            $qs = '';
3763
        }
3764
        $this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
3765
3766
        if ($rm == 'POST') {
3767
            $this->debug("In service, invoke the request");
3768
            $this->parse_request($data);
3769
            if (! $this->fault) {
3770
                $this->invoke_method();
3771
            }
3772
            if (! $this->fault) {
3773
                $this->serialize_return();
3774
            }
3775
            $this->send_response();
3776
        } elseif (preg_match('/wsdl/', $qs) ) {
3777
            $this->debug("In service, this is a request for WSDL");
3778
            if ($this->externalWSDLURL) {
3779
              if (strpos($this->externalWSDLURL, "http://") !== false) { // assume URL
3780
                $this->debug("In service, re-direct for WSDL");
3781
                header('Location: '.$this->externalWSDLURL);
3782
              } else { // assume file
3783
                $this->debug("In service, use file passthru for WSDL");
3784
                header("Content-Type: text/xml\r\n");
3785
                $pos = strpos($this->externalWSDLURL, "file://");
3786
                if ($pos === false) {
3787
                    $filename = $this->externalWSDLURL;
0 ignored issues
show
Unused Code introduced by
$filename is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3788
                } else {
3789
                    $filename = substr($this->externalWSDLURL, $pos + 7);
0 ignored issues
show
Unused Code introduced by
$filename is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3790
                }
3791
                $fp = fopen($this->externalWSDLURL, 'r');
3792
                fpassthru($fp);
3793
              }
3794
            } elseif ($this->wsdl) {
3795
                $this->debug("In service, serialize WSDL");
3796
                header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
3797
                print $this->wsdl->serialize($this->debug_flag);
3798
                if ($this->debug_flag) {
3799
                    $this->debug('wsdl:');
3800
                    $this->appendDebug($this->varDump($this->wsdl));
3801
                    print $this->getDebugAsXMLComment();
3802
                }
3803
            } else {
3804
                $this->debug("In service, there is no WSDL");
3805
                header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3806
                print "This service does not provide WSDL";
3807
            }
3808
        } elseif ($this->wsdl) {
3809
            $this->debug("In service, return Web description");
3810
            print $this->wsdl->webDescription();
3811
        } else {
3812
            $this->debug("In service, no Web description");
3813
            header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3814
            print "This service does not provide a Web description";
3815
        }
3816
    }
3817
3818
    /**
3819
    * parses HTTP request headers.
3820
    *
3821
    * The following fields are set by this function (when successful)
3822
    *
3823
    * headers
3824
    * request
3825
    * xml_encoding
3826
    * SOAPAction
3827
    *
3828
    * @access   private
3829
    */
3830
    function parse_http_headers() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
parse_http_headers uses the super-global variable $HTTP_SERVER_VARS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
parse_http_headers uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
3831
        global $HTTP_SERVER_VARS;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
3832
3833
        $this->request = '';
3834
        $this->SOAPAction = '';
3835
        if (function_exists('getallheaders')) {
3836
            $this->debug("In parse_http_headers, use getallheaders");
3837
            $headers = getallheaders();
3838
            foreach ($headers as $k=>$v) {
3839
                $k = strtolower($k);
3840
                $this->headers[$k] = $v;
3841
                $this->request .= "$k: $v\r\n";
3842
                $this->debug("$k: $v");
3843
            }
3844
            // get SOAPAction header
3845
            if (isset($this->headers['soapaction'])) {
3846
                $this->SOAPAction = str_replace('"','',$this->headers['soapaction']);
3847
            }
3848
            // get the character encoding of the incoming request
3849
            if (isset($this->headers['content-type']) && strpos($this->headers['content-type'],'=')) {
3850
                $enc = str_replace('"','',substr(strstr($this->headers["content-type"],'='),1));
3851
                if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
3852
                    $this->xml_encoding = strtoupper($enc);
3853
                } else {
3854
                    $this->xml_encoding = 'US-ASCII';
3855
                }
3856
            } else {
3857
                // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3858
                $this->xml_encoding = 'ISO-8859-1';
3859
            }
3860
        } elseif (isset($_SERVER) && is_array($_SERVER)) {
3861
            $this->debug("In parse_http_headers, use _SERVER");
3862
            foreach ($_SERVER as $k => $v) {
3863
                if (substr($k, 0, 5) == 'HTTP_') {
3864
                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3865
                } else {
3866
                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3867
                }
3868 View Code Duplication
                if ($k == 'soapaction') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3869
                    // get SOAPAction header
3870
                    $k = 'SOAPAction';
3871
                    $v = str_replace('"', '', $v);
3872
                    $v = str_replace('\\', '', $v);
3873
                    $this->SOAPAction = $v;
3874
                } else if ($k == 'content-type') {
3875
                    // get the character encoding of the incoming request
3876
                    if (strpos($v, '=')) {
3877
                        $enc = substr(strstr($v, '='), 1);
3878
                        $enc = str_replace('"', '', $enc);
3879
                        $enc = str_replace('\\', '', $enc);
3880
                        if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
3881
                            $this->xml_encoding = strtoupper($enc);
3882
                        } else {
3883
                            $this->xml_encoding = 'US-ASCII';
3884
                        }
3885
                    } else {
3886
                        // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3887
                        $this->xml_encoding = 'ISO-8859-1';
3888
                    }
3889
                }
3890
                $this->headers[$k] = $v;
3891
                $this->request .= "$k: $v\r\n";
3892
                $this->debug("$k: $v");
3893
            }
3894
        } elseif (is_array($HTTP_SERVER_VARS)) {
3895
            $this->debug("In parse_http_headers, use HTTP_SERVER_VARS");
3896
            foreach ($HTTP_SERVER_VARS as $k => $v) {
3897
                if (substr($k, 0, 5) == 'HTTP_') {
3898
                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));                                             $k = strtolower(substr($k, 5));
3899
                } else {
3900
                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));                                             $k = strtolower($k);
3901
                }
3902 View Code Duplication
                if ($k == 'soapaction') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3903
                    // get SOAPAction header
3904
                    $k = 'SOAPAction';
3905
                    $v = str_replace('"', '', $v);
3906
                    $v = str_replace('\\', '', $v);
3907
                    $this->SOAPAction = $v;
3908
                } else if ($k == 'content-type') {
3909
                    // get the character encoding of the incoming request
3910
                    if (strpos($v, '=')) {
3911
                        $enc = substr(strstr($v, '='), 1);
3912
                        $enc = str_replace('"', '', $enc);
3913
                        $enc = str_replace('\\', '', $enc);
3914
                        if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
3915
                            $this->xml_encoding = strtoupper($enc);
3916
                        } else {
3917
                            $this->xml_encoding = 'US-ASCII';
3918
                        }
3919
                    } else {
3920
                        // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3921
                        $this->xml_encoding = 'ISO-8859-1';
3922
                    }
3923
                }
3924
                $this->headers[$k] = $v;
3925
                $this->request .= "$k: $v\r\n";
3926
                $this->debug("$k: $v");
3927
            }
3928
        } else {
3929
            $this->debug("In parse_http_headers, HTTP headers not accessible");
3930
            $this->setError("HTTP headers not accessible");
3931
        }
3932
    }
3933
3934
    /**
3935
    * parses a request
3936
    *
3937
    * The following fields are set by this function (when successful)
3938
    *
3939
    * headers
3940
    * request
3941
    * xml_encoding
3942
    * SOAPAction
3943
    * request
3944
    * requestSOAP
3945
    * methodURI
3946
    * methodname
3947
    * methodparams
3948
    * requestHeaders
3949
    * document
3950
    *
3951
    * This sets the fault field on error
3952
    *
3953
    * @param    string $data XML string
3954
    * @access   private
3955
    */
3956
    function parse_request($data='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3957
        $this->debug('entering parse_request()');
3958
        $this->parse_http_headers();
3959
        $this->debug('got character encoding: '.$this->xml_encoding);
3960
        // uncompress if necessary
3961
        if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] != '') {
3962
            $this->debug('got content encoding: ' . $this->headers['content-encoding']);
3963
            if ($this->headers['content-encoding'] == 'deflate' || $this->headers['content-encoding'] == 'gzip') {
3964
                // if decoding works, use it. else assume data wasn't gzencoded
3965
                if (function_exists('gzuncompress')) {
3966
                    if ($this->headers['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {
3967
                        $data = $degzdata;
3968
                    } elseif ($this->headers['content-encoding'] == 'gzip' && $degzdata = gzinflate(substr($data, 10))) {
3969
                        $data = $degzdata;
3970
                    } else {
3971
                        $this->fault('SOAP-ENV:Client', 'Errors occurred when trying to decode the data');
3972
3973
                        return;
3974
                    }
3975
                } else {
3976
                    $this->fault('SOAP-ENV:Client', 'This Server does not support compressed data');
3977
3978
                    return;
3979
                }
3980
            }
3981
        }
3982
        $this->request .= "\r\n".$data;
3983
        $data = $this->parseRequest($this->headers, $data);
3984
        $this->requestSOAP = $data;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data can also be of type false. However, the property $requestSOAP is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
3985
        $this->debug('leaving parse_request');
3986
    }
3987
3988
    /**
3989
    * invokes a PHP function for the requested SOAP method
3990
    *
3991
    * The following fields are set by this function (when successful)
3992
    *
3993
    * methodreturn
3994
    *
3995
    * Note that the PHP function that is called may also set the following
3996
    * fields to affect the response sent to the client
3997
    *
3998
    * responseHeaders
3999
    * outgoing_headers
4000
    *
4001
    * This sets the fault field on error
4002
    *
4003
    * @access   private
4004
    */
4005
    function invoke_method() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4006
        $this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
4007
4008
        //
4009
        // if you are debugging in this area of the code, your service uses a class to implement methods,
4010
        // you use SOAP RPC, and the client is .NET, please be aware of the following...
4011
        // when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the
4012
        // method name.  that is fine for naming the .NET methods.  it is not fine for properly constructing
4013
        // the XML request and reading the XML response.  you need to add the RequestElementName and
4014
        // ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe
4015
        // generates for the method.  these parameters are used to specify the correct XML element names
4016
        // for .NET to use, i.e. the names with the '.' in them.
4017
        //
4018
        $orig_methodname = $this->methodname;
4019
        if ($this->wsdl) {
4020
            if ($this->opData = $this->wsdl->getOperationData($this->methodname)) {
4021
                $this->debug('in invoke_method, found WSDL operation=' . $this->methodname);
4022
                $this->appendDebug('opData=' . $this->varDump($this->opData));
0 ignored issues
show
Bug introduced by
The property opData does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
4023
            } elseif ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction)) {
4024
                // Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
4025
                $this->debug('in invoke_method, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
4026
                $this->appendDebug('opData=' . $this->varDump($this->opData));
4027
                $this->methodname = $this->opData['name'];
4028
            } else {
4029
                $this->debug('in invoke_method, no WSDL for operation=' . $this->methodname);
4030
                $this->fault('SOAP-ENV:Client', "Operation '" . $this->methodname . "' is not defined in the WSDL for this service");
4031
4032
                return;
4033
            }
4034
        } else {
4035
            $this->debug('in invoke_method, no WSDL to validate method');
4036
        }
4037
4038
        // if a . is present in $this->methodname, we see if there is a class in scope,
4039
        // which could be referred to. We will also distinguish between two deliminators,
4040
        // to allow methods to be called a the class or an instance
4041
        if (strpos($this->methodname, '..') > 0) {
4042
            $delim = '..';
4043
        } else if (strpos($this->methodname, '.') > 0) {
4044
            $delim = '.';
4045
        } else {
4046
            $delim = '';
4047
        }
4048
        $this->debug("in invoke_method, delim=$delim");
4049
4050
        $class = '';
4051
        $method = '';
4052
        if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
4053
            $try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
4054
            if (class_exists($try_class)) {
4055
                // get the class and method name
4056
                $class = $try_class;
4057
                $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
4058
                $this->debug("in invoke_method, class=$class method=$method delim=$delim");
4059
            } else {
4060
                $this->debug("in invoke_method, class=$try_class not found");
4061
            }
4062
        } else {
4063
            $try_class = '';
4064
            $this->debug("in invoke_method, no class to try");
4065
        }
4066
4067
        // does method exist?
4068
        if ($class == '') {
4069
            if (!function_exists($this->methodname)) {
4070
                $this->debug("in invoke_method, function '$this->methodname' not found!");
4071
                $this->result = 'fault: method not found';
4072
                $this->fault('SOAP-ENV:Client',"method '$this->methodname'('$orig_methodname') not defined in service('$try_class' '$delim')");
4073
4074
                return;
4075
            }
4076
        } else {
4077
            $method_to_compare = (substr(phpversion(), 0, 2) == '4.') ? strtolower($method) : $method;
4078
            if (!in_array($method_to_compare, get_class_methods($class))) {
4079
                $this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!");
4080
                $this->result = 'fault: method not found';
4081
                $this->fault('SOAP-ENV:Client',"method '$this->methodname'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')");
4082
4083
                return;
4084
            }
4085
        }
4086
4087
        // evaluate message, getting back parameters
4088
        // verify that request parameters match the method's signature
4089
        if (! $this->verify_method($this->methodname,$this->methodparams)) {
4090
            // debug
4091
            $this->debug('ERROR: request not verified against method signature');
4092
            $this->result = 'fault: request failed validation against method signature';
4093
            // return fault
4094
            $this->fault('SOAP-ENV:Client',"Operation '$this->methodname' not defined in service.");
4095
4096
            return;
4097
        }
4098
4099
        // if there are parameters to pass
4100
        $this->debug('in invoke_method, params:');
4101
        $this->appendDebug($this->varDump($this->methodparams));
4102
        $this->debug("in invoke_method, calling '$this->methodname'");
4103
        if (!function_exists('call_user_func_array')) {
4104
            if ($class == '') {
4105
                $this->debug('in invoke_method, calling function using eval()');
4106
                $funcCall = "\$this->methodreturn = $this->methodname(";
4107
            } else {
4108
                if ($delim == '..') {
4109
                    $this->debug('in invoke_method, calling class method using eval()');
4110
                    $funcCall = "\$this->methodreturn = ".$class."::".$method."(";
4111
                } else {
4112
                    $this->debug('in invoke_method, calling instance method using eval()');
4113
                    // generate unique instance name
4114
                    $instname = "\$inst_".time();
4115
                    $funcCall = $instname." = new ".$class."(); ";
4116
                    $funcCall .= "\$this->methodreturn = ".$instname."->".$method."(";
4117
                }
4118
            }
4119
            if ($this->methodparams) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->methodparams of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
4120
                foreach ($this->methodparams as $param) {
4121
                    if (is_array($param) || is_object($param)) {
4122
                        $this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available');
4123
4124
                        return;
4125
                    }
4126
                    $funcCall .= "\"$param\",";
4127
                }
4128
                $funcCall = substr($funcCall, 0, -1);
4129
            }
4130
            $funcCall .= ');';
4131
            $this->debug('in invoke_method, function call: '.$funcCall);
4132
            @eval($funcCall);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
4133
        } else {
4134
            if ($class == '') {
4135
                $this->debug('in invoke_method, calling function using call_user_func_array()');
4136
                $call_arg = "$this->methodname";    // straight assignment changes $this->methodname to lower case after call_user_func_array()
4137
            } elseif ($delim == '..') {
4138
                $this->debug('in invoke_method, calling class method using call_user_func_array()');
4139
                $call_arg = array ($class, $method);
4140
            } else {
4141
                $this->debug('in invoke_method, calling instance method using call_user_func_array()');
4142
                $instance = new $class ();
4143
                $call_arg = array(&$instance, $method);
4144
            }
4145
            if (is_array($this->methodparams)) {
4146
                $this->methodreturn = call_user_func_array($call_arg, array_values($this->methodparams));
4147
            } else {
4148
                $this->methodreturn = call_user_func_array($call_arg, array());
4149
            }
4150
        }
4151
        $this->debug('in invoke_method, methodreturn:');
4152
        $this->appendDebug($this->varDump($this->methodreturn));
4153
        $this->debug("in invoke_method, called method $this->methodname, received data of type ".gettype($this->methodreturn));
4154
    }
4155
4156
    /**
4157
    * serializes the return value from a PHP function into a full SOAP Envelope
4158
    *
4159
    * The following fields are set by this function (when successful)
4160
    *
4161
    * responseSOAP
4162
    *
4163
    * This sets the fault field on error
4164
    *
4165
    * @access   private
4166
    */
4167
    function serialize_return() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4168
        $this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4169
        // if fault
4170
        if (isset($this->methodreturn) && is_object($this->methodreturn) && ((get_class($this->methodreturn) == 'soap_fault') || (get_class($this->methodreturn) == 'nusoap_fault'))) {
4171
            $this->debug('got a fault object from method');
4172
            $this->fault = $this->methodreturn;
4173
4174
            return;
4175
        } elseif ($this->methodreturnisliteralxml) {
4176
            $return_val = $this->methodreturn;
4177
        // returned value(s)
4178
        } else {
4179
            $this->debug('got a(n) '.gettype($this->methodreturn).' from method');
4180
            $this->debug('serializing return value');
4181
            if ($this->wsdl) {
4182
                if (sizeof($this->opData['output']['parts']) > 1) {
4183
                    $this->debug('more than one output part, so use the method return unchanged');
4184
                    $opParams = $this->methodreturn;
4185
                } elseif (sizeof($this->opData['output']['parts']) == 1) {
4186
                    $this->debug('exactly one output part, so wrap the method return in a simple array');
4187
                    // TODO: verify that it is not already wrapped!
4188
                    //foreach ($this->opData['output']['parts'] as $name => $type) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4189
                    //	$this->debug('wrap in element named ' . $name);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4190
                    //}
4191
                    $opParams = array($this->methodreturn);
4192
                }
4193
                $return_val = $this->wsdl->serializeRPCParameters($this->methodname,'output',$opParams);
0 ignored issues
show
Bug introduced by
The variable $opParams does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4194
                $this->appendDebug($this->wsdl->getDebug());
4195
                $this->wsdl->clearDebug();
4196
                if ($errstr = $this->wsdl->getError()) {
4197
                    $this->debug('got wsdl error: '.$errstr);
4198
                    $this->fault('SOAP-ENV:Server', 'unable to serialize result');
4199
4200
                    return;
4201
                }
4202
            } else {
4203
                if (isset($this->methodreturn)) {
4204
                    $return_val = $this->serialize_val($this->methodreturn, 'return');
4205
                } else {
4206
                    $return_val = '';
4207
                    $this->debug('in absence of WSDL, assume void return for backward compatibility');
4208
                }
4209
            }
4210
        }
4211
        $this->debug('return value:');
4212
        $this->appendDebug($this->varDump($return_val));
4213
4214
        $this->debug('serializing response');
4215
        if ($this->wsdl) {
4216
            $this->debug('have WSDL for serialization: style is ' . $this->opData['style']);
4217
            if ($this->opData['style'] == 'rpc') {
4218
                $this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']);
4219
                if ($this->opData['output']['use'] == 'literal') {
4220
                    // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
4221 View Code Duplication
                    if ($this->methodURI) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4222
                        $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
4223
                    } else {
4224
                        $payload = '<'.$this->methodname.'Response>'.$return_val.'</'.$this->methodname.'Response>';
4225
                    }
4226 View Code Duplication
                } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4227
                    if ($this->methodURI) {
4228
                        $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
4229
                    } else {
4230
                        $payload = '<'.$this->methodname.'Response>'.$return_val.'</'.$this->methodname.'Response>';
4231
                    }
4232
                }
4233
            } else {
4234
                $this->debug('style is not rpc for serialization: assume document');
4235
                $payload = $return_val;
4236
            }
4237
        } else {
4238
            $this->debug('do not have WSDL for serialization: assume rpc/encoded');
4239
            $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
4240
        }
4241
        $this->result = 'successful';
4242
        if ($this->wsdl) {
4243
            //if ($this->debug_flag) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4244
                $this->appendDebug($this->wsdl->getDebug());
4245
            //	}
4246
            if (isset($this->opData['output']['encodingStyle'])) {
4247
                $encodingStyle = $this->opData['output']['encodingStyle'];
4248
            } else {
4249
                $encodingStyle = '';
4250
            }
4251
            // Added: In case we use a WSDL, return a serialized env. WITH the usedNamespaces.
4252
            $this->responseSOAP = $this->serializeEnvelope($payload,$this->responseHeaders,$this->wsdl->usedNamespaces,$this->opData['style'],$this->opData['output']['use'],$encodingStyle);
4253
        } else {
4254
            $this->responseSOAP = $this->serializeEnvelope($payload,$this->responseHeaders);
4255
        }
4256
        $this->debug("Leaving serialize_return");
4257
    }
4258
4259
    /**
4260
    * sends an HTTP response
4261
    *
4262
    * The following fields are set by this function (when successful)
4263
    *
4264
    * outgoing_headers
4265
    * response
4266
    *
4267
    * @access   private
4268
    */
4269
    function send_response() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4270
        $this->debug('Enter send_response');
4271
        if ($this->fault) {
4272
            $payload = $this->fault->serialize();
4273
            $this->outgoing_headers[] = "HTTP/1.0 500 Internal Server Error";
4274
            $this->outgoing_headers[] = "Status: 500 Internal Server Error";
4275
        } else {
4276
            $payload = $this->responseSOAP;
4277
            // Some combinations of PHP+Web server allow the Status
4278
            // to come through as a header.  Since OK is the default
4279
            // just do nothing.
4280
            // $this->outgoing_headers[] = "HTTP/1.0 200 OK";
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4281
            // $this->outgoing_headers[] = "Status: 200 OK";
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4282
        }
4283
        // add debug data if in debug mode
4284
        if (isset($this->debug_flag) && $this->debug_flag) {
4285
            $payload .= $this->getDebugAsXMLComment();
4286
        }
4287
        $this->outgoing_headers[] = "Server: $this->title Server v$this->version";
4288
        preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
4289
        $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (".$rev[1].")";
4290
        // Let the Web server decide about this
4291
        //$this->outgoing_headers[] = "Connection: Close\r\n";
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4292
        $payload = $this->getHTTPBody($payload);
4293
        $type = $this->getHTTPContentType();
4294
        $charset = $this->getHTTPContentTypeCharset();
4295
        $this->outgoing_headers[] = "Content-Type: $type" . ($charset ? '; charset=' . $charset : '');
4296
        //begin code to compress payload - by John
4297
        // NOTE: there is no way to know whether the Web server will also compress
4298
        // this data.
4299
        if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding'])) {
4300
            if (strstr($this->headers['accept-encoding'], 'gzip')) {
4301 View Code Duplication
                if (function_exists('gzencode')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4302
                    if (isset($this->debug_flag) && $this->debug_flag) {
4303
                        $payload .= "<!-- Content being gzipped -->";
4304
                    }
4305
                    $this->outgoing_headers[] = "Content-Encoding: gzip";
4306
                    $payload = gzencode($payload);
4307
                } else {
4308
                    if (isset($this->debug_flag) && $this->debug_flag) {
4309
                        $payload .= "<!-- Content will not be gzipped: no gzencode -->";
4310
                    }
4311
                }
4312
            } elseif (strstr($this->headers['accept-encoding'], 'deflate')) {
4313
                // Note: MSIE requires gzdeflate output (no Zlib header and checksum),
4314
                // instead of gzcompress output,
4315
                // which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
4316 View Code Duplication
                if (function_exists('gzdeflate')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4317
                    if (isset($this->debug_flag) && $this->debug_flag) {
4318
                        $payload .= "<!-- Content being deflated -->";
4319
                    }
4320
                    $this->outgoing_headers[] = "Content-Encoding: deflate";
4321
                    $payload = gzdeflate($payload);
4322
                } else {
4323
                    if (isset($this->debug_flag) && $this->debug_flag) {
4324
                        $payload .= "<!-- Content will not be deflated: no gzcompress -->";
4325
                    }
4326
                }
4327
            }
4328
        }
4329
        //end code
4330
        $this->outgoing_headers[] = "Content-Length: ".strlen($payload);
4331
        reset($this->outgoing_headers);
4332
        foreach ($this->outgoing_headers as $hdr) {
4333
            header($hdr, false);
4334
        }
4335
        print $payload;
4336
        $this->response = join("\r\n",$this->outgoing_headers)."\r\n\r\n".$payload;
4337
    }
4338
4339
    /**
4340
    * takes the value that was created by parsing the request
4341
    * and compares to the method's signature, if available.
4342
    *
4343
    * @param	string	$operation	The operation to be invoked
4344
    * @param	array	$request	The array of parameter values
4345
    * @return	boolean	Whether the operation was found
4346
    * @access   private
4347
    */
4348
    function verify_method($operation,$request){
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4349
        if (isset($this->wsdl) && is_object($this->wsdl)) {
4350
            if ($this->wsdl->getOperationData($operation)) {
4351
                return true;
4352
            }
4353
        } elseif (isset($this->operations[$operation])) {
4354
            return true;
4355
        }
4356
4357
        return false;
4358
    }
4359
4360
    /**
4361
    * processes SOAP message received from client
4362
    *
4363
    * @param	array	$headers	The HTTP headers
4364
    * @param	string	$data		unprocessed request data from client
4365
    * @return	mixed	value of the message, decoded into a PHP type
4366
    * @access   private
4367
    */
4368
    function parseRequest($headers, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4369
        $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:');
4370
        $this->appendDebug($this->varDump($headers));
4371
        if (!isset($headers['content-type'])) {
4372
            $this->setError('Request not of type text/xml (no content-type header)');
4373
4374
            return false;
4375
        }
4376
        if (!strstr($headers['content-type'], 'text/xml')) {
4377
            $this->setError('Request not of type text/xml');
4378
4379
            return false;
4380
        }
4381 View Code Duplication
        if (strpos($headers['content-type'], '=')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4382
            $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
4383
            $this->debug('Got response encoding: ' . $enc);
4384
            if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
4385
                $this->xml_encoding = strtoupper($enc);
4386
            } else {
4387
                $this->xml_encoding = 'US-ASCII';
4388
            }
4389
        } else {
4390
            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
4391
            $this->xml_encoding = 'ISO-8859-1';
4392
        }
4393
        $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
4394
        // parse response, get soap parser obj
4395
        $parser = new nusoap_parser($data,$this->xml_encoding,'',$this->decode_utf8);
4396
        // parser debug
4397
        $this->debug("parser debug: \n".$parser->getDebug());
4398
        // if fault occurred during message parsing
4399
        if ($err = $parser->getError()) {
4400
            $this->result = 'fault: error in msg parsing: '.$err;
4401
            $this->fault('SOAP-ENV:Client',"error in msg parsing:\n".$err);
4402
        // else successfully parsed request into soapval object
4403
        } else {
4404
            // get/set methodname
4405
            $this->methodURI = $parser->root_struct_namespace;
4406
            $this->methodname = $parser->root_struct_name;
4407
            $this->debug('methodname: '.$this->methodname.' methodURI: '.$this->methodURI);
4408
            $this->debug('calling parser->get_soapbody()');
4409
            $this->methodparams = $parser->get_soapbody();
0 ignored issues
show
Documentation Bug introduced by
It seems like $parser->get_soapbody() of type * is incompatible with the declared type array of property $methodparams.

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...
4410
            // get SOAP headers
4411
            $this->requestHeaders = $parser->getHeaders();
4412
            // get SOAP Header
4413
            $this->requestHeader = $parser->get_soapheader();
4414
            // add document for doclit support
4415
            $this->document = $parser->document;
4416
        }
4417
     }
4418
4419
    /**
4420
    * gets the HTTP body for the current response.
4421
    *
4422
    * @param string $soapmsg The SOAP payload
4423
    * @return string The HTTP body, which includes the SOAP payload
4424
    * @access private
4425
    */
4426
    function getHTTPBody($soapmsg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4427
        return $soapmsg;
4428
    }
4429
4430
    /**
4431
    * gets the HTTP content type for the current response.
4432
    *
4433
    * Note: getHTTPBody must be called before this.
4434
    *
4435
    * @return string the HTTP content type for the current response.
4436
    * @access private
4437
    */
4438
    function getHTTPContentType() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4439
        return 'text/xml';
4440
    }
4441
4442
    /**
4443
    * gets the HTTP content type charset for the current response.
4444
    * returns false for non-text content types.
4445
    *
4446
    * Note: getHTTPBody must be called before this.
4447
    *
4448
    * @return string the HTTP content type charset for the current response.
4449
    * @access private
4450
    */
4451
    function getHTTPContentTypeCharset() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4452
        return $this->soap_defencoding;
4453
    }
4454
4455
    /**
4456
    * add a method to the dispatch map (this has been replaced by the register method)
4457
    *
4458
    * @param    string $methodname
4459
    * @param    string $in array of input values
4460
    * @param    string $out array of output values
4461
    * @access   public
4462
    * @deprecated
4463
    */
4464
    function add_to_map($methodname,$in,$out){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4465
            $this->operations[$methodname] = array('name' => $methodname,'in' => $in,'out' => $out);
4466
    }
4467
4468
    /**
4469
    * register a service function with the server
4470
    *
4471
    * @param    string $name the name of the PHP function, class.method or class..method
4472
    * @param    array $in assoc array of input values: key = param name, value = param type
4473
    * @param    array $out assoc array of output values: key = param name, value = param type
4474
    * @param	mixed $namespace the element namespace for the method or false
4475
    * @param	mixed $soapaction the soapaction for the method or false
4476
    * @param	mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
4477
    * @param	mixed $use optional (encoded|literal) or false
4478
    * @param	string $documentation optional Description to include in WSDL
4479
    * @param	string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
4480
    * @access   public
4481
    */
4482
    function register($name,$in=array(),$out=array(),$namespace=false,$soapaction=false,$style=false,$use=false,$documentation='',$encodingStyle=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
register uses the super-global variable $HTTP_SERVER_VARS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
register uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
4483
        global $HTTP_SERVER_VARS;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
4484
4485
        if ($this->externalWSDLURL) {
4486
            die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.');
0 ignored issues
show
Coding Style Compatibility introduced by
The method register() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
4487
        }
4488
        if (! $name) {
4489
            die('You must specify a name when you register an operation');
0 ignored issues
show
Coding Style Compatibility introduced by
The method register() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
4490
        }
4491
        if (!is_array($in)) {
4492
            die('You must provide an array for operation inputs');
0 ignored issues
show
Coding Style Compatibility introduced by
The method register() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
4493
        }
4494
        if (!is_array($out)) {
4495
            die('You must provide an array for operation outputs');
0 ignored issues
show
Coding Style Compatibility introduced by
The method register() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
4496
        }
4497
        if (false == $namespace) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
4498
        }
4499
        if (false == $soapaction) {
4500
            if (isset($_SERVER)) {
4501
                $SERVER_NAME = $_SERVER['SERVER_NAME'];
4502
                $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
4503
                $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4504 View Code Duplication
            } elseif (isset($HTTP_SERVER_VARS)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4505
                $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4506
                $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
4507
                $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4508
            } else {
4509
                $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
4510
            }
4511
            if ($HTTPS == '1' || $HTTPS == 'on') {
0 ignored issues
show
Bug introduced by
The variable $HTTPS does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4512
                $SCHEME = 'https';
4513
            } else {
4514
                $SCHEME = 'http';
4515
            }
4516
            $soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name";
0 ignored issues
show
Bug introduced by
The variable $SERVER_NAME does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $SCRIPT_NAME does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4517
        }
4518
        if (false == $style) {
4519
            $style = "rpc";
4520
        }
4521
        if (false == $use) {
4522
            $use = "encoded";
4523
        }
4524
        if ($use == 'encoded' && $encodingStyle == '') {
4525
            $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
4526
        }
4527
4528
        $this->operations[$name] = array(
4529
        'name' => $name,
4530
        'in' => $in,
4531
        'out' => $out,
4532
        'namespace' => $namespace,
4533
        'soapaction' => $soapaction,
4534
        'style' => $style);
4535
        if ($this->wsdl) {
4536
            $this->wsdl->addOperation($name,$in,$out,$namespace,$soapaction,$style,$use,$documentation,$encodingStyle);
4537
        }
4538
4539
        return true;
4540
    }
4541
4542
    /**
4543
    * Specify a fault to be returned to the client.
4544
    * This also acts as a flag to the server that a fault has occured.
4545
    *
4546
    * @param	string $faultcode
4547
    * @param	string $faultstring
4548
    * @param	string $faultactor
4549
    * @param	string $faultdetail
4550
    * @access   public
4551
    */
4552
    function fault($faultcode,$faultstring,$faultactor='',$faultdetail=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4553
        if ($faultdetail == '' && $this->debug_flag) {
4554
            $faultdetail = $this->getDebug();
4555
        }
4556
        $this->fault = new nusoap_fault($faultcode,$faultactor,$faultstring,$faultdetail);
4557
        $this->fault->soap_defencoding = $this->soap_defencoding;
4558
    }
4559
4560
    /**
4561
    * Sets up wsdl object.
4562
    * Acts as a flag to enable internal WSDL generation
4563
    *
4564
    * @param string $serviceName, name of the service
0 ignored issues
show
Documentation introduced by
There is no parameter named $serviceName,. Did you maybe mean $serviceName?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
4565
    * @param mixed $namespace optional 'tns' service namespace or false
4566
    * @param mixed $endpoint optional URL of service endpoint or false
4567
    * @param string $style optional (rpc|document) WSDL style (also specified by operation)
4568
    * @param string $transport optional SOAP transport
4569
    * @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
4570
    */
4571
    function configureWSDL($serviceName,$namespace = false,$endpoint = false,$style='rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
configureWSDL uses the super-global variable $HTTP_SERVER_VARS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
configureWSDL uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
4572
    {
4573
        global $HTTP_SERVER_VARS;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
4574
4575
        if (isset($_SERVER)) {
4576
            $SERVER_NAME = $_SERVER['SERVER_NAME'];
4577
            $SERVER_PORT = $_SERVER['SERVER_PORT'];
4578
            $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
4579
            $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4580 View Code Duplication
        } elseif (isset($HTTP_SERVER_VARS)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4581
            $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4582
            $SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
4583
            $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
4584
            $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4585
        } else {
4586
            $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
4587
        }
4588
        // If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI)
4589
        $colon = strpos($SERVER_NAME,":");
0 ignored issues
show
Bug introduced by
The variable $SERVER_NAME does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4590
        if ($colon) {
4591
            $SERVER_NAME = substr($SERVER_NAME, 0, $colon);
4592
        }
4593
        if ($SERVER_PORT == 80) {
4594
            $SERVER_PORT = '';
4595
        } else {
4596
            $SERVER_PORT = ':' . $SERVER_PORT;
0 ignored issues
show
Bug introduced by
The variable $SERVER_PORT does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4597
        }
4598
        if (false == $namespace) {
4599
            $namespace = "http://$SERVER_NAME/soap/$serviceName";
4600
        }
4601
4602
        if (false == $endpoint) {
4603
            if ($HTTPS == '1' || $HTTPS == 'on') {
0 ignored issues
show
Bug introduced by
The variable $HTTPS does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4604
                $SCHEME = 'https';
4605
            } else {
4606
                $SCHEME = 'http';
4607
            }
4608
            $endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME";
0 ignored issues
show
Bug introduced by
The variable $SCRIPT_NAME does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4609
        }
4610
4611
        if (false == $schemaTargetNamespace) {
4612
            $schemaTargetNamespace = $namespace;
4613
        }
4614
4615
        $this->wsdl = new wsdl;
4616
        $this->wsdl->serviceName = $serviceName;
0 ignored issues
show
Bug introduced by
The property serviceName does not seem to exist in wsdl.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
4617
        $this->wsdl->endpoint = $endpoint;
4618
        $this->wsdl->namespaces['tns'] = $namespace;
4619
        $this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
4620
        $this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
4621
        if ($schemaTargetNamespace != $namespace) {
4622
            $this->wsdl->namespaces['types'] = $schemaTargetNamespace;
4623
        }
4624
        $this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces);
4625
        if ($style == 'document') {
4626
            $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified';
4627
        }
4628
        $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace;
4629
        $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = array('location' => '', 'loaded' => true);
4630
        $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = array('location' => '', 'loaded' => true);
4631
        $this->wsdl->bindings[$serviceName.'Binding'] = array(
4632
            'name'=>$serviceName.'Binding',
4633
            'style'=>$style,
4634
            'transport'=>$transport,
4635
            'portType'=>$serviceName.'PortType');
4636
        $this->wsdl->ports[$serviceName.'Port'] = array(
4637
            'binding'=>$serviceName.'Binding',
4638
            'location'=>$endpoint,
4639
            'bindingType'=>'http://schemas.xmlsoap.org/wsdl/soap/');
4640
    }
4641
}
4642
4643
/**
4644
 * Backward compatibility
4645
 */
4646
class soap_server extends nusoap_server {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4647
}
4648
4649
?><?php
4650
4651
/**
4652
* parses a WSDL file, allows access to it's data, other utility methods.
4653
* also builds WSDL structures programmatically.
4654
*
4655
* @author   Dietrich Ayala <[email protected]>
4656
* @author   Scott Nichol <[email protected]>
4657
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
4658
* @access public
4659
*/
4660
class wsdl extends nusoap_base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4661
    // URL or filename of the root of this WSDL
4662
    var $wsdl;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $wsdl.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4663
    // define internal arrays of bindings, ports, operations, messages, etc.
4664
    var $schemas = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $schemas.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4665
    var $currentSchema;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentSchema.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4666
    var $message = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $message.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4667
    var $complexTypes = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $complexTypes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4668
    var $messages = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $messages.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4669
    var $currentMessage;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentMessage.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4670
    var $currentOperation;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentOperation.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4671
    var $portTypes = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $portTypes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4672
    var $currentPortType;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentPortType.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4673
    var $bindings = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $bindings.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4674
    var $currentBinding;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentBinding.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4675
    var $ports = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $ports.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4676
    var $currentPort;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $currentPort.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4677
    var $opData = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $opData.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4678
    var $status = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $status.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4679
    var $documentation = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $documentation.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4680
    var $endpoint = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $endpoint.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4681
    // array of wsdl docs to import
4682
    var $import = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $import.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4683
    // parser vars
4684
    var $parser;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $parser.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4685
    var $position = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $position.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4686
    var $depth = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $depth.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4687
    var $depth_array = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $depth_array.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4688
    // for getting wsdl
4689
    var $proxyhost = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxyhost.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4690
    var $proxyport = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxyport.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4691
    var $proxyusername = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxyusername.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4692
    var $proxypassword = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxypassword.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4693
    var $timeout = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $timeout.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4694
    var $response_timeout = 30;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $response_timeout.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4695
    var $curl_options = array();    // User-specified cURL options
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $curl_options.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4696
    var $use_curl = false;            // whether to always try to use cURL
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $use_curl.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4697
    // for HTTP authentication
4698
    var $username = '';                // Username for HTTP authentication
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $username.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4699
    var $password = '';                // Password for HTTP authentication
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $password.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4700
    var $authtype = '';                // Type of HTTP authentication
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $authtype.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4701
    var $certRequest = array();        // Certificate for HTTP SSL authentication
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $certRequest.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
4702
4703
    /**
4704
     * constructor
4705
     *
4706
     * @param string  $wsdl             WSDL document URL
4707
     * @param string  $proxyhost
0 ignored issues
show
Documentation introduced by
Should the type for parameter $proxyhost not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
4708
     * @param string  $proxyport
0 ignored issues
show
Documentation introduced by
Should the type for parameter $proxyport not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
4709
     * @param string  $proxyusername
0 ignored issues
show
Documentation introduced by
Should the type for parameter $proxyusername not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
4710
     * @param string  $proxypassword
0 ignored issues
show
Documentation introduced by
Should the type for parameter $proxypassword not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
4711
     * @param integer $timeout          set the connection timeout
4712
     * @param integer $response_timeout set the response timeout
4713
     * @param array   $curl_options     user-specified cURL options
0 ignored issues
show
Documentation introduced by
Should the type for parameter $curl_options not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
4714
     * @param boolean $use_curl         try to use cURL
4715
     * @access public
4716
     */
4717
    function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
4718
        parent::nusoap_base();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (nusoap_base() instead of wsdl()). Are you sure this is correct? If so, you might want to change this to $this->nusoap_base().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Coding Style introduced by
PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead
Loading history...
4719
        $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
4720
        $this->proxyhost = $proxyhost;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxyhost can also be of type false. However, the property $proxyhost is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
4721
        $this->proxyport = $proxyport;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxyport can also be of type false. However, the property $proxyport is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
4722
        $this->proxyusername = $proxyusername;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxyusername can also be of type false. However, the property $proxyusername is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
4723
        $this->proxypassword = $proxypassword;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxypassword can also be of type false. However, the property $proxypassword is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
4724
        $this->timeout = $timeout;
4725
        $this->response_timeout = $response_timeout;
4726
        if (is_array($curl_options))
4727
            $this->curl_options = $curl_options;
4728
        $this->use_curl = $use_curl;
4729
        $this->fetchWSDL($wsdl);
4730
    }
4731
4732
    /**
4733
     * fetches the WSDL document and parses it
4734
     *
4735
     * @access public
4736
     */
4737
    function fetchWSDL($wsdl) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4738
        $this->debug("parse and process WSDL path=$wsdl");
4739
        $this->wsdl = $wsdl;
4740
        // parse wsdl file
4741
        if ($this->wsdl != "") {
4742
            $this->parseWSDL($this->wsdl);
4743
        }
4744
        // imports
4745
        // TODO: handle imports more properly, grabbing them in-line and nesting them
4746
        $imported_urls = array();
4747
        $imported = 1;
4748
        while ($imported > 0) {
4749
            $imported = 0;
4750
            // Schema imports
4751
            foreach ($this->schemas as $ns => $list) {
4752
                foreach ($list as $xs) {
4753
                    $wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4754 View Code Duplication
                    foreach ($xs->imports as $ns2 => $list2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4755
                        for ($ii = 0; $ii < count($list2); $ii++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
4756
                            if (! $list2[$ii]['loaded']) {
4757
                                $this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
4758
                                $url = $list2[$ii]['location'];
4759
                                if ($url != '') {
4760
                                    $urlparts = parse_url($url);
4761
                                    if (!isset($urlparts['host'])) {
4762
                                        $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' .$wsdlparts['port'] : '') .
4763
                                                substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
4764
                                    }
4765
                                    if (! in_array($url, $imported_urls)) {
4766
                                        $this->parseWSDL($url);
4767
                                        $imported++;
4768
                                        $imported_urls[] = $url;
4769
                                    }
4770
                                } else {
4771
                                    $this->debug("Unexpected scenario: empty URL for unloaded import");
4772
                                }
4773
                            }
4774
                        }
4775
                    }
4776
                }
4777
            }
4778
            // WSDL imports
4779
            $wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4780 View Code Duplication
            foreach ($this->import as $ns => $list) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4781
                for ($ii = 0; $ii < count($list); $ii++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
4782
                    if (! $list[$ii]['loaded']) {
4783
                        $this->import[$ns][$ii]['loaded'] = true;
4784
                        $url = $list[$ii]['location'];
4785
                        if ($url != '') {
4786
                            $urlparts = parse_url($url);
4787
                            if (!isset($urlparts['host'])) {
4788
                                $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4789
                                        substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
4790
                            }
4791
                            if (! in_array($url, $imported_urls)) {
4792
                                $this->parseWSDL($url);
4793
                                $imported++;
4794
                                $imported_urls[] = $url;
4795
                            }
4796
                        } else {
4797
                            $this->debug("Unexpected scenario: empty URL for unloaded import");
4798
                        }
4799
                    }
4800
                }
4801
            }
4802
        }
4803
        // add new data to operation data
4804
        foreach ($this->bindings as $binding => $bindingData) {
4805
            if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
4806
                foreach ($bindingData['operations'] as $operation => $data) {
4807
                    $this->debug('post-parse data gathering for ' . $operation);
4808
                    $this->bindings[$binding]['operations'][$operation]['input'] =
4809
                        isset($this->bindings[$binding]['operations'][$operation]['input']) ?
4810
                        array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) :
4811
                        $this->portTypes[ $bindingData['portType'] ][$operation]['input'];
4812
                    $this->bindings[$binding]['operations'][$operation]['output'] =
4813
                        isset($this->bindings[$binding]['operations'][$operation]['output']) ?
4814
                        array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) :
4815
                        $this->portTypes[ $bindingData['portType'] ][$operation]['output'];
4816 View Code Duplication
                    if (isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4817
                        $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ];
4818
                    }
4819 View Code Duplication
                    if (isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4820
                           $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ];
4821
                    }
4822
                    // Set operation style if necessary, but do not override one already provided
4823
                    if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
4824
                        $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
4825
                    }
4826
                    $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
4827
                    $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : '';
4828
                    $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
4829
                }
4830
            }
4831
        }
4832
    }
4833
4834
    /**
4835
     * parses the wsdl document
4836
     *
4837
     * @param string $wsdl path or URL
4838
     * @access private
4839
     */
4840
    function parseWSDL($wsdl = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4841
        $this->debug("parse WSDL at path=$wsdl");
4842
4843
        if ($wsdl == '') {
4844
            $this->debug('no wsdl passed to parseWSDL()!!');
4845
            $this->setError('no wsdl passed to parseWSDL()!!');
4846
4847
            return false;
4848
        }
4849
4850
        // parse $wsdl for url format
4851
        $wsdl_props = parse_url($wsdl);
4852
4853
        if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
4854
            $this->debug('getting WSDL http(s) URL ' . $wsdl);
4855
            // get wsdl
4856
            $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
4857
            $tr->request_method = 'GET';
4858
            $tr->useSOAPAction = false;
4859 View Code Duplication
            if ($this->proxyhost && $this->proxyport) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4860
                $tr->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
4861
            }
4862 View Code Duplication
            if ($this->authtype != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4863
                $tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
4864
            }
4865
            $tr->setEncoding('gzip, deflate');
4866
            $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
4867
            //$this->debug("WSDL request\n" . $tr->outgoing_payload);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4868
            //$this->debug("WSDL response\n" . $tr->incoming_payload);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4869
            $this->appendDebug($tr->getDebug());
4870
            // catch errors
4871
            if ($err = $tr->getError() ) {
4872
                $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err;
4873
                $this->debug($errstr);
4874
                $this->setError($errstr);
4875
                unset($tr);
4876
4877
                return false;
4878
            }
4879
            unset($tr);
4880
            $this->debug("got WSDL URL");
4881
        } else {
4882
            // $wsdl is not http(s), so treat it as a file URL or plain file path
4883
            if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) {
4884
                $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
4885
            } else {
4886
                $path = $wsdl;
4887
            }
4888
            $this->debug('getting WSDL file ' . $path);
4889
            if ($fp = @fopen($path, 'r')) {
4890
                $wsdl_string = '';
4891
                while ($data = fread($fp, 32768)) {
4892
                    $wsdl_string .= $data;
4893
                }
4894
                fclose($fp);
4895
            } else {
4896
                $errstr = "Bad path to WSDL file $path";
4897
                $this->debug($errstr);
4898
                $this->setError($errstr);
4899
4900
                return false;
4901
            }
4902
        }
4903
        $this->debug('Parse WSDL');
4904
        // end new code added
4905
        // Create an XML parser.
4906
        $this->parser = xml_parser_create();
4907
        // Set the options for parsing the XML data.
4908
        // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4909
        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
4910
        // Set the object for the parser.
4911
        xml_set_object($this->parser, $this);
4912
        // Set the element handlers for the parser.
4913
        xml_set_element_handler($this->parser, 'start_element', 'end_element');
4914
        xml_set_character_data_handler($this->parser, 'character_data');
4915
        // Parse the XML file.
4916 View Code Duplication
        if (!xml_parse($this->parser, $wsdl_string, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4917
            // Display an error message.
4918
            $errstr = sprintf(
4919
                'XML error parsing WSDL from %s on line %d: %s',
4920
                $wsdl,
4921
                xml_get_current_line_number($this->parser),
4922
                xml_error_string(xml_get_error_code($this->parser))
4923
                );
4924
            $this->debug($errstr);
4925
            $this->debug("XML payload:\n" . $wsdl_string);
4926
            $this->setError($errstr);
4927
4928
            return false;
4929
        }
4930
        // free the parser
4931
        xml_parser_free($this->parser);
4932
        $this->debug('Parsing WSDL done');
4933
        // catch wsdl parse errors
4934
        if ($this->getError()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getError() of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
4935
            return false;
4936
        }
4937
4938
        return true;
4939
    }
4940
4941
    /**
4942
     * start-element handler
4943
     *
4944
     * @param string $parser XML parser object
4945
     * @param string $name   element name
4946
     * @param string $attrs  associative array of attributes
4947
     * @access private
4948
     */
4949
    function start_element($parser, $name, $attrs)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
4950
    {
4951
        if ($this->status == 'schema') {
4952
            $this->currentSchema->schemaStartElement($parser, $name, $attrs);
4953
            $this->appendDebug($this->currentSchema->getDebug());
4954
            $this->currentSchema->clearDebug();
4955
        } elseif (preg_match('/schema$/', $name)) {
4956
            $this->debug('Parsing WSDL schema');
4957
            // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4958
            $this->status = 'schema';
4959
            $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
4960
            $this->currentSchema->schemaStartElement($parser, $name, $attrs);
4961
            $this->appendDebug($this->currentSchema->getDebug());
4962
            $this->currentSchema->clearDebug();
4963
        } else {
4964
            // position in the total number of elements, starting from 0
4965
            $pos = $this->position++;
4966
            $depth = $this->depth++;
4967
            // set self as current value for this depth
4968
            $this->depth_array[$depth] = $pos;
4969
            $this->message[$pos] = array('cdata' => '');
4970
            // process attributes
4971
            if (count($attrs) > 0) {
4972
                // register namespace declarations
4973
                foreach ($attrs as $k => $v) {
0 ignored issues
show
Bug introduced by
The expression $attrs of type string is not traversable.
Loading history...
4974
                    if (preg_match('/^xmlns/',$k)) {
4975
                        if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
4976
                            $this->namespaces[$ns_prefix] = $v;
4977
                        } else {
4978
                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
4979
                        }
4980 View Code Duplication
                        if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4981
                            $this->XMLSchemaVersion = $v;
4982
                            $this->namespaces['xsi'] = $v . '-instance';
4983
                        }
4984
                    }
4985
                }
4986
                // expand each attribute prefix to its namespace
4987
                foreach ($attrs as $k => $v) {
0 ignored issues
show
Bug introduced by
The expression $attrs of type string is not traversable.
Loading history...
4988
                    $k = strpos($k, ':') ? $this->expandQname($k) : $k;
4989
                    if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
4990
                        $v = strpos($v, ':') ? $this->expandQname($v) : $v;
4991
                    }
4992
                    $eAttrs[$k] = $v;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$eAttrs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $eAttrs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
4993
                }
4994
                $attrs = $eAttrs;
0 ignored issues
show
Bug introduced by
The variable $eAttrs does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4995
            } else {
4996
                $attrs = array();
4997
            }
4998
            // get element prefix, namespace and name
4999
            if (preg_match('/:/', $name)) {
5000
                // get ns prefix
5001
                $prefix = substr($name, 0, strpos($name, ':'));
5002
                // get ns
5003
                $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';
5004
                // get unqualified name
5005
                $name = substr(strstr($name, ':'), 1);
5006
            }
5007
            // process attributes, expanding any prefixes to namespaces
5008
            // find status, register data
5009
            switch ($this->status) {
5010
                case 'message':
5011
                    if ($name == 'part') {
5012 View Code Duplication
                        if (isset($attrs['type'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5013
                            $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
5014
                            $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
5015
                        }
5016 View Code Duplication
                        if (isset($attrs['element'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5017
                            $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
5018
                            $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
5019
                        }
5020
                    }
5021
                    break;
5022
                case 'portType':
5023
                    switch ($name) {
5024
                        case 'operation':
5025
                            $this->currentPortOperation = $attrs['name'];
0 ignored issues
show
Bug introduced by
The property currentPortOperation does not seem to exist. Did you mean currentPort?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5026
                            $this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
0 ignored issues
show
Bug introduced by
The property currentPortOperation does not seem to exist. Did you mean currentPort?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5027
                            if (isset($attrs['parameterOrder'])) {
5028
                                $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
5029
                            }
5030
                            break;
5031
                        case 'documentation':
5032
                            $this->documentation = true;
5033
                            break;
5034
                        // merge input/output data
5035
                        default:
5036
                            $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
5037
                            $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
0 ignored issues
show
Bug introduced by
The property currentPortOperation does not seem to exist. Did you mean currentPort?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5038
                            break;
5039
                    }
5040
                    break;
5041
                case 'binding':
5042
                    switch ($name) {
5043
                        case 'binding':
5044
                            // get ns prefix
5045
                            if (isset($attrs['style'])) {
5046
                            $this->bindings[$this->currentBinding]['prefix'] = $prefix;
0 ignored issues
show
Bug introduced by
The variable $prefix does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
5047
                            }
5048
                            $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
5049
                            break;
5050
                        case 'header':
5051
                            $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
0 ignored issues
show
Bug introduced by
The property opStatus does not seem to exist. Did you mean status?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5052
                            break;
5053
                        case 'operation':
5054 View Code Duplication
                            if (isset($attrs['soapAction'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5055
                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
5056
                            }
5057 View Code Duplication
                            if (isset($attrs['style'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5058
                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
5059
                            }
5060
                            if (isset($attrs['name'])) {
5061
                                $this->currentOperation = $attrs['name'];
5062
                                $this->debug("current binding operation: $this->currentOperation");
5063
                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
5064
                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
5065
                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
5066
                            }
5067
                            break;
5068
                        case 'input':
5069
                            $this->opStatus = 'input';
0 ignored issues
show
Bug introduced by
The property opStatus does not seem to exist. Did you mean status?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5070
                            break;
5071
                        case 'output':
5072
                            $this->opStatus = 'output';
0 ignored issues
show
Bug introduced by
The property opStatus does not seem to exist. Did you mean status?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5073
                            break;
5074
                        case 'body':
5075
                            if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
0 ignored issues
show
Bug introduced by
The property opStatus does not seem to exist. Did you mean status?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5076
                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
0 ignored issues
show
Bug introduced by
The property opStatus does not seem to exist. Did you mean status?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5077
                            } else {
5078
                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
0 ignored issues
show
Bug introduced by
The property opStatus does not seem to exist. Did you mean status?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5079
                            }
5080
                            break;
5081
                    }
5082
                    break;
5083
                case 'service':
5084
                    switch ($name) {
5085
                        case 'port':
5086
                            $this->currentPort = $attrs['name'];
5087
                            $this->debug('current port: ' . $this->currentPort);
5088
                            $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
5089
5090
                            break;
5091
                        case 'address':
5092
                            $this->ports[$this->currentPort]['location'] = $attrs['location'];
5093
                            $this->ports[$this->currentPort]['bindingType'] = $namespace;
0 ignored issues
show
Bug introduced by
The variable $namespace does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
5094
                            $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace;
5095
                            $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location'];
5096
                            break;
5097
                    }
5098
                    break;
5099
            }
5100
        // set status
5101
        switch ($name) {
5102
            case 'import':
5103
                if (isset($attrs['location'])) {
5104
                    $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
5105
                    $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')');
5106
                } else {
5107
                    $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
5108 View Code Duplication
                    if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5109
                        $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
5110
                    }
5111
                    $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')');
5112
                }
5113
                break;
5114
            //wait for schema
5115
            //case 'types':
5116
            //	$this->status = 'schema';
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5117
            //	break;
5118
            case 'message':
5119
                $this->status = 'message';
5120
                $this->messages[$attrs['name']] = array();
5121
                $this->currentMessage = $attrs['name'];
5122
                break;
5123
            case 'portType':
5124
                $this->status = 'portType';
5125
                $this->portTypes[$attrs['name']] = array();
5126
                $this->currentPortType = $attrs['name'];
5127
                break;
5128
            case "binding":
5129
                if (isset($attrs['name'])) {
5130
                // get binding name
5131
                    if (strpos($attrs['name'], ':')) {
5132
                        $this->currentBinding = $this->getLocalPart($attrs['name']);
5133
                    } else {
5134
                        $this->currentBinding = $attrs['name'];
5135
                    }
5136
                    $this->status = 'binding';
5137
                    $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
5138
                    $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
5139
                }
5140
                break;
5141
            case 'service':
5142
                $this->serviceName = $attrs['name'];
0 ignored issues
show
Bug introduced by
The property serviceName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
5143
                $this->status = 'service';
5144
                $this->debug('current service: ' . $this->serviceName);
5145
                break;
5146
            case 'definitions':
5147
                foreach ($attrs as $name => $value) {
5148
                    $this->wsdl_info[$name] = $value;
0 ignored issues
show
Bug introduced by
The property wsdl_info does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
5149
                }
5150
                break;
5151
            }
5152
        }
5153
    }
5154
5155
    /**
5156
    * end-element handler
5157
    *
5158
    * @param string $parser XML parser object
5159
    * @param string $name element name
5160
    * @access private
5161
    */
5162
    function end_element($parser, $name){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5163
        // unset schema status
5164
        if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5165
            $this->status = "";
5166
            $this->appendDebug($this->currentSchema->getDebug());
5167
            $this->currentSchema->clearDebug();
5168
            $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
5169
            $this->debug('Parsing WSDL schema done');
5170
        }
5171
        if ($this->status == 'schema') {
5172
            $this->currentSchema->schemaEndElement($parser, $name);
5173
        } else {
5174
            // bring depth down a notch
5175
            $this->depth--;
5176
        }
5177
        // end documentation
5178
        if ($this->documentation) {
5179
            //TODO: track the node to which documentation should be assigned; it can be a part, message, etc.
5180
            //$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5181
            $this->documentation = false;
5182
        }
5183
    }
5184
5185
    /**
5186
     * element content handler
5187
     *
5188
     * @param string $parser XML parser object
5189
     * @param string $data   element content
5190
     * @access private
5191
     */
5192
    function character_data($parser, $data)
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5193
    {
5194
        $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
5195 View Code Duplication
        if (isset($this->message[$pos]['cdata'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5196
            $this->message[$pos]['cdata'] .= $data;
5197
        }
5198
        if ($this->documentation) {
5199
            $this->documentation .= $data;
5200
        }
5201
    }
5202
5203
    /**
5204
    * if authenticating, set user credentials here
5205
    *
5206
    * @param    string $username
5207
    * @param    string $password
5208
    * @param	string $authtype (basic|digest|certificate|ntlm)
5209
    * @param	array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
5210
    * @access   public
5211
    */
5212 View Code Duplication
    function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5213
        $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
5214
        $this->appendDebug($this->varDump($certRequest));
5215
        $this->username = $username;
5216
        $this->password = $password;
5217
        $this->authtype = $authtype;
5218
        $this->certRequest = $certRequest;
5219
    }
5220
5221
    function getBindingData($binding)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5222
    {
5223
        if (is_array($this->bindings[$binding])) {
5224
            return $this->bindings[$binding];
5225
        }
5226
    }
5227
5228
    /**
5229
     * returns an assoc array of operation names => operation data
5230
     *
5231
     * @param  string $portName    WSDL port name
5232
     * @param  string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported)
5233
     * @return array
5234
     * @access public
5235
     */
5236
    function getOperations($portName = '', $bindingType = 'soap') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5237
        $ops = array();
5238
        if ($bindingType == 'soap') {
5239
            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5240
        } elseif ($bindingType == 'soap12') {
5241
            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5242
        } else {
5243
            $this->debug("getOperations bindingType $bindingType may not be supported");
5244
        }
5245
        $this->debug("getOperations for port '$portName' bindingType $bindingType");
5246
        // loop thru ports
5247
        foreach ($this->ports as $port => $portData) {
5248
            $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
5249
            if ($portName == '' || $port == $portName) {
5250
                // binding type of port matches parameter
5251
                if ($portData['bindingType'] == $bindingType) {
5252
                    $this->debug("getOperations found port $port bindingType $bindingType");
5253
                    //$this->debug("port data: " . $this->varDump($portData));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5254
                    //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5255
                    // merge bindings
5256
                    if (isset($this->bindings[ $portData['binding'] ]['operations'])) {
5257
                        $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']);
5258
                    }
5259
                }
5260
            }
5261
        }
5262
        if (count($ops) == 0) {
5263
            $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType");
5264
        }
5265
5266
        return $ops;
5267
    }
5268
5269
    /**
5270
     * returns an associative array of data necessary for calling an operation
5271
     *
5272
     * @param  string $operation   name of operation
5273
     * @param  string $bindingType type of binding eg: soap, soap12
5274
     * @return array
5275
     * @access public
5276
     */
5277
    function getOperationData($operation, $bindingType = 'soap')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5278
    {
5279
        if ($bindingType == 'soap') {
5280
            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5281
        } elseif ($bindingType == 'soap12') {
5282
            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5283
        }
5284
        // loop thru ports
5285
        foreach ($this->ports as $port => $portData) {
5286
            // binding type of port matches parameter
5287
            if ($portData['bindingType'] == $bindingType) {
5288
                // get binding
5289
                //foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5290
                foreach (array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) {
5291
                    // note that we could/should also check the namespace here
5292
                    if ($operation == $bOperation) {
5293
                        $opData = $this->bindings[ $portData['binding'] ]['operations'][$operation];
5294
5295
                        return $opData;
5296
                    }
5297
                }
5298
            }
5299
        }
5300
    }
5301
5302
    /**
5303
     * returns an associative array of data necessary for calling an operation
5304
     *
5305
     * @param  string $soapAction  soapAction for operation
5306
     * @param  string $bindingType type of binding eg: soap, soap12
5307
     * @return array
5308
     * @access public
5309
     */
5310
    function getOperationDataForSoapAction($soapAction, $bindingType = 'soap') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5311
        if ($bindingType == 'soap') {
5312
            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5313
        } elseif ($bindingType == 'soap12') {
5314
            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5315
        }
5316
        // loop thru ports
5317
        foreach ($this->ports as $port => $portData) {
5318
            // binding type of port matches parameter
5319
            if ($portData['bindingType'] == $bindingType) {
5320
                // loop through operations for the binding
5321
                foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
5322
                    if ($opData['soapAction'] == $soapAction) {
5323
                        return $opData;
5324
                    }
5325
                }
5326
            }
5327
        }
5328
    }
5329
5330
    /**
5331
    * returns an array of information about a given type
5332
    * returns false if no type exists by the given name
5333
    *
5334
    *	 typeDef = array(
5335
    *	 'elements' => array(), // refs to elements array
5336
    *	'restrictionBase' => '',
5337
    *	'phpType' => '',
5338
    *	'order' => '(sequence|all)',
5339
    *	'attrs' => array() // refs to attributes array
5340
    *	)
5341
    *
5342
    * @param string $type the type
5343
    * @param string $ns namespace (not prefix) of the type
5344
    * @return mixed
5345
    * @access public
5346
    * @see nusoap_xmlschema
5347
    */
5348
    function getTypeDef($type, $ns) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5349
        $this->debug("in getTypeDef: type=$type, ns=$ns");
5350
        if ((! $ns) && isset($this->namespaces['tns'])) {
5351
            $ns = $this->namespaces['tns'];
5352
            $this->debug("in getTypeDef: type namespace forced to $ns");
5353
        }
5354
        if (!isset($this->schemas[$ns])) {
5355
            foreach ($this->schemas as $ns0 => $schema0) {
5356
                if (strcasecmp($ns, $ns0) == 0) {
5357
                    $this->debug("in getTypeDef: replacing schema namespace $ns with $ns0");
5358
                    $ns = $ns0;
5359
                    break;
5360
                }
5361
            }
5362
        }
5363
        if (isset($this->schemas[$ns])) {
5364
            $this->debug("in getTypeDef: have schema for namespace $ns");
5365
            for ($i = 0; $i < count($this->schemas[$ns]); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
5366
                $xs = &$this->schemas[$ns][$i];
5367
                $t = $xs->getTypeDef($type);
5368
                $this->appendDebug($xs->getDebug());
5369
                $xs->clearDebug();
5370
                if ($t) {
5371
                    $this->debug("in getTypeDef: found type $type");
5372
                    if (!isset($t['phpType'])) {
5373
                        // get info for type to tack onto the element
5374
                        $uqType = substr($t['type'], strrpos($t['type'], ':') + 1);
5375
                        $ns = substr($t['type'], 0, strrpos($t['type'], ':'));
5376
                        $etype = $this->getTypeDef($uqType, $ns);
5377
                        if ($etype) {
5378
                            $this->debug("found type for [element] $type:");
5379
                            $this->debug($this->varDump($etype));
5380
                            if (isset($etype['phpType'])) {
5381
                                $t['phpType'] = $etype['phpType'];
5382
                            }
5383
                            if (isset($etype['elements'])) {
5384
                                $t['elements'] = $etype['elements'];
5385
                            }
5386
                            if (isset($etype['attrs'])) {
5387
                                $t['attrs'] = $etype['attrs'];
5388
                            }
5389
                        } else {
5390
                            $this->debug("did not find type for [element] $type");
5391
                        }
5392
                    }
5393
5394
                    return $t;
5395
                }
5396
            }
5397
            $this->debug("in getTypeDef: did not find type $type");
5398
        } else {
5399
            $this->debug("in getTypeDef: do not have schema for namespace $ns");
5400
        }
5401
5402
        return false;
5403
    }
5404
5405
    /**
5406
    * prints html description of services
5407
    *
5408
    * @access private
5409
    */
5410
    function webDescription(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
webDescription uses the super-global variable $HTTP_SERVER_VARS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
webDescription uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
5411
        global $HTTP_SERVER_VARS;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
5412
5413
        if (isset($_SERVER)) {
5414
            $PHP_SELF = $_SERVER['PHP_SELF'];
5415
        } elseif (isset($HTTP_SERVER_VARS)) {
5416
            $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
5417
        } else {
5418
            $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
5419
        }
5420
5421
        $b = '
5422
        <html><head><title>NuSOAP: '.$this->serviceName.'</title>
5423
        <style type="text/css">
5424
            body    { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; }
5425
            p       { font-family: arial; color: #000000; margin-top: 0px; margin-bottom: 12px; }
5426
            pre { background-color: silver; padding: 5px; font-family: Courier New; font-size: x-small; color: #000000;}
5427
            ul      { margin-top: 10px; margin-left: 20px; }
5428
            li      { list-style-type: none; margin-top: 10px; color: #000000; }
5429
            .content{
5430
            margin-left: 0px; padding-bottom: 2em; }
5431
            .nav {
5432
            padding-top: 10px; padding-bottom: 10px; padding-left: 15px; font-size: .70em;
5433
            margin-top: 10px; margin-left: 0px; color: #000000;
5434
            background-color: #ccccff; width: 20%; margin-left: 20px; margin-top: 20px; }
5435
            .title {
5436
            font-family: arial; font-size: 26px; color: #ffffff;
5437
            background-color: #999999; width: 100%;
5438
            margin-left: 0px; margin-right: 0px;
5439
            padding-top: 10px; padding-bottom: 10px;}
5440
            .hidden {
5441
            position: absolute; visibility: hidden; z-index: 200; left: 250px; top: 100px;
5442
            font-family: arial; overflow: hidden; width: 600;
5443
            padding: 20px; font-size: 10px; background-color: #999999;
5444
            layer-background-color:#FFFFFF; }
5445
            a,a:active  { color: charcoal; font-weight: bold; }
5446
            a:visited   { color: #666666; font-weight: bold; }
5447
            a:hover     { color: cc3300; font-weight: bold; }
5448
        </style>
5449
        <script language="JavaScript" type="text/javascript">
5450
        <!--
5451
        // POP-UP CAPTIONS...
5452
        function lib_bwcheck(){ //Browsercheck (needed)
5453
            this.ver=navigator.appVersion
5454
            this.agent=navigator.userAgent
5455
            this.dom=document.getElementById?1:0
5456
            this.opera5=this.agent.indexOf("Opera 5")>-1
5457
            this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
5458
            this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
5459
            this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
5460
            this.ie=this.ie4||this.ie5||this.ie6
5461
            this.mac=this.agent.indexOf("Mac")>-1
5462
            this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
5463
            this.ns4=(document.layers && !this.dom)?1:0;
5464
            this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
5465
5466
            return this
5467
        }
5468
        var bw = new lib_bwcheck()
5469
        //Makes crossbrowser object.
5470
        function makeObj(obj){
5471
            this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
5472
            if(!this.evnt) return false
5473
            this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0;
5474
            this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0;
5475
            this.writeIt=b_writeIt;
5476
5477
            return this
5478
        }
5479
        // A unit of measure that will be added when setting the position of a layer.
5480
        //var px = bw.ns4||window.opera?"":"px";
5481
        function b_writeIt(text){
5482
            if (bw.ns4) {this.wref.write(text);this.wref.close()}
5483
            else this.wref.innerHTML = text
5484
        }
5485
        //Shows the messages
5486
        var oDesc;
5487
        function popup(divid){
5488
            if (oDesc = new makeObj(divid)) {
5489
            oDesc.css.visibility = "visible"
5490
            }
5491
        }
5492
        function popout(){ // Hides message
5493
            if(oDesc) oDesc.css.visibility = "hidden"
5494
        }
5495
        //-->
5496
        </script>
5497
        </head>
5498
        <body>
5499
        <div class=content>
5500
            <br><br>
5501
            <div class=title>'.$this->serviceName.'</div>
5502
            <div class=nav>
5503
                <p>View the <a href="'.$PHP_SELF.'?wsdl">WSDL</a> for the service.
0 ignored issues
show
Bug introduced by
The variable $PHP_SELF does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
5504
                Click on an operation name to view it&apos;s details.</p>
5505
                <ul>';
5506
                foreach ($this->getOperations() as $op => $data) {
5507
                    $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
5508
                    // create hidden div
5509
                    $b .= "<div id='$op' class='hidden'>
5510
                    <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>";
5511
                    foreach ($data as $donnie => $marie) { // loop through opdata
5512
                        if ($donnie == 'input' || $donnie == 'output') { // show input/output data
5513
                            $b .= "<font color='white'>".ucfirst($donnie).':</font><br>';
5514
                            foreach ($marie as $captain => $tenille) { // loop through data
5515
                                if ($captain == 'parts') { // loop thru parts
5516
                                    $b .= "&nbsp;&nbsp;$captain:<br>";
5517
                                    //if (is_array($tenille)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5518
                                        foreach ($tenille as $joanie => $chachi) {
5519
                                            $b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
5520
                                        }
5521
                                    //}
5522
                                } else {
5523
                                    $b .= "&nbsp;&nbsp;$captain: $tenille<br>";
5524
                                }
5525
                            }
5526
                        } else {
5527
                            $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>";
5528
                        }
5529
                    }
5530
                    $b .= '</div>';
5531
                }
5532
                $b .= '
5533
                <ul>
5534
            </div>
5535
        </div></body></html>';
5536
5537
        return $b;
5538
    }
5539
5540
    /**
5541
    * serialize the parsed wsdl
5542
    *
5543
    * @param mixed $debug whether to put debug=1 in endpoint URL
5544
    * @return string serialization of WSDL
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
5545
    * @access public
5546
    */
5547
    function serialize($debug = 0)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5548
    {
5549
        $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
5550
        $xml .= "\n<definitions";
5551
        foreach ($this->namespaces as $k => $v) {
5552
            $xml .= " xmlns:$k=\"$v\"";
5553
        }
5554
        // 10.9.02 - add poulter fix for wsdl and tns declarations
5555 View Code Duplication
        if (isset($this->namespaces['wsdl'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5556
            $xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\"";
5557
        }
5558 View Code Duplication
        if (isset($this->namespaces['tns'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5559
            $xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\"";
5560
        }
5561
        $xml .= '>';
5562
        // imports
5563 View Code Duplication
        if (sizeof($this->import) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5564
            foreach ($this->import as $ns => $list) {
5565
                foreach ($list as $ii) {
5566
                    if ($ii['location'] != '') {
5567
                        $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
5568
                    } else {
5569
                        $xml .= '<import namespace="' . $ns . '" />';
5570
                    }
5571
                }
5572
            }
5573
        }
5574
        // types
5575
        if (count($this->schemas)>=1) {
5576
            $xml .= "\n<types>\n";
5577
            foreach ($this->schemas as $ns => $list) {
5578
                foreach ($list as $xs) {
5579
                    $xml .= $xs->serializeSchema();
5580
                }
5581
            }
5582
            $xml .= '</types>';
5583
        }
5584
        // messages
5585
        if (count($this->messages) >= 1) {
5586
            foreach ($this->messages as $msgName => $msgParts) {
5587
                $xml .= "\n<message name=\"" . $msgName . '">';
5588
                if (is_array($msgParts)) {
5589
                    foreach ($msgParts as $partName => $partType) {
5590
                        // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5591
                        if (strpos($partType, ':')) {
5592
                            $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
0 ignored issues
show
Security Bug introduced by
It seems like $this->getPrefix($partType) targeting nusoap_base::getPrefix() can also be of type false; however, nusoap_base::getPrefixFromNamespace() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
5593
                        } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
5594
                            // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5595
                            $typePrefix = 'xsd';
5596
                        } else {
5597
                            foreach ($this->typemap as $ns => $types) {
5598
                                if (isset($types[$partType])) {
5599
                                    $typePrefix = $this->getPrefixFromNamespace($ns);
5600
                                }
5601
                            }
5602
                            if (!isset($typePrefix)) {
5603
                                die("$partType has no namespace!");
0 ignored issues
show
Coding Style Compatibility introduced by
The method serialize() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
5604
                            }
5605
                        }
5606
                        $ns = $this->getNamespaceFromPrefix($typePrefix);
5607
                        $localPart = $this->getLocalPart($partType);
5608
                        $typeDef = $this->getTypeDef($localPart, $ns);
5609
                        if ($typeDef['typeClass'] == 'element') {
5610
                            $elementortype = 'element';
5611
                            if (substr($localPart, -1) == '^') {
5612
                                $localPart = substr($localPart, 0, -1);
5613
                            }
5614
                        } else {
5615
                            $elementortype = 'type';
5616
                        }
5617
                        $xml .= "\n" . '  <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />';
5618
                    }
5619
                }
5620
                $xml .= '</message>';
5621
            }
5622
        }
5623
        // bindings & porttypes
5624
        if (count($this->bindings) >= 1) {
5625
            $binding_xml = '';
5626
            $portType_xml = '';
5627
            foreach ($this->bindings as $bindingName => $attrs) {
5628
                $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
5629
                $binding_xml .= "\n" . '  <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
5630
                $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
5631
                foreach ($attrs['operations'] as $opName => $opParts) {
5632
                    $binding_xml .= "\n" . '  <operation name="' . $opName . '">';
5633
                    $binding_xml .= "\n" . '    <soap:operation soapAction="' . $opParts['soapAction'] . '" style="'. $opParts['style'] . '"/>';
5634 View Code Duplication
                    if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5635
                        $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
5636
                    } else {
5637
                        $enc_style = '';
5638
                    }
5639
                    $binding_xml .= "\n" . '    <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
5640 View Code Duplication
                    if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5641
                        $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
5642
                    } else {
5643
                        $enc_style = '';
5644
                    }
5645
                    $binding_xml .= "\n" . '    <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
5646
                    $binding_xml .= "\n" . '  </operation>';
5647
                    $portType_xml .= "\n" . '  <operation name="' . $opParts['name'] . '"';
5648
                    if (isset($opParts['parameterOrder'])) {
5649
                        $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
5650
                    }
5651
                    $portType_xml .= '>';
5652
                    if (isset($opParts['documentation']) && $opParts['documentation'] != '') {
5653
                        $portType_xml .= "\n" . '    <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
5654
                    }
5655
                    $portType_xml .= "\n" . '    <input message="tns:' . $opParts['input']['message'] . '"/>';
5656
                    $portType_xml .= "\n" . '    <output message="tns:' . $opParts['output']['message'] . '"/>';
5657
                    $portType_xml .= "\n" . '  </operation>';
5658
                }
5659
                $portType_xml .= "\n" . '</portType>';
5660
                $binding_xml .= "\n" . '</binding>';
5661
            }
5662
            $xml .= $portType_xml . $binding_xml;
5663
        }
5664
        // services
5665
        $xml .= "\n<service name=\"" . $this->serviceName . '">';
5666
        if (count($this->ports) >= 1) {
5667
            foreach ($this->ports as $pName => $attrs) {
5668
                $xml .= "\n" . '  <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
5669
                $xml .= "\n" . '    <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
5670
                $xml .= "\n" . '  </port>';
5671
            }
5672
        }
5673
        $xml .= "\n" . '</service>';
5674
5675
        return $xml . "\n</definitions>";
5676
    }
5677
5678
    /**
5679
     * determine whether a set of parameters are unwrapped
5680
     * when they are expect to be wrapped, Microsoft-style.
5681
     *
5682
     * @param  string  $type       the type (element name) of the wrapper
5683
     * @param  array   $parameters the parameter values for the SOAP call
5684
     * @return boolean whether they parameters are unwrapped (and should be wrapped)
5685
     * @access private
5686
     */
5687
    function parametersMatchWrapped($type, &$parameters) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5688
        $this->debug("in parametersMatchWrapped type=$type, parameters=");
5689
        $this->appendDebug($this->varDump($parameters));
5690
5691
        // split type into namespace:unqualified-type
5692
        if (strpos($type, ':')) {
5693
            $uqType = substr($type, strrpos($type, ':') + 1);
5694
            $ns = substr($type, 0, strrpos($type, ':'));
5695
            $this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns");
5696
            if ($this->getNamespaceFromPrefix($ns)) {
5697
                $ns = $this->getNamespaceFromPrefix($ns);
5698
                $this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns");
5699
            }
5700
        } else {
5701
            // TODO: should the type be compared to types in XSD, and the namespace
5702
            // set to XSD if the type matches?
5703
            $this->debug("in parametersMatchWrapped: No namespace for type $type");
5704
            $ns = '';
5705
            $uqType = $type;
5706
        }
5707
5708
        // get the type information
5709
        if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
5710
            $this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type.");
5711
5712
            return false;
5713
        }
5714
        $this->debug("in parametersMatchWrapped: found typeDef=");
5715
        $this->appendDebug($this->varDump($typeDef));
5716 View Code Duplication
        if (substr($uqType, -1) == '^') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5717
            $uqType = substr($uqType, 0, -1);
5718
        }
5719
        $phpType = $typeDef['phpType'];
5720
        $arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '');
5721
        $this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType");
5722
5723
        // we expect a complexType or element of complexType
5724
        if ($phpType != 'struct') {
5725
            $this->debug("in parametersMatchWrapped: not a struct");
5726
5727
            return false;
5728
        }
5729
5730
        // see whether the parameter names match the elements
5731
        if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
5732
            $elements = 0;
5733
            $matches = 0;
5734
            foreach ($typeDef['elements'] as $name => $attrs) {
5735
                if (isset($parameters[$name])) {
5736
                    $this->debug("in parametersMatchWrapped: have parameter named $name");
5737
                    $matches++;
5738
                } else {
5739
                    $this->debug("in parametersMatchWrapped: do not have parameter named $name");
5740
                }
5741
                $elements++;
5742
            }
5743
5744
            $this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names");
5745
            if ($matches == 0) {
5746
                return false;
5747
            }
5748
5749
            return true;
5750
        }
5751
5752
        // since there are no elements for the type, if the user passed no
5753
        // parameters, the parameters match wrapped.
5754
        $this->debug("in parametersMatchWrapped: no elements type $ns:$uqType");
5755
5756
        return count($parameters) == 0;
5757
    }
5758
5759
    /**
5760
     * serialize PHP values according to a WSDL message definition
5761
     * contrary to the method name, this is not limited to RPC
5762
     *
5763
     * TODO
5764
     * - multi-ref serialization
5765
     * - validate PHP values against type definitions, return errors if invalid
5766
     *
5767
     * @param  string $operation   operation name
5768
     * @param  string $direction   (input|output)
5769
     * @param  mixed  $parameters  parameter value(s)
5770
     * @param  string $bindingType (soap|soap12)
5771
     * @return mixed  parameters serialized as XML or false on error (e.g. operation not found)
5772
     * @access public
5773
     */
5774
    function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5775
        $this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType");
5776
        $this->appendDebug('parameters=' . $this->varDump($parameters));
5777
5778 View Code Duplication
        if ($direction != 'input' && $direction != 'output') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5779
            $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5780
            $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5781
5782
            return false;
5783
        }
5784
        if (!$opData = $this->getOperationData($operation, $bindingType)) {
5785
            $this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5786
            $this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5787
5788
            return false;
5789
        }
5790
        $this->debug('in serializeRPCParameters: opData:');
5791
        $this->appendDebug($this->varDump($opData));
5792
5793
        // Get encoding style for output and set to current
5794
        $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5795 View Code Duplication
        if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5796
            $encodingStyle = $opData['output']['encodingStyle'];
5797
            $enc_style = $encodingStyle;
0 ignored issues
show
Unused Code introduced by
$enc_style is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
5798
        }
5799
5800
        // set input params
5801
        $xml = '';
5802
        if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
5803
            $parts = &$opData[$direction]['parts'];
5804
            $part_count = sizeof($parts);
5805
            $style = $opData['style'];
5806
            $use = $opData[$direction]['use'];
5807
            $this->debug("have $part_count part(s) to serialize using $style/$use");
5808
            if (is_array($parameters)) {
5809
                $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
5810
                $parameter_count = count($parameters);
5811
                $this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize");
5812
                // check for Microsoft-style wrapped parameters
5813
                if ($style == 'document' && $use == 'literal' && $part_count == 1 && isset($parts['parameters'])) {
5814
                    $this->debug('check whether the caller has wrapped the parameters');
5815
                    if ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1) {
5816
                        // TODO: consider checking here for double-wrapping, when
5817
                        // service function wraps, then NuSOAP wraps again
5818
                        $this->debug("change simple array to associative with 'parameters' element");
5819
                        $parameters['parameters'] = $parameters[0];
5820
                        unset($parameters[0]);
5821
                    }
5822
                    if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) {
5823
                        $this->debug('check whether caller\'s parameters match the wrapped ones');
5824
                        if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) {
5825
                            $this->debug('wrap the parameters for the caller');
5826
                            $parameters = array('parameters' => $parameters);
5827
                            $parameter_count = 1;
0 ignored issues
show
Unused Code introduced by
$parameter_count is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
5828
                        }
5829
                    }
5830
                }
5831
                foreach ($parts as $name => $type) {
5832
                    $this->debug("serializing part $name of type $type");
5833
                    // Track encoding style
5834 View Code Duplication
                    if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5835
                        $encodingStyle = $opData[$direction]['encodingStyle'];
5836
                        $enc_style = $encodingStyle;
5837
                    } else {
5838
                        $enc_style = false;
5839
                    }
5840
                    // NOTE: add error handling here
5841
                    // if serializeType returns false, then catch global error and fault
5842 View Code Duplication
                    if ($parametersArrayType == 'arraySimple') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5843
                        $p = array_shift($parameters);
5844
                        $this->debug('calling serializeType w/indexed param');
5845
                        $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
5846
                    } elseif (isset($parameters[$name])) {
5847
                        $this->debug('calling serializeType w/named param');
5848
                        $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
5849
                    } else {
5850
                        // TODO: only send nillable
5851
                        $this->debug('calling serializeType w/null param');
5852
                        $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
5853
                    }
5854
                }
5855
            } else {
5856
                $this->debug('no parameters passed.');
5857
            }
5858
        }
5859
        $this->debug("serializeRPCParameters returning: $xml");
5860
5861
        return $xml;
5862
    }
5863
5864
    /**
5865
     * serialize a PHP value according to a WSDL message definition
5866
     *
5867
     * TODO
5868
     * - multi-ref serialization
5869
     * - validate PHP values against type definitions, return errors if invalid
5870
     *
5871
     * @param  string $operation  operation name
5872
     * @param  string $direction  (input|output)
5873
     * @param  mixed  $parameters parameter value(s)
5874
     * @return mixed  parameters serialized as XML or false on error (e.g. operation not found)
5875
     * @access public
5876
     * @deprecated
5877
     */
5878
    function serializeParameters($operation, $direction, $parameters)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5879
    {
5880
        $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion");
5881
        $this->appendDebug('parameters=' . $this->varDump($parameters));
5882
5883 View Code Duplication
        if ($direction != 'input' && $direction != 'output') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5884
            $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5885
            $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5886
5887
            return false;
5888
        }
5889
        if (!$opData = $this->getOperationData($operation)) {
5890
            $this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
5891
            $this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
5892
5893
            return false;
5894
        }
5895
        $this->debug('opData:');
5896
        $this->appendDebug($this->varDump($opData));
5897
5898
        // Get encoding style for output and set to current
5899
        $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5900 View Code Duplication
        if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5901
            $encodingStyle = $opData['output']['encodingStyle'];
5902
            $enc_style = $encodingStyle;
0 ignored issues
show
Unused Code introduced by
$enc_style is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
5903
        }
5904
5905
        // set input params
5906
        $xml = '';
5907
        if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
5908
5909
            $use = $opData[$direction]['use'];
5910
            $this->debug("use=$use");
5911
            $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
5912
            if (is_array($parameters)) {
5913
                $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
5914
                $this->debug('have ' . $parametersArrayType . ' parameters');
5915
                foreach ($opData[$direction]['parts'] as $name => $type) {
5916
                    $this->debug('serializing part "'.$name.'" of type "'.$type.'"');
5917
                    // Track encoding style
5918 View Code Duplication
                    if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5919
                        $encodingStyle = $opData[$direction]['encodingStyle'];
5920
                        $enc_style = $encodingStyle;
5921
                    } else {
5922
                        $enc_style = false;
5923
                    }
5924
                    // NOTE: add error handling here
5925
                    // if serializeType returns false, then catch global error and fault
5926 View Code Duplication
                    if ($parametersArrayType == 'arraySimple') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5927
                        $p = array_shift($parameters);
5928
                        $this->debug('calling serializeType w/indexed param');
5929
                        $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
5930
                    } elseif (isset($parameters[$name])) {
5931
                        $this->debug('calling serializeType w/named param');
5932
                        $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
5933
                    } else {
5934
                        // TODO: only send nillable
5935
                        $this->debug('calling serializeType w/null param');
5936
                        $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
5937
                    }
5938
                }
5939
            } else {
5940
                $this->debug('no parameters passed.');
5941
            }
5942
        }
5943
        $this->debug("serializeParameters returning: $xml");
5944
5945
        return $xml;
5946
    }
5947
5948
    /**
5949
     * serializes a PHP value according a given type definition
5950
     *
5951
     * @param  string  $name          name of value (part or element)
5952
     * @param  string  $type          XML schema type of value (type or element)
5953
     * @param  mixed   $value         a native PHP value (parameter value)
5954
     * @param  string  $use           use for part (encoded|literal)
5955
     * @param  string  $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $encodingStyle not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
5956
     * @param  boolean $unqualified   a kludge for what should be XML namespace form handling
5957
     * @return string  value serialized as an XML string
5958
     * @access private
5959
     */
5960
    function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false, $unqualified=false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5961
    {
5962
        $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified"));
5963
        $this->appendDebug("value=" . $this->varDump($value));
5964
        if ($use == 'encoded' && $encodingStyle) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $encodingStyle of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
5965
            $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
5966
        }
5967
5968
        // if a soapval has been supplied, let its type override the WSDL
5969
        if (is_object($value) && get_class($value) == 'soapval') {
5970
            if ($value->type_ns) {
5971
                $type = $value->type_ns . ':' . $value->type;
5972
                $forceType = true;
5973
                $this->debug("in serializeType: soapval overrides type to $type");
5974
            } elseif ($value->type) {
5975
                $type = $value->type;
5976
                $forceType = true;
5977
                $this->debug("in serializeType: soapval overrides type to $type");
5978
            } else {
5979
                $forceType = false;
5980
                $this->debug("in serializeType: soapval does not override type");
5981
            }
5982
            $attrs = $value->attributes;
5983
            $value = $value->value;
5984
            $this->debug("in serializeType: soapval overrides value to $value");
5985
            if ($attrs) {
5986
                if (!is_array($value)) {
5987
                    $value['!'] = $value;
5988
                }
5989
                foreach ($attrs as $n => $v) {
5990
                    $value['!' . $n] = $v;
5991
                }
5992
                $this->debug("in serializeType: soapval provides attributes");
5993
            }
5994
        } else {
5995
            $forceType = false;
5996
        }
5997
5998
        $xml = '';
5999
        if (strpos($type, ':')) {
6000
            $uqType = substr($type, strrpos($type, ':') + 1);
6001
            $ns = substr($type, 0, strrpos($type, ':'));
6002
            $this->debug("in serializeType: got a prefixed type: $uqType, $ns");
6003
            if ($this->getNamespaceFromPrefix($ns)) {
6004
                $ns = $this->getNamespaceFromPrefix($ns);
6005
                $this->debug("in serializeType: expanded prefixed type: $uqType, $ns");
6006
            }
6007
6008
            if ($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/') {
6009
                $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type');
6010
                if ($unqualified && $use == 'literal') {
6011
                    $elementNS = " xmlns=\"\"";
6012
                } else {
6013
                    $elementNS = '';
6014
                }
6015 View Code Duplication
                if (is_null($value)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6016
                    if ($use == 'literal') {
6017
                        // TODO: depends on minOccurs
6018
                        $xml = "<$name$elementNS/>";
6019
                    } else {
6020
                        // TODO: depends on nillable, which should be checked before calling this method
6021
                        $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6022
                    }
6023
                    $this->debug("in serializeType: returning: $xml");
6024
6025
                    return $xml;
6026
                }
6027
                if ($uqType == 'Array') {
6028
                    // JBoss/Axis does this sometimes
6029
                    return $this->serialize_val($value, $name, false, false, false, false, $use);
6030
                }
6031
                if ($uqType == 'boolean') {
6032
                    if ((is_string($value) && $value == 'false') || (! $value)) {
6033
                        $value = 'false';
6034
                    } else {
6035
                        $value = 'true';
6036
                    }
6037
                }
6038
                if ($uqType == 'string' && gettype($value) == 'string') {
6039
                    $value = $this->expandEntities($value);
6040
                }
6041
                if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') {
6042
                    $value = sprintf("%.0lf", $value);
6043
                }
6044
                // it's a scalar
6045
                // TODO: what about null/nil values?
6046
                // check type isn't a custom type extending xmlschema namespace
6047
                if (!$this->getTypeDef($uqType, $ns)) {
6048
                    if ($use == 'literal') {
6049
                        if ($forceType) {
6050
                            $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6051
                        } else {
6052
                            $xml = "<$name$elementNS>$value</$name>";
6053
                        }
6054
                    } else {
6055
                        $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6056
                    }
6057
                    $this->debug("in serializeType: returning: $xml");
6058
6059
                    return $xml;
6060
                }
6061
                $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)');
6062
            } else if ($ns == 'http://xml.apache.org/xml-soap') {
6063
                $this->debug('in serializeType: appears to be Apache SOAP type');
6064
                if ($uqType == 'Map') {
6065
                    $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6066
                    if (! $tt_prefix) {
6067
                        $this->debug('in serializeType: Add namespace for Apache SOAP type');
6068
                        $tt_prefix = 'ns' . rand(1000, 9999);
6069
                        $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap';
6070
                        // force this to be added to usedNamespaces
6071
                        $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6072
                    }
6073
                    $contents = '';
6074
                    foreach ($value as $k => $v) {
6075
                        $this->debug("serializing map element: key $k, value $v");
6076
                        $contents .= '<item>';
6077
                        $contents .= $this->serialize_val($k,'key',false,false,false,false,$use);
6078
                        $contents .= $this->serialize_val($v,'value',false,false,false,false,$use);
6079
                        $contents .= '</item>';
6080
                    }
6081 View Code Duplication
                    if ($use == 'literal') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6082
                        if ($forceType) {
6083
                            $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>";
6084
                        } else {
6085
                            $xml = "<$name>$contents</$name>";
6086
                        }
6087
                    } else {
6088
                        $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>";
6089
                    }
6090
                    $this->debug("in serializeType: returning: $xml");
6091
6092
                    return $xml;
6093
                }
6094
                $this->debug('in serializeType: Apache SOAP type, but only support Map');
6095
            }
6096
        } else {
6097
            // TODO: should the type be compared to types in XSD, and the namespace
6098
            // set to XSD if the type matches?
6099
            $this->debug("in serializeType: No namespace for type $type");
6100
            $ns = '';
6101
            $uqType = $type;
6102
        }
6103
        if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
6104
            $this->setError("$type ($uqType) is not a supported type.");
6105
            $this->debug("in serializeType: $type ($uqType) is not a supported type.");
6106
6107
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by wsdl::serializeType of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
6108
        } else {
6109
            $this->debug("in serializeType: found typeDef");
6110
            $this->appendDebug('typeDef=' . $this->varDump($typeDef));
6111 View Code Duplication
            if (substr($uqType, -1) == '^') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6112
                $uqType = substr($uqType, 0, -1);
6113
            }
6114
        }
6115
        if (!isset($typeDef['phpType'])) {
6116
            $this->setError("$type ($uqType) has no phpType.");
6117
            $this->debug("in serializeType: $type ($uqType) has no phpType.");
6118
6119
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by wsdl::serializeType of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
6120
        }
6121
        $phpType = $typeDef['phpType'];
6122
        $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') );
6123
        // if php type == struct, map value to the <all> element names
6124
        if ($phpType == 'struct') {
6125
            if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
6126
                $elementName = $uqType;
6127 View Code Duplication
                if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6128
                    $elementNS = " xmlns=\"$ns\"";
6129
                } else {
6130
                    $elementNS = " xmlns=\"\"";
6131
                }
6132
            } else {
6133
                $elementName = $name;
6134
                if ($unqualified) {
6135
                    $elementNS = " xmlns=\"\"";
6136
                } else {
6137
                    $elementNS = '';
6138
                }
6139
            }
6140 View Code Duplication
            if (is_null($value)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6141
                if ($use == 'literal') {
6142
                    // TODO: depends on minOccurs and nillable
6143
                    $xml = "<$elementName$elementNS/>";
6144
                } else {
6145
                    $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6146
                }
6147
                $this->debug("in serializeType: returning: $xml");
6148
6149
                return $xml;
6150
            }
6151
            if (is_object($value)) {
6152
                $value = get_object_vars($value);
6153
            }
6154
            if (is_array($value)) {
6155
                $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
6156 View Code Duplication
                if ($use == 'literal') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6157
                    if ($forceType) {
6158
                        $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
6159
                    } else {
6160
                        $xml = "<$elementName$elementNS$elementAttrs>";
6161
                    }
6162
                } else {
6163
                    $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
6164
                }
6165
6166
                if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') {
6167
                    if (isset($value['!'])) {
6168
                        $xml .= $value['!'];
6169
                        $this->debug("in serializeType: serialized simpleContent for type $type");
6170
                    } else {
6171
                        $this->debug("in serializeType: no simpleContent to serialize for type $type");
6172
                    }
6173
                } else {
6174
                    // complexContent
6175
                    $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
6176
                }
6177
                $xml .= "</$elementName>";
6178
            } else {
6179
                $this->debug("in serializeType: phpType is struct, but value is not an array");
6180
                $this->setError("phpType is struct, but value is not an array: see debug output for details");
6181
                $xml = '';
6182
            }
6183
        } elseif ($phpType == 'array') {
6184 View Code Duplication
            if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6185
                $elementNS = " xmlns=\"$ns\"";
6186
            } else {
6187
                if ($unqualified) {
6188
                    $elementNS = " xmlns=\"\"";
6189
                } else {
6190
                    $elementNS = '';
6191
                }
6192
            }
6193
            if (is_null($value)) {
6194 View Code Duplication
                if ($use == 'literal') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6195
                    // TODO: depends on minOccurs
6196
                    $xml = "<$name$elementNS/>";
6197
                } else {
6198
                    $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" .
6199
                        $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
6200
                        ":Array\" " .
6201
                        $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
6202
                        ':arrayType="' .
6203
                        $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) .
0 ignored issues
show
Security Bug introduced by
It seems like $this->getPrefix($typeDef['arrayType']) targeting nusoap_base::getPrefix() can also be of type false; however, nusoap_base::getPrefixFromNamespace() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
6204
                        ':' .
6205
                        $this->getLocalPart($typeDef['arrayType'])."[0]\"/>";
6206
                }
6207
                $this->debug("in serializeType: returning: $xml");
6208
6209
                return $xml;
6210
            }
6211
            if (isset($typeDef['multidimensional'])) {
6212
                $nv = array();
6213
                foreach ($value as $v) {
0 ignored issues
show
Bug introduced by
The expression $value of type object|integer|double|string|array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
6214
                    $cols = ',' . sizeof($v);
6215
                    $nv = array_merge($nv, $v);
6216
                }
6217
                $value = $nv;
6218
            } else {
6219
                $cols = '';
6220
            }
6221
            if (is_array($value) && sizeof($value) >= 1) {
6222
                $rows = sizeof($value);
6223
                $contents = '';
6224
                foreach ($value as $k => $v) {
6225
                    $this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");
6226
                    //if (strpos($typeDef['arrayType'], ':') ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
6227
                    if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) {
6228
                        $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
6229
                    } else {
6230
                        $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
6231
                    }
6232
                }
6233
            } else {
6234
                $rows = 0;
6235
                $contents = null;
6236
            }
6237
            // TODO: for now, an empty value will be serialized as a zero element
6238
            // array.  Revisit this when coding the handling of null/nil values.
6239
            if ($use == 'literal') {
6240
                $xml = "<$name$elementNS>"
6241
                    .$contents
6242
                    ."</$name>";
6243 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6244
                $xml = "<$name$elementNS xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '.
6245
                    $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
6246
                    .':arrayType="'
6247
                    .$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
0 ignored issues
show
Security Bug introduced by
It seems like $this->getPrefix($typeDef['arrayType']) targeting nusoap_base::getPrefix() can also be of type false; however, nusoap_base::getPrefixFromNamespace() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
6248
                    .":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">"
0 ignored issues
show
Bug introduced by
The variable $cols does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
6249
                    .$contents
6250
                    ."</$name>";
6251
            }
6252
        } elseif ($phpType == 'scalar') {
6253 View Code Duplication
            if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6254
                $elementNS = " xmlns=\"$ns\"";
6255
            } else {
6256
                if ($unqualified) {
6257
                    $elementNS = " xmlns=\"\"";
6258
                } else {
6259
                    $elementNS = '';
6260
                }
6261
            }
6262
            if ($use == 'literal') {
6263
                if ($forceType) {
6264
                    $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6265
                } else {
6266
                    $xml = "<$name$elementNS>$value</$name>";
6267
                }
6268
            } else {
6269
                $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6270
            }
6271
        }
6272
        $this->debug("in serializeType: returning: $xml");
6273
6274
        return $xml;
6275
    }
6276
6277
    /**
6278
     * serializes the attributes for a complexType
6279
     *
6280
     * @param  array  $typeDef our internal representation of an XML schema type (or element)
6281
     * @param  mixed  $value   a native PHP value (parameter value)
6282
     * @param  string $ns      the namespace of the type
6283
     * @param  string $uqType  the local part of the type
6284
     * @return string value serialized as an XML string
6285
     * @access private
6286
     */
6287
    function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6288
        $this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType");
6289
        $xml = '';
6290 View Code Duplication
        if (isset($typeDef['extensionBase'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6291
            $nsx = $this->getPrefix($typeDef['extensionBase']);
6292
            $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6293
            if ($this->getNamespaceFromPrefix($nsx)) {
0 ignored issues
show
Security Bug introduced by
It seems like $nsx defined by $this->getPrefix($typeDef['extensionBase']) on line 6291 can also be of type false; however, nusoap_base::getNamespaceFromPrefix() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
6294
                $nsx = $this->getNamespaceFromPrefix($nsx);
0 ignored issues
show
Security Bug introduced by
It seems like $nsx defined by $this->getNamespaceFromPrefix($nsx) on line 6294 can also be of type false; however, nusoap_base::getNamespaceFromPrefix() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
6295
            }
6296
            if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
6297
                $this->debug("serialize attributes for extension base $nsx:$uqTypex");
6298
                $xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex);
6299
            } else {
6300
                $this->debug("extension base $nsx:$uqTypex is not a supported type");
6301
            }
6302
        }
6303
        if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) {
6304
            $this->debug("serialize attributes for XML Schema type $ns:$uqType");
6305 View Code Duplication
            if (is_array($value)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6306
                $xvalue = $value;
6307
            } elseif (is_object($value)) {
6308
                $xvalue = get_object_vars($value);
6309
            } else {
6310
                $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6311
                $xvalue = array();
6312
            }
6313
            foreach ($typeDef['attrs'] as $aName => $attrs) {
6314
                if (isset($xvalue['!' . $aName])) {
6315
                    $xname = '!' . $aName;
6316
                    $this->debug("value provided for attribute $aName with key $xname");
6317
                } elseif (isset($xvalue[$aName])) {
6318
                    $xname = $aName;
6319
                    $this->debug("value provided for attribute $aName with key $xname");
6320 View Code Duplication
                } elseif (isset($attrs['default'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6321
                    $xname = '!' . $aName;
6322
                    $xvalue[$xname] = $attrs['default'];
6323
                    $this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName);
6324
                } else {
6325
                    $xname = '';
6326
                    $this->debug("no value provided for attribute $aName");
6327
                }
6328
                if ($xname) {
6329
                    $xml .=  " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\"";
6330
                }
6331
            }
6332
        } else {
6333
            $this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
6334
        }
6335
6336
        return $xml;
6337
    }
6338
6339
    /**
6340
     * serializes the elements for a complexType
6341
     *
6342
     * @param  array  $typeDef       our internal representation of an XML schema type (or element)
6343
     * @param  mixed  $value         a native PHP value (parameter value)
6344
     * @param  string $ns            the namespace of the type
6345
     * @param  string $uqType        the local part of the type
6346
     * @param  string $use           use for part (encoded|literal)
6347
     * @param  string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $encodingStyle not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
6348
     * @return string value serialized as an XML string
6349
     * @access private
6350
     */
6351
    function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6352
        $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
6353
        $xml = '';
6354 View Code Duplication
        if (isset($typeDef['extensionBase'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6355
            $nsx = $this->getPrefix($typeDef['extensionBase']);
6356
            $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6357
            if ($this->getNamespaceFromPrefix($nsx)) {
0 ignored issues
show
Security Bug introduced by
It seems like $nsx defined by $this->getPrefix($typeDef['extensionBase']) on line 6355 can also be of type false; however, nusoap_base::getNamespaceFromPrefix() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
6358
                $nsx = $this->getNamespaceFromPrefix($nsx);
0 ignored issues
show
Security Bug introduced by
It seems like $nsx defined by $this->getNamespaceFromPrefix($nsx) on line 6358 can also be of type false; however, nusoap_base::getNamespaceFromPrefix() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
6359
            }
6360
            if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
6361
                $this->debug("serialize elements for extension base $nsx:$uqTypex");
6362
                $xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle);
6363
            } else {
6364
                $this->debug("extension base $nsx:$uqTypex is not a supported type");
6365
            }
6366
        }
6367
        if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
6368
            $this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType");
6369 View Code Duplication
            if (is_array($value)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6370
                $xvalue = $value;
6371
            } elseif (is_object($value)) {
6372
                $xvalue = get_object_vars($value);
6373
            } else {
6374
                $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6375
                $xvalue = array();
6376
            }
6377
            // toggle whether all elements are present - ideally should validate against schema
6378
            if (count($typeDef['elements']) != count($xvalue)) {
6379
                $optionals = true;
6380
            }
6381
            foreach ($typeDef['elements'] as $eName => $attrs) {
6382
                if (!isset($xvalue[$eName])) {
6383 View Code Duplication
                    if (isset($attrs['default'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6384
                        $xvalue[$eName] = $attrs['default'];
6385
                        $this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
6386
                    }
6387
                }
6388
                // if user took advantage of a minOccurs=0, then only serialize named parameters
6389
                if (isset($optionals)
6390
                    && (!isset($xvalue[$eName]))
6391
                    && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true')
6392
                    ){
6393
                    if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') {
6394
                        $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']);
6395
                    }
6396
                    // do nothing
6397
                    $this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing");
6398
                } else {
6399
                    // get value
6400
                    if (isset($xvalue[$eName])) {
6401
                        $v = $xvalue[$eName];
6402
                    } else {
6403
                        $v = null;
6404
                    }
6405
                    if (isset($attrs['form'])) {
6406
                        $unqualified = ($attrs['form'] == 'unqualified');
6407
                    } else {
6408
                        $unqualified = false;
6409
                    }
6410
                    if (isset($attrs['maxOccurs']) && ($attrs['maxOccurs'] == 'unbounded' || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') {
6411
                        $vv = $v;
6412
                        foreach ($vv as $k => $v) {
6413
                            if (isset($attrs['type']) || isset($attrs['ref'])) {
6414
                                // serialize schema-defined type
6415
                                $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6416 View Code Duplication
                            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6417
                                // serialize generic type (can this ever really happen?)
6418
                                $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6419
                                $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
6420
                            }
6421
                        }
6422
                    } else {
6423
                        if (is_null($v) && isset($attrs['minOccurs']) && $attrs['minOccurs'] == '0') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
6424
                            // do nothing
6425
                        } elseif (is_null($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true') {
6426
                            // TODO: serialize a nil correctly, but for now serialize schema-defined type
6427
                            $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6428
                        } elseif (isset($attrs['type']) || isset($attrs['ref'])) {
6429
                            // serialize schema-defined type
6430
                            $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6431 View Code Duplication
                        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6432
                            // serialize generic type (can this ever really happen?)
6433
                            $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6434
                            $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
6435
                        }
6436
                    }
6437
                }
6438
            }
6439
        } else {
6440
            $this->debug("no elements to serialize for XML Schema type $ns:$uqType");
6441
        }
6442
6443
        return $xml;
6444
    }
6445
6446
    /**
6447
    * adds an XML Schema complex type to the WSDL types
6448
    *
6449
    * @param string	$name
6450
    * @param string $typeClass (complexType|simpleType|attribute)
6451
    * @param string $phpType currently supported are array and struct (php assoc array)
6452
    * @param string $compositor (all|sequence|choice)
6453
    * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6454
    * @param array $elements e.g. array ( name => array(name=>'',type=>'') )
6455
    * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
6456
    * @param string $arrayType as namespace:name (xsd:string)
6457
    * @see nusoap_xmlschema
6458
    * @access public
6459
    */
6460
    function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6461
        if (count($elements) > 0) {
6462
            $eElements = array();
6463 View Code Duplication
            foreach ($elements as $n => $e) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6464
                // expand each element
6465
                $ee = array();
6466
                foreach ($e as $k => $v) {
6467
                    $k = strpos($k,':') ? $this->expandQname($k) : $k;
6468
                    $v = strpos($v,':') ? $this->expandQname($v) : $v;
6469
                    $ee[$k] = $v;
6470
                }
6471
                $eElements[$n] = $ee;
6472
            }
6473
            $elements = $eElements;
6474
        }
6475
6476
        if (count($attrs) > 0) {
6477 View Code Duplication
            foreach ($attrs as $n => $a) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6478
                // expand each attribute
6479
                foreach ($a as $k => $v) {
6480
                    $k = strpos($k,':') ? $this->expandQname($k) : $k;
6481
                    $v = strpos($v,':') ? $this->expandQname($v) : $v;
6482
                    $aa[$k] = $v;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aa was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aa = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
6483
                }
6484
                $eAttrs[$n] = $aa;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$eAttrs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $eAttrs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $aa does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
6485
            }
6486
            $attrs = $eAttrs;
0 ignored issues
show
Bug introduced by
The variable $eAttrs does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
6487
        }
6488
6489
        $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6490
        $arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType;
6491
6492
        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6493
        $this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType);
6494
    }
6495
6496
    /**
6497
    * adds an XML Schema simple type to the WSDL types
6498
    *
6499
    * @param string $name
6500
    * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6501
    * @param string $typeClass (should always be simpleType)
6502
    * @param string $phpType (should always be scalar)
6503
    * @param array $enumeration array of values
6504
    * @see nusoap_xmlschema
6505
    * @access public
6506
    */
6507
    function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6508
        $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6509
6510
        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6511
        $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration);
6512
    }
6513
6514
    /**
6515
    * adds an element to the WSDL types
6516
    *
6517
    * @param array $attrs attributes that must include name and type
6518
    * @see nusoap_xmlschema
6519
    * @access public
6520
    */
6521
    function addElement($attrs) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6522
        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6523
        $this->schemas[$typens][0]->addElement($attrs);
6524
    }
6525
6526
    /**
6527
    * register an operation with the server
6528
    *
6529
    * @param string $name operation (method) name
6530
    * @param array $in assoc array of input values: key = param name, value = param type
0 ignored issues
show
Documentation introduced by
Should the type for parameter $in not be false|array?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
6531
    * @param array $out assoc array of output values: key = param name, value = param type
0 ignored issues
show
Documentation introduced by
Should the type for parameter $out not be false|array?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
6532
    * @param string $namespace optional The namespace for the operation
0 ignored issues
show
Documentation introduced by
Should the type for parameter $namespace not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
6533
    * @param string $soapaction optional The soapaction for the operation
0 ignored issues
show
Documentation introduced by
Should the type for parameter $soapaction not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
6534
    * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically
6535
    * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
6536
    * @param string $documentation optional The description to include in the WSDL
6537
    * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
6538
    * @access public
6539
    */
6540
    function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6541
        if ($use == 'encoded' && $encodingStyle == '') {
6542
            $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
6543
        }
6544
6545
        if ($style == 'document') {
6546
            $elements = array();
6547 View Code Duplication
            foreach ($in as $n => $t) {
0 ignored issues
show
Bug introduced by
The expression $in of type false|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6548
                $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
6549
            }
6550
            $this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
6551
            $this->addElement(array('name' => $name, 'type' => $name . 'RequestType'));
6552
            $in = array('parameters' => 'tns:' . $name . '^');
6553
6554
            $elements = array();
6555 View Code Duplication
            foreach ($out as $n => $t) {
0 ignored issues
show
Bug introduced by
The expression $out of type false|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6556
                $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
6557
            }
6558
            $this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
6559
            $this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified'));
6560
            $out = array('parameters' => 'tns:' . $name . 'Response' . '^');
6561
        }
6562
6563
        // get binding
6564
        $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] =
6565
        array(
6566
        'name' => $name,
6567
        'binding' => $this->serviceName . 'Binding',
6568
        'endpoint' => $this->endpoint,
6569
        'soapAction' => $soapaction,
6570
        'style' => $style,
6571
        'input' => array(
6572
            'use' => $use,
6573
            'namespace' => $namespace,
6574
            'encodingStyle' => $encodingStyle,
6575
            'message' => $name . 'Request',
6576
            'parts' => $in),
6577
        'output' => array(
6578
            'use' => $use,
6579
            'namespace' => $namespace,
6580
            'encodingStyle' => $encodingStyle,
6581
            'message' => $name . 'Response',
6582
            'parts' => $out),
6583
        'namespace' => $namespace,
6584
        'transport' => 'http://schemas.xmlsoap.org/soap/http',
6585
        'documentation' => $documentation);
6586
        // add portTypes
6587
        // add messages
6588 View Code Duplication
        if($in)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6589
        {
6590
            foreach($in as $pName => $pType)
6591
            {
6592
                if (strpos($pType,':')) {
6593
                    $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
0 ignored issues
show
Security Bug introduced by
It seems like $this->getPrefix($pType) targeting nusoap_base::getPrefix() can also be of type false; however, nusoap_base::getNamespaceFromPrefix() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
6594
                }
6595
                $this->messages[$name.'Request'][$pName] = $pType;
6596
            }
6597
        } else {
6598
            $this->messages[$name.'Request']= '0';
6599
        }
6600 View Code Duplication
        if($out)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6601
        {
6602
            foreach($out as $pName => $pType)
6603
            {
6604
                if (strpos($pType,':')) {
6605
                    $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
0 ignored issues
show
Security Bug introduced by
It seems like $this->getPrefix($pType) targeting nusoap_base::getPrefix() can also be of type false; however, nusoap_base::getNamespaceFromPrefix() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
6606
                }
6607
                $this->messages[$name.'Response'][$pName] = $pType;
6608
            }
6609
        } else {
6610
            $this->messages[$name.'Response']= '0';
6611
        }
6612
6613
        return true;
6614
    }
6615
}
6616
?><?php
6617
6618
/**
6619
*
6620
* nusoap_parser class parses SOAP XML messages into native PHP values
6621
*
6622
* @author   Dietrich Ayala <[email protected]>
6623
* @author   Scott Nichol <[email protected]>
6624
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
6625
* @access   public
6626
*/
6627
class nusoap_parser extends nusoap_base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6628
6629
    var $xml = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $xml.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6630
    var $xml_encoding = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $xml_encoding.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6631
    var $method = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $method.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6632
    var $root_struct = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $root_struct.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6633
    var $root_struct_name = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $root_struct_name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6634
    var $root_struct_namespace = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $root_struct_namespace.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6635
    var $root_header = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $root_header.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6636
    var $document = '';            // incoming SOAP body (text)
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $document.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6637
    // determines where in the message we are (envelope,header,body,method)
6638
    var $status = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $status.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6639
    var $position = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $position.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6640
    var $depth = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $depth.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6641
    var $default_namespace = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $default_namespace.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6642
    var $namespaces = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $namespaces.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6643
    var $message = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $message.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6644
    var $parent = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $parent.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6645
    var $fault = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fault.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6646
    var $fault_code = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fault_code.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6647
    var $fault_str = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fault_str.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6648
    var $fault_detail = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fault_detail.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6649
    var $depth_array = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $depth_array.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6650
    var $debug_flag = true;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $debug_flag.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6651
    var $soapresponse = NULL;    // parsed SOAP Body
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $soapresponse.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6652
    var $soapheader = NULL;        // parsed SOAP Header
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $soapheader.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6653
    var $responseHeaders = '';    // incoming SOAP headers (text)
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $responseHeaders.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6654
    var $body_position = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $body_position.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6655
    // for multiref parsing:
6656
    // array of id => pos
6657
    var $ids = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $ids.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6658
    // array of id => hrefs => pos
6659
    var $multirefs = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $multirefs.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6660
    // toggle for auto-decoding element content
6661
    var $decode_utf8 = true;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $decode_utf8.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6662
6663
    /**
6664
    * constructor that actually does the parsing
6665
    *
6666
    * @param    string $xml SOAP message
6667
    * @param    string $encoding character encoding scheme of message
6668
    * @param    string $method method for which XML is parsed (unused?)
6669
    * @param    string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
0 ignored issues
show
Documentation introduced by
Should the type for parameter $decode_utf8 not be boolean|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
6670
    * @access   public
6671
    */
6672
    function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
6673
        parent::nusoap_base();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (nusoap_base() instead of nusoap_parser()). Are you sure this is correct? If so, you might want to change this to $this->nusoap_base().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Coding Style introduced by
PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead
Loading history...
6674
        $this->xml = $xml;
6675
        $this->xml_encoding = $encoding;
6676
        $this->method = $method;
6677
        $this->decode_utf8 = $decode_utf8;
0 ignored issues
show
Documentation Bug introduced by
It seems like $decode_utf8 can also be of type string. However, the property $decode_utf8 is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
6678
6679
        // Check whether content has been read.
6680
        if (!empty($xml)) {
6681
            // Check XML encoding
6682
            $pos_xml = strpos($xml, '<?xml');
6683
            if ($pos_xml !== FALSE) {
6684
                $xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1);
6685
                if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
6686
                    $xml_encoding = $res[1];
6687
                    if (strtoupper($xml_encoding) != $encoding) {
6688
                        $err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
6689
                        $this->debug($err);
6690
                        if ($encoding != 'ISO-8859-1' || strtoupper($xml_encoding) != 'UTF-8') {
6691
                            $this->setError($err);
6692
6693
                            return;
6694
                        }
6695
                        // when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
6696
                    } else {
6697
                        $this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
6698
                    }
6699
                } else {
6700
                    $this->debug('No encoding specified in XML declaration');
6701
                }
6702
            } else {
6703
                $this->debug('No XML declaration');
6704
            }
6705
            $this->debug('Entering nusoap_parser(), length='.strlen($xml).', encoding='.$encoding);
6706
            // Create an XML parser - why not xml_parser_create_ns?
6707
            $this->parser = xml_parser_create($this->xml_encoding);
0 ignored issues
show
Bug introduced by
The property parser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
6708
            // Set the options for parsing the XML data.
6709
            //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
6710
            xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
6711
            xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
6712
            // Set the object for the parser.
6713
            xml_set_object($this->parser, $this);
6714
            // Set the element handlers for the parser.
6715
            xml_set_element_handler($this->parser, 'start_element','end_element');
6716
            xml_set_character_data_handler($this->parser,'character_data');
6717
6718
            // Parse the XML file.
6719
            if (!xml_parse($this->parser,$xml,true)) {
6720
                // Display an error message.
6721
                $err = sprintf('XML error parsing SOAP payload on line %d: %s',
6722
                xml_get_current_line_number($this->parser),
6723
                xml_error_string(xml_get_error_code($this->parser)));
6724
                $this->debug($err);
6725
                $this->debug("XML payload:\n" . $xml);
6726
                $this->setError($err);
6727
            } else {
6728
                $this->debug('in nusoap_parser ctor, message:');
6729
                $this->appendDebug($this->varDump($this->message));
6730
                $this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name);
6731
                // get final value
6732
                $this->soapresponse = $this->message[$this->root_struct]['result'];
6733
                // get header value
6734
                if ($this->root_header != '' && isset($this->message[$this->root_header]['result'])) {
6735
                    $this->soapheader = $this->message[$this->root_header]['result'];
6736
                }
6737
                // resolve hrefs/ids
6738
                if (sizeof($this->multirefs) > 0) {
6739
                    foreach ($this->multirefs as $id => $hrefs) {
6740
                        $this->debug('resolving multirefs for id: '.$id);
6741
                        $idVal = $this->buildVal($this->ids[$id]);
6742
                        if (is_array($idVal) && isset($idVal['!id'])) {
6743
                            unset($idVal['!id']);
6744
                        }
6745
                        foreach ($hrefs as $refPos => $ref) {
6746
                            $this->debug('resolving href at pos '.$refPos);
6747
                            $this->multirefs[$id][$refPos] = $idVal;
6748
                        }
6749
                    }
6750
                }
6751
            }
6752
            xml_parser_free($this->parser);
6753
        } else {
6754
            $this->debug('xml was empty, didn\'t parse!');
6755
            $this->setError('xml was empty, didn\'t parse!');
6756
        }
6757
    }
6758
6759
    /**
6760
    * start-element handler
6761
    *
6762
    * @param    resource $parser XML parser object
6763
    * @param    string $name element name
6764
    * @param    array $attrs associative array of attributes
6765
    * @access   private
6766
    */
6767
    function start_element($parser, $name, $attrs) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6768
        // position in a total number of elements, starting from 0
6769
        // update class level pos
6770
        $pos = $this->position++;
6771
        // and set mine
6772
        $this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>'');
6773
        // depth = how many levels removed from root?
6774
        // set mine as current global depth and increment global depth value
6775
        $this->message[$pos]['depth'] = $this->depth++;
6776
6777
        // else add self as child to whoever the current parent is
6778
        if ($pos != 0) {
6779
            $this->message[$this->parent]['children'] .= '|'.$pos;
6780
        }
6781
        // set my parent
6782
        $this->message[$pos]['parent'] = $this->parent;
6783
        // set self as current parent
6784
        $this->parent = $pos;
0 ignored issues
show
Documentation Bug introduced by
The property $parent was declared of type string, but $pos is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
6785
        // set self as current value for this depth
6786
        $this->depth_array[$this->depth] = $pos;
6787
        // get element prefix
6788 View Code Duplication
        if (strpos($name,':')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6789
            // get ns prefix
6790
            $prefix = substr($name,0,strpos($name,':'));
6791
            // get unqualified name
6792
            $name = substr(strstr($name,':'),1);
6793
        }
6794
        // set status
6795
        if ($name == 'Envelope' && $this->status == '') {
6796
            $this->status = 'envelope';
6797
        } elseif ($name == 'Header' && $this->status == 'envelope') {
6798
            $this->root_header = $pos;
0 ignored issues
show
Documentation Bug introduced by
The property $root_header was declared of type string, but $pos is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
6799
            $this->status = 'header';
6800
        } elseif ($name == 'Body' && $this->status == 'envelope') {
6801
            $this->status = 'body';
6802
            $this->body_position = $pos;
6803
        // set method
6804
        } elseif ($this->status == 'body' && $pos == ($this->body_position+1)) {
6805
            $this->status = 'method';
6806
            $this->root_struct_name = $name;
6807
            $this->root_struct = $pos;
0 ignored issues
show
Documentation Bug introduced by
The property $root_struct was declared of type string, but $pos is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
6808
            $this->message[$pos]['type'] = 'struct';
6809
            $this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
6810
        }
6811
        // set my status
6812
        $this->message[$pos]['status'] = $this->status;
6813
        // set name
6814
        $this->message[$pos]['name'] = htmlspecialchars($name);
6815
        // set attrs
6816
        $this->message[$pos]['attrs'] = $attrs;
6817
6818
        // loop through atts, logging ns and type declarations
6819
        $attstr = '';
6820
        foreach ($attrs as $key => $value) {
6821
            $key_prefix = $this->getPrefix($key);
6822
            $key_localpart = $this->getLocalPart($key);
6823
            // if ns declarations, add to class level array of valid namespaces
6824
            if ($key_prefix == 'xmlns') {
6825
                if (preg_match('/^http:\/\/www.w3.org\/[0-9]{4}\/XMLSchema$/',$value)) {
6826
                    $this->XMLSchemaVersion = $value;
6827
                    $this->namespaces['xsd'] = $this->XMLSchemaVersion;
6828
                    $this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance';
6829
                }
6830
                $this->namespaces[$key_localpart] = $value;
6831
                // set method namespace
6832
                if ($name == $this->root_struct_name) {
6833
                    $this->methodNamespace = $value;
0 ignored issues
show
Bug introduced by
The property methodNamespace does not seem to exist. Did you mean method?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
6834
                }
6835
            // if it's a type declaration, set type
6836
        } elseif ($key_localpart == 'type') {
6837
                if (isset($this->message[$pos]['type']) && $this->message[$pos]['type'] == 'array') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
6838
                    // do nothing: already processed arrayType
6839
                } else {
6840
                    $value_prefix = $this->getPrefix($value);
6841
                    $value_localpart = $this->getLocalPart($value);
6842
                    $this->message[$pos]['type'] = $value_localpart;
6843
                    $this->message[$pos]['typePrefix'] = $value_prefix;
6844
                    if (isset($this->namespaces[$value_prefix])) {
6845
                        $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
6846
                    } else if (isset($attrs['xmlns:'.$value_prefix])) {
6847
                        $this->message[$pos]['type_namespace'] = $attrs['xmlns:'.$value_prefix];
6848
                    }
6849
                    // should do something here with the namespace of specified type?
6850
                }
6851
            } elseif ($key_localpart == 'arrayType') {
6852
                $this->message[$pos]['type'] = 'array';
6853
                /* do arrayType ereg here
6854
                [1]    arrayTypeValue    ::=    atype asize
6855
                [2]    atype    ::=    QName rank*
6856
                [3]    rank    ::=    '[' (',')* ']'
6857
                [4]    asize    ::=    '[' length~ ']'
6858
                [5]    length    ::=    nextDimension* Digit+
6859
                [6]    nextDimension    ::=    Digit+ ','
6860
                */
6861
                $expr = '/([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]/';
6862
                if (preg_match($expr,$value,$regs)) {
6863
                    $this->message[$pos]['typePrefix'] = $regs[1];
6864
                    $this->message[$pos]['arrayTypePrefix'] = $regs[1];
6865
                    if (isset($this->namespaces[$regs[1]])) {
6866
                        $this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
6867
                    } else if (isset($attrs['xmlns:'.$regs[1]])) {
6868
                        $this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:'.$regs[1]];
6869
                    }
6870
                    $this->message[$pos]['arrayType'] = $regs[2];
6871
                    $this->message[$pos]['arraySize'] = $regs[3];
6872
                    $this->message[$pos]['arrayCols'] = $regs[4];
6873
                }
6874
            // specifies nil value (or not)
6875
            } elseif ($key_localpart == 'nil') {
6876
                $this->message[$pos]['nil'] = ($value == 'true' || $value == '1');
6877
            // some other attribute
6878
            } elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') {
6879
                $this->message[$pos]['xattrs']['!' . $key] = $value;
6880
            }
6881
6882
            if ($key == 'xmlns') {
6883
                $this->default_namespace = $value;
6884
            }
6885
            // log id
6886
            if ($key == 'id') {
6887
                $this->ids[$value] = $pos;
6888
            }
6889
            // root
6890
            if ($key_localpart == 'root' && $value == 1) {
6891
                $this->status = 'method';
6892
                $this->root_struct_name = $name;
6893
                $this->root_struct = $pos;
6894
                $this->debug("found root struct $this->root_struct_name, pos $pos");
6895
            }
6896
            // for doclit
6897
            $attstr .= " $key=\"$value\"";
6898
        }
6899
        // get namespace - must be done after namespace atts are processed
6900
        if (isset($prefix)) {
6901
            $this->message[$pos]['namespace'] = $this->namespaces[$prefix];
6902
            $this->default_namespace = $this->namespaces[$prefix];
6903
        } else {
6904
            $this->message[$pos]['namespace'] = $this->default_namespace;
6905
        }
6906 View Code Duplication
        if ($this->status == 'header') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6907
            if ($this->root_header != $pos) {
6908
                $this->responseHeaders .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
6909
            }
6910
        } elseif ($this->root_struct_name != '') {
6911
            $this->document .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
6912
        }
6913
    }
6914
6915
    /**
6916
    * end-element handler
6917
    *
6918
    * @param    resource $parser XML parser object
6919
    * @param    string $name element name
6920
    * @access   private
6921
    */
6922
    function end_element($parser, $name) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6923
        // position of current element is equal to the last value left in depth_array for my depth
6924
        $pos = $this->depth_array[$this->depth--];
6925
6926
        // get element prefix
6927 View Code Duplication
        if (strpos($name,':')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6928
            // get ns prefix
6929
            $prefix = substr($name,0,strpos($name,':'));
6930
            // get unqualified name
6931
            $name = substr(strstr($name,':'),1);
6932
        }
6933
6934
        // build to native type
6935
        if (isset($this->body_position) && $pos > $this->body_position) {
6936
            // deal w/ multirefs
6937
            if (isset($this->message[$pos]['attrs']['href'])) {
6938
                // get id
6939
                $id = substr($this->message[$pos]['attrs']['href'],1);
6940
                // add placeholder to href array
6941
                $this->multirefs[$id][$pos] = 'placeholder';
6942
                // add set a reference to it as the result value
6943
                $this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
6944
            // build complexType values
6945
            } elseif ($this->message[$pos]['children'] != '') {
6946
                // if result has already been generated (struct/array)
6947
                if (!isset($this->message[$pos]['result'])) {
6948
                    $this->message[$pos]['result'] = $this->buildVal($pos);
6949
                }
6950
            // build complexType values of attributes and possibly simpleContent
6951
            } elseif (isset($this->message[$pos]['xattrs'])) {
6952
                if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
6953
                    $this->message[$pos]['xattrs']['!'] = null;
6954
                } elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
6955
                    if (isset($this->message[$pos]['type'])) {
6956
                        $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
6957 View Code Duplication
                    } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6958
                        $parent = $this->message[$pos]['parent'];
6959
                        if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
6960
                            $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
6961
                        } else {
6962
                            $this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
6963
                        }
6964
                    }
6965
                }
6966
                $this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
6967
            // set value of simpleType (or nil complexType)
6968
            } else {
6969
                //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
6970
                if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
6971
                    $this->message[$pos]['xattrs']['!'] = null;
6972
                } elseif (isset($this->message[$pos]['type'])) {
6973
                    $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
6974 View Code Duplication
                } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6975
                    $parent = $this->message[$pos]['parent'];
6976
                    if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
6977
                        $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
6978
                    } else {
6979
                        $this->message[$pos]['result'] = $this->message[$pos]['cdata'];
6980
                    }
6981
                }
6982
6983
                /* add value to parent's result, if parent is struct/array
6984
                $parent = $this->message[$pos]['parent'];
6985
                if ($this->message[$parent]['type'] != 'map') {
6986
                    if (strtolower($this->message[$parent]['type']) == 'array') {
6987
                        $this->message[$parent]['result'][] = $this->message[$pos]['result'];
6988
                    } else {
6989
                        $this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];
6990
                    }
6991
                }
6992
                */
6993
            }
6994
        }
6995
6996
        // for doclit
6997 View Code Duplication
        if ($this->status == 'header') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6998
            if ($this->root_header != $pos) {
6999
                $this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7000
            }
7001
        } elseif ($pos >= $this->root_struct) {
7002
            $this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7003
        }
7004
        // switch status
7005
        if ($pos == $this->root_struct) {
7006
            $this->status = 'body';
7007
            $this->root_struct_namespace = $this->message[$pos]['namespace'];
7008
        } elseif ($pos == $this->root_header) {
7009
            $this->status = 'envelope';
7010
        } elseif ($name == 'Body' && $this->status == 'body') {
7011
            $this->status = 'envelope';
7012
        } elseif ($name == 'Header' && $this->status == 'header') { // will never happen
7013
            $this->status = 'envelope';
7014
        } elseif ($name == 'Envelope' && $this->status == 'envelope') {
7015
            $this->status = '';
7016
        }
7017
        // set parent back to my parent
7018
        $this->parent = $this->message[$pos]['parent'];
7019
    }
7020
7021
    /**
7022
    * element content handler
7023
    *
7024
    * @param    resource $parser XML parser object
7025
    * @param    string $data element content
7026
    * @access   private
7027
    */
7028
    function character_data($parser, $data){
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7029
        $pos = $this->depth_array[$this->depth];
7030
        if ($this->xml_encoding=='UTF-8') {
7031
            // TODO: add an option to disable this for folks who want
7032
            // raw UTF-8 that, e.g., might not map to iso-8859-1
7033
            // TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
7034
            if ($this->decode_utf8) {
7035
                $data = utf8_decode($data);
7036
            }
7037
        }
7038
        $this->message[$pos]['cdata'] .= $data;
7039
        // for doclit
7040
        if ($this->status == 'header') {
7041
            $this->responseHeaders .= $data;
7042
        } else {
7043
            $this->document .= $data;
7044
        }
7045
    }
7046
7047
    /**
7048
    * get the parsed message (SOAP Body)
7049
    *
7050
    * @return	mixed
7051
    * @access   public
7052
    * @deprecated	use get_soapbody instead
7053
    */
7054
    function get_response(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7055
        return $this->soapresponse;
7056
    }
7057
7058
    /**
7059
    * get the parsed SOAP Body (NULL if there was none)
7060
    *
7061
    * @return	mixed
7062
    * @access   public
7063
    */
7064
    function get_soapbody(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7065
        return $this->soapresponse;
7066
    }
7067
7068
    /**
7069
    * get the parsed SOAP Header (NULL if there was none)
7070
    *
7071
    * @return	mixed
7072
    * @access   public
7073
    */
7074
    function get_soapheader(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7075
        return $this->soapheader;
7076
    }
7077
7078
    /**
7079
    * get the unparsed SOAP Header
7080
    *
7081
    * @return	string XML or empty if no Header
7082
    * @access   public
7083
    */
7084
    function getHeaders(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7085
        return $this->responseHeaders;
7086
    }
7087
7088
    /**
7089
    * decodes simple types into PHP variables
7090
    *
7091
    * @param    string $value value to decode
7092
    * @param    string $type XML type to decode
7093
    * @param    string $typens XML type namespace to decode
7094
    * @return	mixed PHP value
7095
    * @access   private
7096
    */
7097
    function decodeSimple($value, $type, $typens) {
0 ignored issues
show
Unused Code introduced by
The parameter $typens is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7098
        // TODO: use the namespace!
7099
        if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') {
7100
            return (string) $value;
7101
        }
7102
        if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') {
7103
            return (int) $value;
7104
        }
7105
        if ($type == 'float' || $type == 'double' || $type == 'decimal') {
7106
            return (double) $value;
7107
        }
7108
        if ($type == 'boolean') {
7109
            if (strtolower($value) == 'false' || strtolower($value) == 'f') {
7110
                return false;
7111
            }
7112
7113
            return (boolean) $value;
7114
        }
7115
        if ($type == 'base64' || $type == 'base64Binary') {
7116
            $this->debug('Decode base64 value');
7117
7118
            return base64_decode($value);
7119
        }
7120
        // obscure numeric types
7121
        if ($type == 'nonPositiveInteger' || $type == 'negativeInteger'
7122
            || $type == 'nonNegativeInteger' || $type == 'positiveInteger'
7123
            || $type == 'unsignedInt'
7124
            || $type == 'unsignedShort' || $type == 'unsignedByte') {
7125
            return (int) $value;
7126
        }
7127
        // bogus: parser treats array with no elements as a simple type
7128
        if ($type == 'array') {
7129
            return array();
7130
        }
7131
        // everything else
7132
        return (string) $value;
7133
    }
7134
7135
    /**
7136
    * builds response structures for compound values (arrays/structs)
7137
    * and scalars
7138
    *
7139
    * @param    integer $pos position in node tree
7140
    * @return	mixed	PHP value
7141
    * @access   private
7142
    */
7143
    function buildVal($pos){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7144 View Code Duplication
        if (!isset($this->message[$pos]['type'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7145
            $this->message[$pos]['type'] = '';
7146
        }
7147
        $this->debug('in buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']);
7148
        // if there are children...
7149
        if ($this->message[$pos]['children'] != '') {
7150
            $this->debug('in buildVal, there are children');
7151
            $children = explode('|',$this->message[$pos]['children']);
7152
            array_shift($children); // knock off empty
7153
            // md array
7154
            if (isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != '') {
7155
                $r=0; // rowcount
7156
                $c=0; // colcount
7157
                foreach ($children as $child_pos) {
7158
                    $this->debug("in buildVal, got an MD array element: $r, $c");
7159
                    $params[$r][] = $this->message[$child_pos]['result'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
7160
                    $c++;
7161
                    if ($c == $this->message[$pos]['arrayCols']) {
7162
                        $c = 0;
7163
                        $r++;
7164
                    }
7165
                }
7166
            // array
7167
            } elseif ($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array') {
7168
                $this->debug('in buildVal, adding array '.$this->message[$pos]['name']);
7169
                foreach ($children as $child_pos) {
7170
                    $params[] = &$this->message[$child_pos]['result'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
7171
                }
7172
            // apache Map type: java hashtable
7173
            } elseif ($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
7174
                $this->debug('in buildVal, Java Map '.$this->message[$pos]['name']);
7175
                foreach ($children as $child_pos) {
7176
                    $kv = explode("|",$this->message[$child_pos]['children']);
7177
                       $params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
7178
                }
7179
            // generic compound type
7180
            //} elseif ($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7181
            } else {
7182
                // Apache Vector type: treat as an array
7183
                $this->debug('in buildVal, adding Java Vector or generic compound type '.$this->message[$pos]['name']);
7184
                if ($this->message[$pos]['type'] == 'Vector' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
7185
                    $notstruct = 1;
7186
                } else {
7187
                    $notstruct = 0;
7188
                }
7189
                //
7190
                foreach ($children as $child_pos) {
7191
                    if ($notstruct) {
7192
                        $params[] = &$this->message[$child_pos]['result'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
7193
                    } else {
7194
                        if (isset($params[$this->message[$child_pos]['name']])) {
7195
                            // de-serialize repeated element name into an array
7196
                            if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
7197
                                $params[$this->message[$child_pos]['name']] = array($params[$this->message[$child_pos]['name']]);
7198
                            }
7199
                            $params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
7200
                        } else {
7201
                            $params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
0 ignored issues
show
Bug introduced by
The variable $params does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7202
                        }
7203
                    }
7204
                }
7205
            }
7206
            if (isset($this->message[$pos]['xattrs'])) {
7207
                $this->debug('in buildVal, handling attributes');
7208
                foreach ($this->message[$pos]['xattrs'] as $n => $v) {
7209
                    $params[$n] = $v;
7210
                }
7211
            }
7212
            // handle simpleContent
7213
            if (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
7214
                $this->debug('in buildVal, handling simpleContent');
7215
                if (isset($this->message[$pos]['type'])) {
7216
                    $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7217
                } else {
7218
                    $parent = $this->message[$pos]['parent'];
7219
                    if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7220
                        $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7221
                    } else {
7222
                        $params['!'] = $this->message[$pos]['cdata'];
7223
                    }
7224
                }
7225
            }
7226
            $ret = is_array($params) ? $params : array();
7227
            $this->debug('in buildVal, return:');
7228
            $this->appendDebug($this->varDump($ret));
7229
7230
            return $ret;
7231
        } else {
7232
            $this->debug('in buildVal, no children, building scalar');
7233
            $cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : '';
7234
            if (isset($this->message[$pos]['type'])) {
7235
                $ret = $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7236
                $this->debug("in buildVal, return: $ret");
7237
7238
                return $ret;
7239
            }
7240
            $parent = $this->message[$pos]['parent'];
7241
            if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7242
                $ret = $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7243
                $this->debug("in buildVal, return: $ret");
7244
7245
                return $ret;
7246
            }
7247
               $ret = $this->message[$pos]['cdata'];
7248
            $this->debug("in buildVal, return: $ret");
7249
7250
               return $ret;
7251
        }
7252
    }
7253
}
7254
7255
/**
7256
 * Backward compatibility
7257
 */
7258
class soap_parser extends nusoap_parser {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7259
}
7260
7261
?><?php
7262
7263
/**
7264
*
7265
* [nu]soapclient higher level class for easy usage.
7266
*
7267
* usage:
7268
*
7269
* // instantiate client with server info
7270
* $soapclient = new nusoap_client( string path [ ,mixed wsdl] );
7271
*
7272
* // call method, get results
7273
* echo $soapclient->call( string methodname [ ,array parameters] );
7274
*
7275
* // bye bye client
7276
* unset($soapclient);
7277
*
7278
* @author   Dietrich Ayala <[email protected]>
7279
* @author   Scott Nichol <[email protected]>
7280
* @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
7281
* @access   public
7282
*/
7283
class nusoap_client extends nusoap_base  {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7284
7285
    var $username = '';                // Username for HTTP authentication
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $username.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7286
    var $password = '';                // Password for HTTP authentication
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $password.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7287
    var $authtype = '';                // Type of HTTP authentication
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $authtype.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7288
    var $certRequest = array();        // Certificate for HTTP SSL authentication
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $certRequest.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7289
    var $requestHeaders = false;    // SOAP headers in request (text)
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $requestHeaders.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7290
    var $responseHeaders = '';        // SOAP headers from response (incomplete namespace resolution) (text)
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $responseHeaders.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7291
    var $responseHeader = NULL;        // SOAP Header from response (parsed)
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $responseHeader.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7292
    var $document = '';                // SOAP body response portion (incomplete namespace resolution) (text)
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $document.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7293
    var $endpoint;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $endpoint.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7294
    var $forceEndpoint = '';        // overrides WSDL endpoint
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $forceEndpoint.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7295
    var $proxyhost = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxyhost.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7296
    var $proxyport = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxyport.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7297
    var $proxyusername = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxyusername.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7298
    var $proxypassword = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $proxypassword.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7299
    var $portName = '';                // port name to use in WSDL
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $portName.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7300
    var $xml_encoding = '';            // character set encoding of incoming (response) messages
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $xml_encoding.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7301
    var $http_encoding = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $http_encoding.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7302
    var $timeout = 0;                // HTTP connection timeout
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $timeout.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7303
    var $response_timeout = 30;        // HTTP response timeout
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $response_timeout.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7304
    var $endpointType = '';            // soap|wsdl, empty for WSDL initialization error
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $endpointType.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7305
    var $persistentConnection = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $persistentConnection.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7306
    var $defaultRpcParams = false;    // This is no longer used
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $defaultRpcParams.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7307
    var $request = '';                // HTTP request
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $request.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7308
    var $response = '';                // HTTP response
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $response.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7309
    var $responseData = '';            // SOAP payload of response
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $responseData.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7310
    var $cookies = array();            // Cookies from response or for request
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $cookies.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7311
    var $decode_utf8 = true;        // toggles whether the parser decodes element content w/ utf8_decode()
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $decode_utf8.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7312
    var $operations = array();        // WSDL operations, empty for WSDL initialization error
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $operations.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7313
    var $curl_options = array();    // User-specified cURL options
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $curl_options.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7314
    var $bindingType = '';            // WSDL operation binding type
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $bindingType.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7315
    var $use_curl = false;            // whether to always try to use cURL
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $use_curl.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7316
7317
    /*
7318
     * fault related variables
7319
     */
7320
    /**
7321
     * @var fault
7322
     * @access   public
7323
     */
7324
    var $fault;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fault.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7325
    /**
7326
     * @var faultcode
7327
     * @access   public
7328
     */
7329
    var $faultcode;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $faultcode.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7330
    /**
7331
     * @var faultstring
7332
     * @access   public
7333
     */
7334
    var $faultstring;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $faultstring.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7335
    /**
7336
     * @var faultdetail
7337
     * @access   public
7338
     */
7339
    var $faultdetail;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $faultdetail.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7340
7341
    /**
7342
    * constructor
7343
    *
7344
    * @param    mixed $endpoint SOAP server or WSDL URL (string) , or wsdl instance (object)
7345
    * @param    mixed $wsdl optional, set to 'wsdl' or true if using WSDL
7346
    * @param    string $proxyhost optional
0 ignored issues
show
Documentation introduced by
Should the type for parameter $proxyhost not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
7347
    * @param    string $proxyport optional
0 ignored issues
show
Documentation introduced by
Should the type for parameter $proxyport not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
7348
    * @param	string $proxyusername optional
0 ignored issues
show
Documentation introduced by
Should the type for parameter $proxyusername not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
7349
    * @param	string $proxypassword optional
0 ignored issues
show
Documentation introduced by
Should the type for parameter $proxypassword not be false|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
7350
    * @param	integer $timeout set the connection timeout
7351
    * @param	integer $response_timeout set the response timeout
7352
    * @param	string $portName optional portName in WSDL document
7353
    * @access   public
7354
    */
7355
    function nusoap_client($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
7356
        parent::nusoap_base();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (nusoap_base() instead of nusoap_client()). Are you sure this is correct? If so, you might want to change this to $this->nusoap_base().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Coding Style introduced by
PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead
Loading history...
7357
        $this->endpoint = $endpoint;
7358
        $this->proxyhost = $proxyhost;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxyhost can also be of type false. However, the property $proxyhost is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
7359
        $this->proxyport = $proxyport;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxyport can also be of type false. However, the property $proxyport is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
7360
        $this->proxyusername = $proxyusername;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxyusername can also be of type false. However, the property $proxyusername is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
7361
        $this->proxypassword = $proxypassword;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxypassword can also be of type false. However, the property $proxypassword is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
7362
        $this->timeout = $timeout;
7363
        $this->response_timeout = $response_timeout;
7364
        $this->portName = $portName;
7365
7366
        $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
7367
        $this->appendDebug('endpoint=' . $this->varDump($endpoint));
7368
7369
        // make values
7370
        if ($wsdl) {
7371
            if (is_object($endpoint) && (get_class($endpoint) == 'wsdl')) {
7372
                $this->wsdl = $endpoint;
0 ignored issues
show
Bug introduced by
The property wsdl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
7373
                $this->endpoint = $this->wsdl->wsdl;
7374
                $this->wsdlFile = $this->endpoint;
0 ignored issues
show
Bug introduced by
The property wsdlFile does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
7375
                $this->debug('existing wsdl instance created from ' . $this->endpoint);
7376
                $this->checkWSDL();
7377
            } else {
7378
                $this->wsdlFile = $this->endpoint;
7379
                $this->wsdl = null;
7380
                $this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
7381
            }
7382
            $this->endpointType = 'wsdl';
7383
        } else {
7384
            $this->debug("instantiate SOAP with endpoint at $endpoint");
7385
            $this->endpointType = 'soap';
7386
        }
7387
    }
7388
7389
    /**
7390
    * calls method, returns PHP native type
7391
    *
7392
    * @param    string $operation SOAP server URL or path
7393
    * @param    mixed $params An array, associative or simple, of the parameters
7394
    *			              for the method call, or a string that is the XML
7395
    *			              for the call.  For rpc style, this call will
7396
    *			              wrap the XML in a tag named after the method, as
7397
    *			              well as the SOAP Envelope and Body.  For document
7398
    *			              style, this will only wrap with the Envelope and Body.
7399
    *			              IMPORTANT: when using an array with document style,
7400
    *			              in which case there
7401
    *                         is really one parameter, the root of the fragment
7402
    *                         used in the call, which encloses what programmers
7403
    *                         normally think of parameters.  A parameter array
7404
    *                         *must* include the wrapper.
7405
    * @param	string $namespace optional method namespace (WSDL can override)
7406
    * @param	string $soapAction optional SOAPAction value (WSDL can override)
7407
    * @param	mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
7408
    * @param	boolean $rpcParams optional (no longer used)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $rpcParams not be boolean|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
7409
    * @param	string	$style optional (rpc|document) the style to use when serializing parameters (WSDL can override)
7410
    * @param	string	$use optional (encoded|literal) the use when serializing parameters (WSDL can override)
7411
    * @return	mixed	response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors
7412
    * @access   public
7413
    */
7414
    function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded'){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7415
        $this->operation = $operation;
0 ignored issues
show
Bug introduced by
The property operation does not seem to exist. Did you mean operations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
7416
        $this->fault = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type object<fault> of property $fault.

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...
7417
        $this->setError('');
7418
        $this->request = '';
7419
        $this->response = '';
7420
        $this->responseData = '';
7421
        $this->faultstring = '';
0 ignored issues
show
Documentation Bug introduced by
It seems like '' of type string is incompatible with the declared type object<faultstring> of property $faultstring.

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...
7422
        $this->faultcode = '';
0 ignored issues
show
Documentation Bug introduced by
It seems like '' of type string is incompatible with the declared type object<faultcode> of property $faultcode.

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...
7423
        $this->opData = array();
0 ignored issues
show
Bug introduced by
The property opData does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
7424
7425
        $this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType");
7426
        $this->appendDebug('params=' . $this->varDump($params));
7427
        $this->appendDebug('headers=' . $this->varDump($headers));
7428
        if ($headers) {
7429
            $this->requestHeaders = $headers;
7430
        }
7431 View Code Duplication
        if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7432
            $this->loadWSDL();
7433
            if ($this->getError())
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getError() of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
7434
                return false;
7435
        }
7436
        // serialize parameters
7437
        if ($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)) {
7438
            // use WSDL for operation
7439
            $this->opData = $opData;
7440
            $this->debug("found operation");
7441
            $this->appendDebug('opData=' . $this->varDump($opData));
7442
            if (isset($opData['soapAction'])) {
7443
                $soapAction = $opData['soapAction'];
7444
            }
7445
            if (! $this->forceEndpoint) {
7446
                $this->endpoint = $opData['endpoint'];
7447
            } else {
7448
                $this->endpoint = $this->forceEndpoint;
7449
            }
7450
            $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] :    $namespace;
7451
            $style = $opData['style'];
7452
            $use = $opData['input']['use'];
7453
            // add ns to ns array
7454
            if ($namespace != '' && !isset($this->wsdl->namespaces[$namespace])) {
7455
                $nsPrefix = 'ns' . rand(1000, 9999);
7456
                $this->wsdl->namespaces[$nsPrefix] = $namespace;
7457
            }
7458
            $nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);
7459
            // serialize payload
7460
            if (is_string($params)) {
7461
                $this->debug("serializing param string for WSDL operation $operation");
7462
                $payload = $params;
7463
            } elseif (is_array($params)) {
7464
                $this->debug("serializing param array for WSDL operation $operation");
7465
                $payload = $this->wsdl->serializeRPCParameters($operation,'input',$params,$this->bindingType);
7466
            } else {
7467
                $this->debug('params must be array or string');
7468
                $this->setError('params must be array or string');
7469
7470
                return false;
7471
            }
7472
            $usedNamespaces = $this->wsdl->usedNamespaces;
7473
            if (isset($opData['input']['encodingStyle'])) {
7474
                $encodingStyle = $opData['input']['encodingStyle'];
7475
            } else {
7476
                $encodingStyle = '';
7477
            }
7478
            $this->appendDebug($this->wsdl->getDebug());
7479
            $this->wsdl->clearDebug();
7480
            if ($errstr = $this->wsdl->getError()) {
7481
                $this->debug('got wsdl error: '.$errstr);
7482
                $this->setError('wsdl error: '.$errstr);
7483
7484
                return false;
7485
            }
7486
        } elseif ($this->endpointType == 'wsdl') {
7487
            // operation not in WSDL
7488
            $this->appendDebug($this->wsdl->getDebug());
7489
            $this->wsdl->clearDebug();
7490
            $this->setError('operation '.$operation.' not present in WSDL.');
7491
            $this->debug("operation '$operation' not present in WSDL.");
7492
7493
            return false;
7494
        } else {
7495
            // no WSDL
7496
            //$this->namespaces['ns1'] = $namespace;
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7497
            $nsPrefix = 'ns' . rand(1000, 9999);
7498
            // serialize
7499
            $payload = '';
7500
            if (is_string($params)) {
7501
                $this->debug("serializing param string for operation $operation");
7502
                $payload = $params;
7503
            } elseif (is_array($params)) {
7504
                $this->debug("serializing param array for operation $operation");
7505
                foreach ($params as $k => $v) {
7506
                    $payload .= $this->serialize_val($v,$k,false,false,false,false,$use);
7507
                }
7508
            } else {
7509
                $this->debug('params must be array or string');
7510
                $this->setError('params must be array or string');
7511
7512
                return false;
7513
            }
7514
            $usedNamespaces = array();
7515
            if ($use == 'encoded') {
7516
                $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
7517
            } else {
7518
                $encodingStyle = '';
7519
            }
7520
        }
7521
        // wrap RPC calls with method element
7522
        if ($style == 'rpc') {
7523
            if ($use == 'literal') {
7524
                $this->debug("wrapping RPC request with literal method element");
7525 View Code Duplication
                if ($namespace) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7526
                    // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
7527
                    $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7528
                                $payload .
7529
                                "</$nsPrefix:$operation>";
7530
                } else {
7531
                    $payload = "<$operation>" . $payload . "</$operation>";
7532
                }
7533 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7534
                $this->debug("wrapping RPC request with encoded method element");
7535
                if ($namespace) {
7536
                    $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7537
                                $payload .
7538
                                "</$nsPrefix:$operation>";
7539
                } else {
7540
                    $payload = "<$operation>" .
7541
                                $payload .
7542
                                "</$operation>";
7543
                }
7544
            }
7545
        }
7546
        // serialize envelope
7547
        $soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders,$usedNamespaces,$style,$use,$encodingStyle);
7548
        $this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle");
7549
        $this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000));
7550
        // send
7551
        $return = $this->send($this->getHTTPBody($soapmsg),$soapAction,$this->timeout,$this->response_timeout);
7552
        if ($errstr = $this->getError()) {
7553
            $this->debug('Error: '.$errstr);
7554
7555
            return false;
7556
        } else {
7557
            $this->return = $return;
0 ignored issues
show
Bug introduced by
The property return does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
7558
            $this->debug('sent message successfully and got a(n) '.gettype($return));
7559
               $this->appendDebug('return=' . $this->varDump($return));
7560
7561
            // fault?
7562
            if (is_array($return) && isset($return['faultcode'])) {
7563
                $this->debug('got fault');
7564
                $this->setError($return['faultcode'].': '.$return['faultstring']);
7565
                $this->fault = true;
0 ignored issues
show
Documentation Bug introduced by
It seems like true of type boolean is incompatible with the declared type object<fault> of property $fault.

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...
7566
                foreach ($return as $k => $v) {
7567
                    $this->$k = $v;
7568
                    $this->debug("$k = $v<br>");
7569
                }
7570
7571
                return $return;
7572
            } elseif ($style == 'document') {
7573
                // NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
7574
                // we are only going to return the first part here...sorry about that
7575
                return $return;
7576
            } else {
7577
                // array of return values
7578
                if (is_array($return)) {
7579
                    // multiple 'out' parameters, which we return wrapped up
7580
                    // in the array
7581
                    if (sizeof($return) > 1) {
7582
                        return $return;
7583
                    }
7584
                    // single 'out' parameter (normally the return value)
7585
                    $return = array_shift($return);
7586
                    $this->debug('return shifted value: ');
7587
                    $this->appendDebug($this->varDump($return));
7588
7589
                       return $return;
7590
                // nothing returned (ie, echoVoid)
7591
                } else {
7592
                    return "";
7593
                }
7594
            }
7595
        }
7596
    }
7597
7598
    /**
7599
    * check WSDL passed as an instance or pulled from an endpoint
7600
    *
7601
    * @access   private
7602
    */
7603
    function checkWSDL() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7604
        $this->appendDebug($this->wsdl->getDebug());
7605
        $this->wsdl->clearDebug();
7606
        $this->debug('checkWSDL');
7607
        // catch errors
7608
        if ($errstr = $this->wsdl->getError()) {
7609
            $this->appendDebug($this->wsdl->getDebug());
7610
            $this->wsdl->clearDebug();
7611
            $this->debug('got wsdl error: '.$errstr);
7612
            $this->setError('wsdl error: '.$errstr);
7613
        } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap')) {
7614
            $this->appendDebug($this->wsdl->getDebug());
7615
            $this->wsdl->clearDebug();
7616
            $this->bindingType = 'soap';
7617
            $this->debug('got '.count($this->operations).' operations from wsdl '.$this->wsdlFile.' for binding type '.$this->bindingType);
7618
        } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap12')) {
7619
            $this->appendDebug($this->wsdl->getDebug());
7620
            $this->wsdl->clearDebug();
7621
            $this->bindingType = 'soap12';
7622
            $this->debug('got '.count($this->operations).' operations from wsdl '.$this->wsdlFile.' for binding type '.$this->bindingType);
7623
            $this->debug('**************** WARNING: SOAP 1.2 BINDING *****************');
7624
        } else {
7625
            $this->appendDebug($this->wsdl->getDebug());
7626
            $this->wsdl->clearDebug();
7627
            $this->debug('getOperations returned false');
7628
            $this->setError('no operations defined in the WSDL document!');
7629
        }
7630
    }
7631
7632
    /**
7633
     * instantiate wsdl object and parse wsdl file
7634
     *
7635
     * @access	public
7636
     */
7637
    function loadWSDL() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7638
        $this->debug('instantiating wsdl class with doc: '.$this->wsdlFile);
7639
        $this->wsdl = new wsdl('',$this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword,$this->timeout,$this->response_timeout,$this->curl_options,$this->use_curl);
7640
        $this->wsdl->setCredentials($this->username, $this->password, $this->authtype, $this->certRequest);
7641
        $this->wsdl->fetchWSDL($this->wsdlFile);
7642
        $this->checkWSDL();
7643
    }
7644
7645
    /**
7646
    * get available data pertaining to an operation
7647
    *
7648
    * @param    string $operation operation name
7649
    * @return	array array of data pertaining to the operation
7650
    * @access   public
7651
    */
7652
    function getOperationData($operation){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7653 View Code Duplication
        if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7654
            $this->loadWSDL();
7655
            if ($this->getError())
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getError() of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
7656
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by nusoap_client::getOperationData of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
7657
        }
7658
        if (isset($this->operations[$operation])) {
7659
            return $this->operations[$operation];
7660
        }
7661
        $this->debug("No data for operation: $operation");
7662
    }
7663
7664
    /**
7665
    * send the SOAP message
7666
    *
7667
    * Note: if the operation has multiple return values
7668
    * the return value of this method will be an array
7669
    * of those values.
7670
    *
7671
    * @param    string $msg a SOAPx4 soapmsg object
7672
    * @param    string $soapaction SOAPAction value
7673
    * @param    integer $timeout set connection timeout in seconds
7674
    * @param	integer $response_timeout set response timeout in seconds
7675
    * @return	mixed native PHP types.
7676
    * @access   private
7677
    */
7678
    function send($msg, $soapaction = '', $timeout=0, $response_timeout=30) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7679
        $this->checkCookies();
7680
        // detect transport
7681
        switch (true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^http/', $this->endpoint) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
7682
            // http(s)
7683
            case preg_match('/^http/',$this->endpoint):
7684
                $this->debug('transporting via HTTP');
7685
                if ($this->persistentConnection == true && is_object($this->persistentConnection)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
7686
                    $http =& $this->persistentConnection;
7687
                } else {
7688
                    $http = new soap_transport_http($this->endpoint, $this->curl_options, $this->use_curl);
7689
                    if ($this->persistentConnection) {
7690
                        $http->usePersistentConnection();
7691
                    }
7692
                }
7693
                $http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
7694
                $http->setSOAPAction($soapaction);
7695 View Code Duplication
                if ($this->proxyhost && $this->proxyport) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7696
                    $http->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
7697
                }
7698 View Code Duplication
                if ($this->authtype != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7699
                    $http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
7700
                }
7701
                if ($this->http_encoding != '') {
7702
                    $http->setEncoding($this->http_encoding);
0 ignored issues
show
Documentation introduced by
$this->http_encoding is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
7703
                }
7704
                $this->debug('sending message, length='.strlen($msg));
7705
                if (preg_match('/^http:/',$this->endpoint)) {
7706
                //if (strpos($this->endpoint,'http:')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7707
                    $this->responseData = $http->send($msg,$timeout,$response_timeout,$this->cookies);
0 ignored issues
show
Documentation Bug introduced by
It seems like $http->send($msg, $timeo...imeout, $this->cookies) can also be of type false. However, the property $responseData is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
7708
                } elseif (preg_match('/^https/',$this->endpoint)) {
7709
                //} elseif (strpos($this->endpoint,'https:')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7710
                    //if (phpversion() == '4.3.0-dev') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7711
                        //$response = $http->send($msg,$timeout,$response_timeout);
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7712
                           //$this->request = $http->outgoing_payload;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7713
                        //$this->response = $http->incoming_payload;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7714
                    //} else
7715
                    $this->responseData = $http->sendHTTPS($msg,$timeout,$response_timeout,$this->cookies);
0 ignored issues
show
Documentation Bug introduced by
It seems like $http->sendHTTPS($msg, $...imeout, $this->cookies) can also be of type false. However, the property $responseData is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Deprecated Code introduced by
The method soap_transport_http::sendHTTPS() has been deprecated.

This method has been deprecated.

Loading history...
7716
                } else {
7717
                    $this->setError('no http/s in endpoint url');
7718
                }
7719
                $this->request = $http->outgoing_payload;
7720
                $this->response = $http->incoming_payload;
7721
                $this->appendDebug($http->getDebug());
7722
                $this->UpdateCookies($http->incoming_cookies);
7723
7724
                // save transport object if using persistent connections
7725
                if ($this->persistentConnection) {
7726
                    $http->clearDebug();
7727
                    if (!is_object($this->persistentConnection)) {
7728
                        $this->persistentConnection = $http;
0 ignored issues
show
Documentation Bug introduced by
It seems like $http of type object<soap_transport_http> is incompatible with the declared type boolean of property $persistentConnection.

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...
7729
                    }
7730
                }
7731
7732
                if ($err = $http->getError()) {
7733
                    $this->setError('HTTP Error: '.$err);
7734
7735
                    return false;
7736
                } elseif ($this->getError()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getError() of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
7737
                    return false;
7738
                } else {
7739
                    $this->debug('got response, length='. strlen($this->responseData).' type='.$http->incoming_headers['content-type']);
7740
7741
                    return $this->parseResponse($http->incoming_headers, $this->responseData);
0 ignored issues
show
Security Bug introduced by
It seems like $this->responseData can also be of type false; however, nusoap_client::parseResponse() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
7742
                }
7743
            break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
7744
            default:
7745
                $this->setError('no transport found, or selected transport is not yet supported!');
7746
7747
            return false;
7748
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
7749
        }
7750
    }
7751
7752
    /**
7753
    * processes SOAP message returned from server
7754
    *
7755
    * @param	array	$headers	The HTTP headers
7756
    * @param	string	$data		unprocessed response data from server
7757
    * @return	mixed	value of the message, decoded into a PHP type
7758
    * @access   private
7759
    */
7760
    function parseResponse($headers, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7761
        $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
7762
        $this->appendDebug($this->varDump($headers));
7763
        if (!isset($headers['content-type'])) {
7764
            $this->setError('Response not of type text/xml (no content-type header)');
7765
7766
            return false;
7767
        }
7768
        if (!strstr($headers['content-type'], 'text/xml')) {
7769
            $this->setError('Response not of type text/xml: ' . $headers['content-type']);
7770
7771
            return false;
7772
        }
7773 View Code Duplication
        if (strpos($headers['content-type'], '=')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7774
            $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
7775
            $this->debug('Got response encoding: ' . $enc);
7776
            if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
7777
                $this->xml_encoding = strtoupper($enc);
7778
            } else {
7779
                $this->xml_encoding = 'US-ASCII';
7780
            }
7781
        } else {
7782
            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
7783
            $this->xml_encoding = 'ISO-8859-1';
7784
        }
7785
        $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
7786
        $parser = new nusoap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8);
0 ignored issues
show
Bug introduced by
The property operation does not seem to exist. Did you mean operations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
7787
        // add parser debug data to our debug
7788
        $this->appendDebug($parser->getDebug());
7789
        // if parse errors
7790
        if ($errstr = $parser->getError()) {
7791
            $this->setError( $errstr);
7792
            // destroy the parser object
7793
            unset($parser);
7794
7795
            return false;
7796
        } else {
7797
            // get SOAP headers
7798
            $this->responseHeaders = $parser->getHeaders();
7799
            // get SOAP headers
7800
            $this->responseHeader = $parser->get_soapheader();
7801
            // get decoded message
7802
            $return = $parser->get_soapbody();
7803
            // add document for doclit support
7804
            $this->document = $parser->document;
7805
            // destroy the parser object
7806
            unset($parser);
7807
            // return decode message
7808
            return $return;
7809
        }
7810
     }
7811
7812
    /**
7813
    * sets user-specified cURL options
7814
    *
7815
    * @param	mixed $option The cURL option (always integer?)
7816
    * @param	mixed $value The cURL option value
7817
    * @access   public
7818
    */
7819
    function setCurlOption($option, $value) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7820
        $this->debug("setCurlOption option=$option, value=");
7821
        $this->appendDebug($this->varDump($value));
7822
        $this->curl_options[$option] = $value;
7823
    }
7824
7825
    /**
7826
    * sets the SOAP endpoint, which can override WSDL
7827
    *
7828
    * @param	string $endpoint The endpoint URL to use, or empty string or false to prevent override
7829
    * @access   public
7830
    */
7831
    function setEndpoint($endpoint) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7832
        $this->debug("setEndpoint(\"$endpoint\")");
7833
        $this->forceEndpoint = $endpoint;
7834
    }
7835
7836
    /**
7837
    * set the SOAP headers
7838
    *
7839
    * @param	mixed $headers String of XML with SOAP header content, or array of soapval objects for SOAP headers
7840
    * @access   public
7841
    */
7842
    function setHeaders($headers){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7843
        $this->debug("setHeaders headers=");
7844
        $this->appendDebug($this->varDump($headers));
7845
        $this->requestHeaders = $headers;
7846
    }
7847
7848
    /**
7849
    * get the SOAP response headers (namespace resolution incomplete)
7850
    *
7851
    * @return	string
7852
    * @access   public
7853
    */
7854
    function getHeaders(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7855
        return $this->responseHeaders;
7856
    }
7857
7858
    /**
7859
    * get the SOAP response Header (parsed)
7860
    *
7861
    * @return	mixed
7862
    * @access   public
7863
    */
7864
    function getHeader(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7865
        return $this->responseHeader;
7866
    }
7867
7868
    /**
7869
    * set proxy info here
7870
    *
7871
    * @param    string $proxyhost
7872
    * @param    string $proxyport
7873
    * @param	string $proxyusername
7874
    * @param	string $proxypassword
7875
    * @access   public
7876
    */
7877
    function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7878
        $this->proxyhost = $proxyhost;
7879
        $this->proxyport = $proxyport;
7880
        $this->proxyusername = $proxyusername;
7881
        $this->proxypassword = $proxypassword;
7882
    }
7883
7884
    /**
7885
    * if authenticating, set user credentials here
7886
    *
7887
    * @param    string $username
7888
    * @param    string $password
7889
    * @param	string $authtype (basic|digest|certificate|ntlm)
7890
    * @param	array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
7891
    * @access   public
7892
    */
7893 View Code Duplication
    function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7894
        $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
7895
        $this->appendDebug($this->varDump($certRequest));
7896
        $this->username = $username;
7897
        $this->password = $password;
7898
        $this->authtype = $authtype;
7899
        $this->certRequest = $certRequest;
7900
    }
7901
7902
    /**
7903
    * use HTTP encoding
7904
    *
7905
    * @param    string $enc HTTP encoding
7906
    * @access   public
7907
    */
7908
    function setHTTPEncoding($enc='gzip, deflate'){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7909
        $this->debug("setHTTPEncoding(\"$enc\")");
7910
        $this->http_encoding = $enc;
0 ignored issues
show
Documentation Bug introduced by
The property $http_encoding was declared of type boolean, but $enc is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
7911
    }
7912
7913
    /**
7914
    * Set whether to try to use cURL connections if possible
7915
    *
7916
    * @param	boolean $use Whether to try to use cURL
7917
    * @access   public
7918
    */
7919
    function setUseCURL($use) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7920
        $this->debug("setUseCURL($use)");
7921
        $this->use_curl = $use;
7922
    }
7923
7924
    /**
7925
    * use HTTP persistent connections if possible
7926
    *
7927
    * @access   public
7928
    */
7929
    function useHTTPPersistentConnection(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7930
        $this->debug("useHTTPPersistentConnection");
7931
        $this->persistentConnection = true;
7932
    }
7933
7934
    /**
7935
    * gets the default RPC parameter setting.
7936
    * If true, default is that call params are like RPC even for document style.
7937
    * Each call() can override this value.
7938
    *
7939
    * This is no longer used.
7940
    *
7941
    * @return boolean
7942
    * @access public
7943
    * @deprecated
7944
    */
7945
    function getDefaultRpcParams() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7946
        return $this->defaultRpcParams;
7947
    }
7948
7949
    /**
7950
    * sets the default RPC parameter setting.
7951
    * If true, default is that call params are like RPC even for document style
7952
    * Each call() can override this value.
7953
    *
7954
    * This is no longer used.
7955
    *
7956
    * @param    boolean $rpcParams
7957
    * @access public
7958
    * @deprecated
7959
    */
7960
    function setDefaultRpcParams($rpcParams) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7961
        $this->defaultRpcParams = $rpcParams;
7962
    }
7963
7964
    /**
7965
    * dynamically creates an instance of a proxy class,
7966
    * allowing user to directly call methods from wsdl
7967
    *
7968
    * @return   object soap_proxy object
7969
    * @access   public
7970
    */
7971
    function getProxy() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7972
        $r = rand();
7973
        $evalStr = $this->_getProxyClassCode($r);
7974
        //$this->debug("proxy class: $evalStr");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7975
        if ($this->getError()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getError() of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
7976
            $this->debug("Error from _getProxyClassCode, so return NULL");
7977
7978
            return null;
7979
        }
7980
        // eval the class
7981
        eval($evalStr);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
7982
        // instantiate proxy object
7983
        eval("\$proxy = new nusoap_proxy_$r('');");
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
7984
        // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice
7985
        $proxy->endpointType = 'wsdl';
0 ignored issues
show
Bug introduced by
The variable $proxy does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
7986
        $proxy->wsdlFile = $this->wsdlFile;
7987
        $proxy->wsdl = $this->wsdl;
7988
        $proxy->operations = $this->operations;
7989
        $proxy->defaultRpcParams = $this->defaultRpcParams;
7990
        // transfer other state
7991
        $proxy->soap_defencoding = $this->soap_defencoding;
7992
        $proxy->username = $this->username;
7993
        $proxy->password = $this->password;
7994
        $proxy->authtype = $this->authtype;
7995
        $proxy->certRequest = $this->certRequest;
7996
        $proxy->requestHeaders = $this->requestHeaders;
7997
        $proxy->endpoint = $this->endpoint;
7998
        $proxy->forceEndpoint = $this->forceEndpoint;
7999
        $proxy->proxyhost = $this->proxyhost;
8000
        $proxy->proxyport = $this->proxyport;
8001
        $proxy->proxyusername = $this->proxyusername;
8002
        $proxy->proxypassword = $this->proxypassword;
8003
        $proxy->http_encoding = $this->http_encoding;
8004
        $proxy->timeout = $this->timeout;
8005
        $proxy->response_timeout = $this->response_timeout;
8006
        $proxy->persistentConnection = &$this->persistentConnection;
8007
        $proxy->decode_utf8 = $this->decode_utf8;
8008
        $proxy->curl_options = $this->curl_options;
8009
        $proxy->bindingType = $this->bindingType;
8010
        $proxy->use_curl = $this->use_curl;
8011
8012
        return $proxy;
8013
    }
8014
8015
    /**
8016
    * dynamically creates proxy class code
8017
    *
8018
    * @return   string PHP/NuSOAP code for the proxy class
8019
    * @access   private
8020
    */
8021
    function _getProxyClassCode($r) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8022
        $this->debug("in getProxy endpointType=$this->endpointType");
8023
        $this->appendDebug("wsdl=" . $this->varDump($this->wsdl));
8024
        if ($this->endpointType != 'wsdl') {
8025
            $evalStr = 'A proxy can only be created for a WSDL client';
8026
            $this->setError($evalStr);
8027
            $evalStr = "echo \"$evalStr\";";
8028
8029
            return $evalStr;
8030
        }
8031
        if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
8032
            $this->loadWSDL();
8033
            if ($this->getError()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getError() of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
8034
                return "echo \"" . $this->getError() . "\";";
8035
            }
8036
        }
8037
        $evalStr = '';
8038
        foreach ($this->operations as $operation => $opData) {
8039
            if ($operation != '') {
8040
                // create param string and param comment string
8041
                if (sizeof($opData['input']['parts']) > 0) {
8042
                    $paramStr = '';
8043
                    $paramArrayStr = '';
8044
                    $paramCommentStr = '';
8045
                    foreach ($opData['input']['parts'] as $name => $type) {
8046
                        $paramStr .= "\$$name, ";
8047
                        $paramArrayStr .= "'$name' => \$$name, ";
8048
                        $paramCommentStr .= "$type \$$name, ";
8049
                    }
8050
                    $paramStr = substr($paramStr, 0, strlen($paramStr)-2);
8051
                    $paramArrayStr = substr($paramArrayStr, 0, strlen($paramArrayStr)-2);
8052
                    $paramCommentStr = substr($paramCommentStr, 0, strlen($paramCommentStr)-2);
8053
                } else {
8054
                    $paramStr = '';
8055
                    $paramArrayStr = '';
8056
                    $paramCommentStr = 'void';
8057
                }
8058
                $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
8059
                $evalStr .= "// $paramCommentStr
8060
    function " . str_replace('.', '__', $operation) . "($paramStr) {
8061
        \$params = array($paramArrayStr);
8062
8063
        return \$this->call('$operation', \$params, '".$opData['namespace']."', '".(isset($opData['soapAction']) ? $opData['soapAction'] : '')."');
8064
    }
8065
    ";
8066
                unset($paramStr);
8067
                unset($paramCommentStr);
8068
            }
8069
        }
8070
        $evalStr = 'class nusoap_proxy_'.$r.' extends nusoap_client {
8071
    '.$evalStr.'
8072
}';
8073
8074
        return $evalStr;
8075
    }
8076
8077
    /**
8078
    * dynamically creates proxy class code
8079
    *
8080
    * @return   string PHP/NuSOAP code for the proxy class
8081
    * @access   public
8082
    */
8083
    function getProxyClassCode() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8084
        $r = rand();
8085
8086
        return $this->_getProxyClassCode($r);
8087
    }
8088
8089
    /**
8090
    * gets the HTTP body for the current request.
8091
    *
8092
    * @param string $soapmsg The SOAP payload
8093
    * @return string The HTTP body, which includes the SOAP payload
8094
    * @access private
8095
    */
8096
    function getHTTPBody($soapmsg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8097
        return $soapmsg;
8098
    }
8099
8100
    /**
8101
    * gets the HTTP content type for the current request.
8102
    *
8103
    * Note: getHTTPBody must be called before this.
8104
    *
8105
    * @return string the HTTP content type for the current request.
8106
    * @access private
8107
    */
8108
    function getHTTPContentType() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8109
        return 'text/xml';
8110
    }
8111
8112
    /**
8113
    * gets the HTTP content type charset for the current request.
8114
    * returns false for non-text content types.
8115
    *
8116
    * Note: getHTTPBody must be called before this.
8117
    *
8118
    * @return string the HTTP content type charset for the current request.
8119
    * @access private
8120
    */
8121
    function getHTTPContentTypeCharset() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8122
        return $this->soap_defencoding;
8123
    }
8124
8125
    /*
8126
    * whether or not parser should decode utf8 element content
8127
    *
8128
    * @return   always returns true
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
8129
    * @access   public
8130
    */
8131
    function decodeUTF8($bool){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8132
        $this->decode_utf8 = $bool;
8133
8134
        return true;
8135
    }
8136
8137
    /**
8138
     * adds a new Cookie into $this->cookies array
8139
     *
8140
     * @param  string  $name  Cookie Name
8141
     * @param  string  $value Cookie Value
8142
     * @return boolean if cookie-set was successful returns true, else false
8143
     * @access	public
8144
     */
8145
    function setCookie($name, $value) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8146
        if (strlen($name) == 0) {
8147
            return false;
8148
        }
8149
        $this->cookies[] = array('name' => $name, 'value' => $value);
8150
8151
        return true;
8152
    }
8153
8154
    /**
8155
     * gets all Cookies
8156
     *
8157
     * @return array with all internal cookies
8158
     * @access   public
8159
     */
8160
    function getCookies() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8161
        return $this->cookies;
8162
    }
8163
8164
    /**
8165
     * checks all Cookies and delete those which are expired
8166
     *
8167
     * @return boolean always return true
8168
     * @access   private
8169
     */
8170
    function checkCookies() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8171
        if (sizeof($this->cookies) == 0) {
8172
            return true;
8173
        }
8174
        $this->debug('checkCookie: check ' . sizeof($this->cookies) . ' cookies');
8175
        $curr_cookies = $this->cookies;
8176
        $this->cookies = array();
8177
        foreach ($curr_cookies as $cookie) {
8178
            if (! is_array($cookie)) {
8179
                $this->debug('Remove cookie that is not an array');
8180
                continue;
8181
            }
8182
            if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
8183
                if (strtotime($cookie['expires']) > time()) {
8184
                    $this->cookies[] = $cookie;
8185
                } else {
8186
                    $this->debug('Remove expired cookie ' . $cookie['name']);
8187
                }
8188
            } else {
8189
                $this->cookies[] = $cookie;
8190
            }
8191
        }
8192
        $this->debug('checkCookie: '.sizeof($this->cookies).' cookies left in array');
8193
8194
        return true;
8195
    }
8196
8197
    /**
8198
     * updates the current cookies with a new set
8199
     *
8200
     * @param  array   $cookies new cookies with which to update current ones
8201
     * @return boolean always return true
8202
     * @access	private
8203
     */
8204
    function UpdateCookies($cookies) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8205
        if (sizeof($this->cookies) == 0) {
8206
            // no existing cookies: take whatever is new
8207
            if (sizeof($cookies) > 0) {
8208
                $this->debug('Setting new cookie(s)');
8209
                $this->cookies = $cookies;
8210
            }
8211
8212
            return true;
8213
        }
8214
        if (sizeof($cookies) == 0) {
8215
            // no new cookies: keep what we've got
8216
            return true;
8217
        }
8218
        // merge
8219
        foreach ($cookies as $newCookie) {
8220
            if (!is_array($newCookie)) {
8221
                continue;
8222
            }
8223
            if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) {
8224
                continue;
8225
            }
8226
            $newName = $newCookie['name'];
8227
8228
            $found = false;
8229
            for ($i = 0; $i < count($this->cookies); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
8230
                $cookie = $this->cookies[$i];
8231
                if (!is_array($cookie)) {
8232
                    continue;
8233
                }
8234
                if (!isset($cookie['name'])) {
8235
                    continue;
8236
                }
8237
                if ($newName != $cookie['name']) {
8238
                    continue;
8239
                }
8240
                $newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN';
8241
                $domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN';
8242
                if ($newDomain != $domain) {
8243
                    continue;
8244
                }
8245
                $newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH';
8246
                $path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH';
8247
                if ($newPath != $path) {
8248
                    continue;
8249
                }
8250
                $this->cookies[$i] = $newCookie;
8251
                $found = true;
8252
                $this->debug('Update cookie ' . $newName . '=' . $newCookie['value']);
8253
                break;
8254
            }
8255
            if (! $found) {
8256
                $this->debug('Add cookie ' . $newName . '=' . $newCookie['value']);
8257
                $this->cookies[] = $newCookie;
8258
            }
8259
        }
8260
8261
        return true;
8262
    }
8263
}
8264
8265
if (!extension_loaded('soap')) {
8266
    /**
8267
     *	For backwards compatiblity, define soapclient unless the PHP SOAP extension is loaded.
8268
     */
8269
    class soapclient extends nusoap_client {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8270
    }
8271
}
8272
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
8273