Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
19 | View Code Duplication | class NotAuthorizedException extends \OutOfBoundsException |
|
|
|||
20 | { |
||
21 | const ERROR_RESPONSE = 'wamp.error.not_authorized'; |
||
22 | |||
23 | /** |
||
24 | * @var string name of the topic |
||
25 | */ |
||
26 | protected $topicName; |
||
27 | |||
28 | /** |
||
29 | * @param string $topicName |
||
30 | * @param string the router error message |
||
31 | */ |
||
32 | public function __construct($topicName, $errorMsg = 'session is not authorized') |
||
38 | |||
39 | /** |
||
40 | * @param string $topicName |
||
41 | */ |
||
42 | protected function setTopicName($topicName) |
||
46 | |||
47 | /** |
||
48 | * @return string the topic name |
||
49 | */ |
||
50 | public function getTopicName() |
||
54 | |||
55 | /** |
||
56 | * Checks if a router response is a 'no_such_topic' error. |
||
57 | * |
||
58 | * @param $errorResponse |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public static function isNotAuthrorizedError($errorResponse) |
||
66 | } |
||
67 |
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.