Completed
Push — phpunit6 ( 08fba7...238eb7 )
by Richard
11:54
created

RpcNameHandler::handleCharacterData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 2
dl 0
loc 11
ccs 7
cts 8
cp 0.875
crap 3.0175
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * @copyright       XOOPS Project (http://xoops.org)
14
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package         class
16
 * @subpackage      xml
17
 * @since           1.0.0
18
 * @author          Kazumi Ono (AKA onokazu)
19
 * @version         $Id $
20
 */
21
22
/**
23
 * Class RSS Parser
24
 *
25
 * This class offers methods to parse RSS Files
26
 *
27
 * @link      http://www.xoops.org/ Latest release of this class
28
 * @package   class
29
 * @copyright Copyright (c) 2001 xoops.org. All rights reserved.
30
 * @author    Kazumi Ono <[email protected]>
31
 * @version   $Id$
32
 * @access    public
33
 */
34
class XoopsXmlRpcParser extends SaxParser
35
{
36
37
    /**
38
     * @access protected
39
     * @var    array
40
     */
41
    protected $_param;
42
43
    /**
44
     * @access protected
45
     * @var    string
46
     */
47
    protected $_methodName;
48
49
    /**
50
     * @access protected
51
     * @var    array
52
     */
53
    protected $_tempName;
54
55
    /**
56
     * @access protected
57
     * @var    array
58
     */
59
    protected $_tempValue;
60
61
    /**
62
     * @access protected
63
     * @var    array
64
     */
65
    protected $_tempMember;
66
67
    /**
68
     * @access protected
69
     * @var    array
70
     */
71
    protected $_tempStruct;
72
73
    /**
74
     * @access protected
75
     * @var    array
76
     */
77
    protected $_tempArray;
78
79
    /**
80
     * @access protected
81
     * @var    array
82
     */
83
    protected $_workingLevel = array();
84
85
86
    /**
87
     * Constructor of the class
88
     *
89
     * @param $input
90
     */
91 22
    public function __construct(&$input)
92
    {
93 22
        parent::__construct($input);
94 22
        $this->addTagHandler(new RpcMethodNameHandler());
95 22
        $this->addTagHandler(new RpcIntHandler());
96 22
        $this->addTagHandler(new RpcDoubleHandler());
97 22
        $this->addTagHandler(new RpcBooleanHandler());
98 22
        $this->addTagHandler(new RpcStringHandler());
99 22
        $this->addTagHandler(new RpcDateTimeHandler());
100 22
        $this->addTagHandler(new RpcBase64Handler());
101 22
        $this->addTagHandler(new RpcNameHandler());
102 22
        $this->addTagHandler(new RpcValueHandler());
103 22
        $this->addTagHandler(new RpcMemberHandler());
104 22
        $this->addTagHandler(new RpcStructHandler());
105 22
        $this->addTagHandler(new RpcArrayHandler());
106 22
    }
107
108
    /**
109
     * This Method starts the parsing of the specified RDF File. The File can be a local or a remote File.
110
     *
111
     * @param $name
112
     *
113
     * @return void
114
     */
115 2
    public function setTempName($name)
116
    {
117 2
        $this->_tempName[$this->getWorkingLevel()] = $name;
118 2
    }
119
120
    /**
121
     * @return string
122
     */
123 2
    public function getTempName()
124
    {
125 2
        return $this->_tempName[$this->getWorkingLevel()];
126
    }
127
128
    /**
129
     * @param mixed $value
130
     * @return void
131
     */
132 10
    public function setTempValue($value)
133
    {
134 10
        if (is_array($value)) {
135 2
            settype($this->_tempValue, 'array');
136 2
            foreach ($value as $k => $v) {
137 2
                $this->_tempValue[$k] = $v;
138
            }
139 8
        } elseif (is_string($value)) {
140 4
            if (isset($this->_tempValue)) {
141
                if (is_string($this->_tempValue)) {
142
                    $this->_tempValue .= $value;
143
                }
144
            } else {
145 4
                $this->_tempValue = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value of type string is incompatible with the declared type array of property $_tempValue.

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...
146
            }
147
        } else {
148 4
            $this->_tempValue = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value of type object or integer or double or null or boolean is incompatible with the declared type array of property $_tempValue.

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...
149
        }
150 10
    }
151
152
    /**
153
     * @return array
154
     */
155 8
    public function getTempValue()
156
    {
157 8
        return $this->_tempValue;
158
    }
159
160
    /**
161
     * @return void
162
     */
163 1
    public function resetTempValue()
164
    {
165 1
        $this->_tempValue = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $_tempValue.

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...
166 1
    }
167
168
    /**
169
     * @param string $name
170
     * @param mixed $value
171
     * @return void
172
     */
173 1
    public function setTempMember($name, $value)
174
    {
175 1
        $this->_tempMember[$this->getWorkingLevel()][$name] = $value;
176 1
    }
177
178
    /**
179
     * @return mixed
180
     */
181 2
    public function getTempMember()
182
    {
183 2
        return $this->_tempMember[$this->getWorkingLevel()];
184
    }
185
186
    /**
187
     * @return void
188
     */
189 2
    public function resetTempMember()
190
    {
191 2
        $this->_tempMember[$this->getWorkingLevel()] = array();
192 2
    }
193
194
    /**
195
     * @return void
196
     */
197 4
    public function setWorkingLevel()
198
    {
199 4
        array_push($this->_workingLevel, $this->getCurrentLevel());
200 4
    }
201
202
    /**
203
     * @return mixed
204
     */
205 9
    public function getWorkingLevel()
206
    {
207 9
        return (count($this->_workingLevel) > 0)
208 4
            ? $this->_workingLevel[count($this->_workingLevel) - 1]
209 9
            : null;
210
    }
211
212
    /**
213
     * @return void
214
     */
215 4
    public function releaseWorkingLevel()
216
    {
217 4
        array_pop($this->_workingLevel);
218 4
    }
219
220
    /**
221
     * @param array $member
222
     * @return void
223
     */
224 2
    public function setTempStruct($member)
225
    {
226 2
        $key = key($member);
227 2
        $this->_tempStruct[$this->getWorkingLevel()][$key] = $member[$key];
228 2
    }
229
230
    /**
231
     * @return
232
     */
233 2
    public function getTempStruct()
234
    {
235 2
        return $this->_tempStruct[$this->getWorkingLevel()];
236
    }
237
238
    /**
239
     * @return void
240
     */
241 2
    public function resetTempStruct()
242
    {
243 2
        $this->_tempStruct[$this->getWorkingLevel()] = array();
244 2
    }
245
246
    /**
247
     * @param mixed $value
248
     * @return void
249
     */
250 1
    public function setTempArray($value)
251
    {
252 1
        $this->_tempArray[$this->getWorkingLevel()][] = $value;
253 1
    }
254
255
    /**
256
     * @return mixed
257
     */
258 2
    public function getTempArray()
259
    {
260 2
        return $this->_tempArray[$this->getWorkingLevel()];
261
    }
262
263
    /**
264
     * @return void
265
     */
266 2
    public function resetTempArray()
267
    {
268 2
        $this->_tempArray[$this->getWorkingLevel()] = array();
269 2
    }
270
271
    /**
272
     * @param string $methodName
273
     * @return void
274
     */
275 2
    public function setMethodName($methodName)
276
    {
277 2
        $this->_methodName = $methodName;
278 2
    }
279
280
    /**
281
     * @return string
282
     */
283 2
    public function getMethodName()
284
    {
285 2
        return $this->_methodName;
286
    }
287
288
    /**
289
     * @param mixed $value
290
     * @return void
291
     */
292 1
    public function setParam($value)
293
    {
294 1
        $this->_param[] = $value;
295 1
    }
296
297
    /**
298
     * @return array
299
     */
300 1
    public function getParam()
301
    {
302 1
        return $this->_param;
303
    }
304
}
305
306
/**
307
 * Class RpcMethodNameHandler
308
 */
309
class RpcMethodNameHandler extends XmlTagHandler
310
{
311
312
    /**
313
     * @return string
314
     */
315 23
    public function getName()
316
    {
317 23
        return 'methodName';
318
    }
319
320
    /**
321
     * @param SaxParser $parser
322
     * @param $data
323
     * @return void
324
     */
325 1
    public function handleCharacterData(SaxParser $parser, &$data)
326
    {
327 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
328 1
        $parser->setMethodName($data);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setMethodName() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
329 1
    }
330
}
331
332
/**
333
 * Class RpcIntHandler
334
 */
335
class RpcIntHandler extends XmlTagHandler
336
{
337
338
    /**
339
    * @return string[]
340
    */
341 23
    public function getName()
342
    {
343 23
        return array('int', 'i4');
344
    }
345
346
    /**
347
     * @param SaxParser $parser
348
     * @param $data
349
     * @return void
350
     */
351 1
    public function handleCharacterData(SaxParser $parser, &$data)
352
    {
353 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
354 1
        $parser->setTempValue((int)($data));
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
355 1
    }
356
}
357
358
/**
359
 * Class RpcDoubleHandler
360
 */
361
class RpcDoubleHandler extends XmlTagHandler
362
{
363
364
    /**
365
     * @return string
366
     */
367 23
    public function getName()
368
    {
369 23
        return 'double';
370
    }
371
372
    /**
373
     * @param SaxParser $parser
374
     * @param $data
375
     * @return void
376
     */
377 1
    public function handleCharacterData(SaxParser $parser, &$data)
378
    {
379 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
380 1
        $data = (float)$data;
381 1
        $parser->setTempValue($data);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
382 1
    }
383
}
384
385
/**
386
 * Class RpcBooleanHandler
387
 */
388
class RpcBooleanHandler extends XmlTagHandler
389
{
390
391
    /**
392
     * @return string
393
     */
394 23
    public function getName()
395
    {
396 23
        return 'boolean';
397
    }
398
399
    /**
400
     * @param SaxParser $parser
401
     * @param $data
402
     * @return void
403
     */
404 1
    public function handleCharacterData(SaxParser $parser, &$data)
405
    {
406 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
407 1
        $data = (boolean)$data;
408 1
        $parser->setTempValue($data);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
409 1
    }
410
}
411
412
/**
413
 * Class RpcStringHandler
414
 */
415
class RpcStringHandler extends XmlTagHandler
416
{
417
418
    /**
419
     * @return string
420
     */
421 23
    public function getName()
422
    {
423 23
        return 'string';
424
    }
425
426
    /**
427
     * @param SaxParser $parser
428
     * @param $data
429
     * @return void
430
     */
431 1
    public function handleCharacterData(SaxParser $parser, &$data)
432
    {
433 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
434 1
        $parser->setTempValue((string)($data));
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
435 1
    }
436
}
437
438
/**
439
 * Class RpcDateTimeHandler
440
 */
441
class RpcDateTimeHandler extends XmlTagHandler
442
{
443
444
    /**
445
     * @return string
446
     */
447 23
    public function getName()
448
    {
449 23
        return 'dateTime.iso8601';
450
    }
451
452
    /**
453
     * @param SaxParser $parser
454
     * @param $data
455
     * @return void
456
     */
457 1
    public function handleCharacterData(SaxParser $parser, &$data)
458
    {
459 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
460 1
        $matches = array();
461 1
        if (!preg_match("/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})$/", $data, $matches)) {
462 1
            $parser->setTempValue(time());
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
463
        } else {
464
            $parser->setTempValue(gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]));
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
465
        }
466 1
    }
467
}
468
469
/**
470
 * Class RpcBase64Handler
471
 */
472
class RpcBase64Handler extends XmlTagHandler
473
{
474
475
    /**
476
     * @return string
477
     */
478 23
    public function getName()
479
    {
480 23
        return 'base64';
481
    }
482
483
    /**
484
     * @param SaxParser $parser
485
     * @param $data
486
     * @return void
487
     */
488 1
    public function handleCharacterData(SaxParser $parser, &$data)
489
    {
490 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
491 1
        $parser->setTempValue(base64_decode($data));
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
492 1
    }
493
}
494
495
/**
496
 * Class RpcNameHandler
497
 */
498
class RpcNameHandler extends XmlTagHandler
499
{
500
501
    /**
502
     * @return string
503
     */
504 23
    public function getName()
505
    {
506 23
        return 'name';
507
    }
508
509
    /**
510
     * @param SaxParser $parser
511
     * @param $data
512
     * @return void
513
     */
514 1
    public function handleCharacterData(SaxParser $parser, &$data)
515
    {
516 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
517 1
        switch ($parser->getParentTag()) {
518
            case 'member':
519 1
                $parser->setTempName($data);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempName() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
520 1
                break;
521
            default:
522 1
                break;
523
        }
524 1
    }
525
}
526
527
/**
528
 * Class RpcValueHandler
529
 */
530
class RpcValueHandler extends XmlTagHandler
531
{
532
533
    /**
534
     * @return string
535
     */
536 23
    public function getName()
537
    {
538 23
        return 'value';
539
    }
540
541
    /**
542
     * @param SaxParser $parser
543
     * @param $data
544
     * @return void
545
     */
546 1
    public function handleCharacterData(SaxParser $parser, &$data)
547
    {
548 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
549 1
        switch ($parser->getParentTag()) {
550
            case 'member':
551 1
                $parser->setTempValue($data);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
552 1
                break;
553
            case 'data':
554
            case 'array':
555 1
                $parser->setTempValue($data);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
556 1
                break;
557
            default:
558 1
                break;
559
        }
560 1
    }
561
562
    /**
563
     * @param SaxParser $parser
564
     * @param $attributes
565
     * @return void
566
     */
567 1
    public function handleBeginElement(SaxParser $parser, &$attributes)
568
    {
569 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
570
        //$parser->resetTempValue();
571 1
    }
572
573
    /**
574
     * @param SaxParser $parser
575
     * @return void
576
     */
577
    public function handleEndElement(SaxParser $parser)
578
    {
579
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
580
        switch ($parser->getCurrentTag()) {
581
            case 'member':
582
                $parser->setTempMember($parser->getTempName(), $parser->getTempValue());
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method getTempName() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method getTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempMember() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
583
                break;
584
            case 'array':
585
            case 'data':
586
                $parser->setTempArray($parser->getTempValue());
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method getTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempArray() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
587
                break;
588
            default:
589
                $parser->setParam($parser->getTempValue());
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method getTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setParam() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
590
                break;
591
        }
592
        $parser->resetTempValue();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method resetTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
593
    }
594
}
595
596
/**
597
 * Class RpcMemberHandler
598
 */
599 View Code Duplication
class RpcMemberHandler extends XmlTagHandler
0 ignored issues
show
Duplication introduced by
This class 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...
600
{
601
602
    /**
603
     * @return string
604
     */
605 23
    public function getName()
606
    {
607 23
        return 'member';
608
    }
609
610
    /**
611
     * @param SaxParser $parser
612
     * @param array $attributes
613
     * @return void
614
     */
615 1
    public function handleBeginElement(SaxParser $parser, &$attributes)
616
    {
617 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
618 1
        $parser->setWorkingLevel();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setWorkingLevel() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
619 1
        $parser->resetTempMember();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method resetTempMember() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
620 1
    }
621
622
    /**
623
     * @param SaxParser $parser
624
     * @return void
625
     */
626 1
    public function handleEndElement(SaxParser $parser)
627
    {
628 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
629 1
        $member = $parser->getTempMember();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method getTempMember() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
630 1
        $parser->releaseWorkingLevel();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method releaseWorkingLevel() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
631 1
        $parser->setTempStruct($member);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempStruct() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
632 1
    }
633
}
634
635
/**
636
 * Class RpcArrayHandler
637
 */
638 View Code Duplication
class RpcArrayHandler extends XmlTagHandler
0 ignored issues
show
Duplication introduced by
This class 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...
639
{
640
641
    /**
642
     * @return string
643
     */
644 23
    public function getName()
645
    {
646 23
        return 'array';
647
    }
648
649
    /**
650
    * @param SaxParser $parser
651
    * @param array $attributes
652
    * @return void
653
    */
654 1
    public function handleBeginElement(SaxParser $parser, &$attributes)
655
    {
656 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
657 1
        $parser->setWorkingLevel();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setWorkingLevel() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
658 1
        $parser->resetTempArray();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method resetTempArray() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
659 1
    }
660
661
    /**
662
     * @param SaxParser $parser
663
     * @return void
664
     */
665 1
    public function handleEndElement(SaxParser $parser)
666
    {
667 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
668 1
        $parser->setTempValue($parser->getTempArray());
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method getTempArray() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
669 1
        $parser->releaseWorkingLevel();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method releaseWorkingLevel() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
670 1
    }
671
}
672
673
/**
674
 * Class RpcStructHandler
675
 */
676 View Code Duplication
class RpcStructHandler extends XmlTagHandler
0 ignored issues
show
Duplication introduced by
This class 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...
677
{
678
679
    /**
680
     * @return string
681
     */
682 23
    public function getName()
683
    {
684 23
        return 'struct';
685
    }
686
687
    /**
688
     * @param SaxParser $parser
689
     * @param array $attributes
690
     * @return void
691
     */
692 1
    public function handleBeginElement(SaxParser $parser, &$attributes)
693
    {
694 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
695 1
        $parser->setWorkingLevel();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setWorkingLevel() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
696 1
        $parser->resetTempStruct();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method resetTempStruct() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
697 1
    }
698
699
    /**
700
     * @param SaxParser $parser
701
     * @return void
702
     */
703 1
    public function handleEndElement(SaxParser $parser)
704
    {
705 1
        if (!is_a($parser,'XoopsXmlRpcParser')) return;
706 1
        $parser->setTempValue($parser->getTempStruct());
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method getTempStruct() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method setTempValue() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
707 1
        $parser->releaseWorkingLevel();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SaxParser as the method releaseWorkingLevel() does only exist in the following sub-classes of SaxParser: XoopsXmlRpcParser. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
708 1
    }
709
}
710