Completed
Push — xmfuuid ( 701fb9...3b299c )
by Richard
05:28
created

ThemeSetEmailHandler::handleCharacterData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 2
dl 11
loc 11
ccs 8
cts 8
cp 1
crap 3
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
class XoopsThemeSetParser extends SaxParser
23
{
24
    /**
25
     * @var array
26
     */
27
    public $tempArr = array();
28
29
    /**
30
     * @var array
31
     */
32
    public $themeSetData = array();
33
34
    /**
35
     * @var array
36
     */
37
    public $imagesData = array();
38
39
    /**
40
     * @var array
41
     */
42
    public $templatesData = array();
43
44
    /**
45
     * @param string $input
46
     */
47 25
    public function __construct(&$input)
48
    {
49 25
        parent::__construct($input);
50
        //$this->addTagHandler(new ThemeSetThemeNameHandler());
51 25
        $this->addTagHandler(new ThemeSetDateCreatedHandler());
52 25
        $this->addTagHandler(new ThemeSetAuthorHandler());
53 25
        $this->addTagHandler(new ThemeSetDescriptionHandler());
54 25
        $this->addTagHandler(new ThemeSetGeneratorHandler());
55 25
        $this->addTagHandler(new ThemeSetNameHandler());
56 25
        $this->addTagHandler(new ThemeSetEmailHandler());
57 25
        $this->addTagHandler(new ThemeSetLinkHandler());
58 25
        $this->addTagHandler(new ThemeSetTemplateHandler());
59 25
        $this->addTagHandler(new ThemeSetImageHandler());
60 25
        $this->addTagHandler(new ThemeSetModuleHandler());
61 25
        $this->addTagHandler(new ThemeSetFileTypeHandler());
62 25
        $this->addTagHandler(new ThemeSetTagHandler());
63 25
    }
64
65
    /**
66
     * @param string $name
67
     * @param string $value
68
     * @return void
69
     */
70 4
    public function setThemeSetData($name, &$value)
71
    {
72 4
        $this->themeSetData[$name] = $value;
73 4
    }
74
75
    /**
76
     * @param string $name
77
     * @return array|bool
78
     */
79 4
    public function getThemeSetData($name = null)
80
    {
81 4
        if (isset($name)) {
82 4
            if (isset($this->themeSetData[$name])) {
83 4
                return $this->themeSetData[$name];
84
            }
85 4
            return false;
86
        }
87 1
        return $this->themeSetData;
88
    }
89
90
    /**
91
     * @param array $imagearr
92
     * @return void
93
     */
94 2
    public function setImagesData(&$imagearr)
95
    {
96 2
        $this->imagesData[] = $imagearr;
97 2
    }
98
99
    /**
100
     * @return array
101
     */
102 2
    public function getImagesData()
103
    {
104 2
        return $this->imagesData;
105
    }
106
107
108
    /**
109
     * @param array $tplarr
110
     * @return void
111
     */
112 2
    public function setTemplatesData(&$tplarr)
113
    {
114 2
        $this->templatesData[] = $tplarr;
115 2
    }
116
117
    /**
118
     * @return array
119
     */
120 2
    public function getTemplatesData()
121
    {
122 2
        return $this->templatesData;
123
    }
124
125
    /**
126
     * @param string $name
127
     * @param string $value
128
     * @param string $delim
129
     * @return void
130
     */
131 13 View Code Duplication
    public function setTempArr($name, &$value, $delim = '')
132
    {
133 13
        if (!isset($this->tempArr[$name])) {
134 13
            $this->tempArr[$name] = $value;
135
        } else {
136 1
            $this->tempArr[$name] .= $delim . $value;
137
        }
138 13
    }
139
140
    /**
141
     * @return array
142
     */
143 13
    public function getTempArr($name = null)
144
    {
145 13
        if (isset($name)) {
146 11
            if (isset($this->tempArr[$name])) {
147 11
                return $this->tempArr[$name];
148
            }
149 9
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by XoopsThemeSetParser::getTempArr of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
150
        }
151 3
        return $this->tempArr;
152
    }
153
154
    /**
155
     * @return void
156
     */
157 6
    public function resetTempArr()
158
    {
159 6
        unset($this->tempArr);
160 6
        $this->tempArr = array();
161 6
    }
162
}
163
164
/**
165
 * Class ThemeSetDateCreatedHandler
166
 */
167
class ThemeSetDateCreatedHandler extends XmlTagHandler
168
{
169
170
    /**
171
     * @return string
172
     */
173 26
    public function getName()
174
    {
175 26
        return 'dateCreated';
176
    }
177
178
    /**
179
     * @param SaxParser $parser
180
     * @param array $data
181
     * @return void
182
     */
183 1
    public function handleCharacterData(SaxParser $parser, &$data)
184
    {
185 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
186 1
        switch ($parser->getParentTag()) {
187 1
            case 'themeset':
188 1
                $parser->setThemeSetData('date', $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 setThemeSetData() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser. 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...
189 1
                break;
190
            default:
191 1
                break;
192
        }
193 1
    }
194
}
195
196
/**
197
 * Class ThemeSetAuthorHandler
198
 */
199
class ThemeSetAuthorHandler extends XmlTagHandler
200
{
201
    /**
202
     * @return string
203
     */
204 26
    public function getName()
205
    {
206 26
        return 'author';
207
    }
208
209
    /**
210
     * @param SaxParser $parser
211
     * @param array $attributes
212
     * @return void
213
     */
214 1
    public function handleBeginElement(SaxParser $parser, &$attributes)
215
    {
216 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
217 1
        $parser->resetTempArr();
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 resetTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
218 1
    }
219
220
    /**
221
     * @param SaxParser $parser
222
     * @return void
223
     */
224
    public function handleEndElement(SaxParser $parser)
225
    {
226
        if (!is_a($parser,'XoopsThemeSetParser')) return;
227
        //todo where does this method come from??
228
        $parser->setCreditsData($parser->getTempArr());
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 getTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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
The method setCreditsData() does not seem to exist on object<SaxParser>.

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

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

Loading history...
229
    }
230
}
231
232
/**
233
 * Class ThemeSetDescriptionHandler
234
 */
235 View Code Duplication
class ThemeSetDescriptionHandler 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...
236
{
237
    /**
238
     * @return string
239
     */
240 26
    public function getName()
241
    {
242 26
        return 'description';
243
    }
244
245
    /**
246
     * @param SaxParser $parser
247
     * @param array $data
248
     * @return void
249
     */
250 1
    public function handleCharacterData(SaxParser $parser, &$data)
251
    {
252 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
253 1
        switch ($parser->getParentTag()) {
254 1
            case 'template':
255 1
                $parser->setTempArr('description', $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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
256 1
                break;
257 1
            case 'image':
258 1
                $parser->setTempArr('description', $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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
259 1
                break;
260
            default:
261 1
                break;
262
        }
263 1
    }
264
}
265
266
/**
267
 * Class ThemeSetGeneratorHandler
268
 */
269
class ThemeSetGeneratorHandler extends XmlTagHandler
270
{
271
    /**
272
     * @return string
273
     */
274 26
    public function getName()
275
    {
276 26
        return 'generator';
277
    }
278
279
    /**
280
     * @param SaxParser $parser
281
     * @param array $data
282
     * @return void
283
     */
284 1
    public function handleCharacterData(SaxParser $parser, &$data)
285
    {
286 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
287 1
        switch ($parser->getParentTag()) {
288 1
            case 'themeset':
289 1
                $parser->setThemeSetData('generator', $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 setThemeSetData() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser. 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...
290 1
                break;
291
            default:
292 1
                break;
293
        }
294 1
    }
295
}
296
297
/**
298
 * Class ThemeSetNameHandler
299
 */
300 View Code Duplication
class ThemeSetNameHandler 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...
301
{
302
303 26
    public function getName()
304
    {
305 26
        return 'name';
306
    }
307
308
    /**
309
     * @param SaxParser $parser
310
     * @param array $data
311
     * @return void
312
     */
313 1
    public function handleCharacterData(SaxParser $parser, &$data)
314
    {
315 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
316 1
        switch ($parser->getParentTag()) {
317 1
            case 'themeset':
318 1
                $parser->setThemeSetData('name', $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 setThemeSetData() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser. 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...
319 1
                break;
320 1
            case 'author':
321 1
                $parser->setTempArr('name', $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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
322 1
                break;
323
            default:
324 1
                break;
325
        }
326 1
    }
327
}
328
329
/**
330
 * Class ThemeSetEmailHandler
331
 */
332 View Code Duplication
class ThemeSetEmailHandler 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...
333
{
334
    /**
335
     * @return string
336
     */
337 26
    public function getName()
338
    {
339 26
        return 'email';
340
    }
341
342
    /**
343
     * @param SaxParser $parser
344
     * @param array $data
345
     * @return void
346
     */
347 1
    public function handleCharacterData(SaxParser $parser, &$data)
348
    {
349 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
350 1
        switch ($parser->getParentTag()) {
351 1
            case 'author':
352 1
                $parser->setTempArr('email', $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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
353 1
                break;
354
            default:
355 1
                break;
356
        }
357 1
    }
358
}
359
360
/**
361
 * Class ThemeSetLinkHandler
362
 */
363 View Code Duplication
class ThemeSetLinkHandler 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...
364
{
365
    /**
366
     * @return string
367
     */
368 26
    public function getName()
369
    {
370 26
        return 'link';
371
    }
372
373
    /**
374
     * @param SaxParser $parser
375
     * @param array $data
376
     * @return void
377
     */
378 1
    public function handleCharacterData(SaxParser $parser, &$data)
379
    {
380 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
381 1
        switch ($parser->getParentTag()) {
382 1
            case 'author':
383 1
                $parser->setTempArr('link', $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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
384 1
                break;
385
            default:
386 1
                break;
387
        }
388 1
    }
389
}
390
391
/**
392
 * Class ThemeSetTemplateHandler
393
 */
394 View Code Duplication
class ThemeSetTemplateHandler 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...
395
{
396
    /**
397
     * @return string
398
     */
399 26
    public function getName()
400
    {
401 26
        return 'template';
402
    }
403
404
    /**
405
     * @param SaxParser $parser
406
     * @param array $attributes
407
     * @return void
408
     */
409 2
    public function handleBeginElement(SaxParser $parser, &$attributes)
410
    {
411 2
        if (!is_a($parser,'XoopsThemeSetParser')) return;
412 2
        $parser->resetTempArr();
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 resetTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
413 2
        if (isset($attributes['name'])) {
414 2
            $parser->setTempArr('name', $attributes['name']);
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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
415
        }
416 2
    }
417
418
    /**
419
     * @param SaxParser $parser
420
     * @return void
421
     */
422 1
    public function handleEndElement(SaxParser $parser)
423
    {
424 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
425 1
        $value = $parser->getTempArr();
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 getTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
426 1
        $parser->setTemplatesData($value);
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 setTemplatesData() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser. 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...
427 1
    }
428
}
429
430
/**
431
 * Class ThemeSetImageHandler
432
 */
433 View Code Duplication
class ThemeSetImageHandler 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...
434
{
435
    /**
436
     * @return string
437
     */
438 26
    public function getName()
439
    {
440 26
        return 'image';
441
    }
442
443
    /**
444
     * @param SaxParser $parser
445
     * @param array $attributes
446
     * @return void
447
     */
448 2
    public function handleBeginElement(SaxParser $parser, &$attributes)
449
    {
450 2
        if (!is_a($parser,'XoopsThemeSetParser')) return;
451 2
        $parser->resetTempArr();
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 resetTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
452 2
        if (isset($attributes['name'])) {
453 2
            $parser->setTempArr('name', $attributes['name']);
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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
454
        }
455 2
    }
456
457
    /**
458
     * @param SaxParser $parser
459
     * @return void
460
     */
461 1
    public function handleEndElement(SaxParser $parser)
462
    {
463 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
464 1
        $value = $parser->getTempArr();
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 getTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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 1
        $parser->setImagesData($value);
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 setImagesData() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser. 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...
466 1
    }
467
}
468
469
/**
470
 * Class ThemeSetModuleHandler
471
 */
472
class ThemeSetModuleHandler extends XmlTagHandler
473
{
474
    /**
475
     * @return string
476
     */
477 26
    public function getName()
478
    {
479 26
        return 'module';
480
    }
481
482
    /**
483
     * @param SaxParser $parser
484
     * @param array $data
485
     * @return void
486
     */
487 1
    public function handleCharacterData(SaxParser $parser, &$data)
488
    {
489 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
490 1
        switch ($parser->getParentTag()) {
491 1
            case 'template':
492 1
            case 'image':
493 1
                $parser->setTempArr('module', $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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
494 1
                break;
495
            default:
496 1
                break;
497
        }
498 1
    }
499
}
500
501
/**
502
 * Class ThemeSetFileTypeHandler
503
 */
504 View Code Duplication
class ThemeSetFileTypeHandler 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...
505
{
506
    /**
507
     * @return string
508
     */
509 26
    public function getName()
510
    {
511 26
        return 'fileType';
512
    }
513
514
    /**
515
     * @param SaxParser $parser
516
     * @param array $data
517
     * @return void
518
     */
519 1
    public function handleCharacterData(SaxParser $parser, &$data)
520
    {
521 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
522 1
        switch ($parser->getParentTag()) {
523 1
            case 'template':
524 1
                $parser->setTempArr('type', $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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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...
525 1
                break;
526
            default:
527 1
                break;
528
        }
529 1
    }
530
}
531
532
/**
533
 * Class ThemeSetTagHandler
534
 */
535 View Code Duplication
class ThemeSetTagHandler 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...
536
{
537
    /**
538
     * @return string
539
     */
540 26
    public function getName()
541
    {
542 26
        return 'tag';
543
    }
544
545
    /**
546
     * @param SaxParser $parser
547
     * @param array $data
548
     * @return void
549
     */
550 1
    public function handleCharacterData(SaxParser $parser, &$data)
551
    {
552 1
        if (!is_a($parser,'XoopsThemeSetParser')) return;
553 1
        switch ($parser->getParentTag()) {
554 1
            case 'image':
555 1
                $parser->setTempArr('tag', $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 setTempArr() does only exist in the following sub-classes of SaxParser: XoopsThemeSetParser, XoopsXmlRss2Parser. 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