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 | class RegistrationMonitor |
||
20 | { |
||
21 | use MonitorTrait; |
||
22 | |||
23 | const REGISTRATION_CREATE_TOPIC = 'wamp.registration.on_create'; |
||
24 | const REGISTRATION_REG_TOPIC = 'wamp.registration.on_register'; |
||
25 | const REGISTRATION_UNREG_TOPIC = 'wamp.registration.on_unregister'; |
||
26 | const REGISTRATION_DELETE_TOPIC = 'wamp.registration.on_delete'; |
||
27 | const REGISTRATION_LIST_TOPIC = 'wamp.registration.list'; |
||
28 | const REGISTRATION_LOOKUP_TOPIC = 'wamp.registration.lookup'; |
||
29 | const REGISTRATION_MATCH_TOPIC = 'wamp.registration.match'; |
||
30 | const REGISTRATION_GET_TOPIC = 'wamp.registration.get'; |
||
31 | const REGISTRATION_REGLIST_TOPIC = 'wamp.registration.list_callees'; |
||
32 | const REGISTRATION_REGCOUNT_TOPIC = 'wamp.registration.count_callees'; |
||
33 | |||
34 | /** |
||
35 | * @var \stdClass Objects withs lists of subscriptions (exact, prefix, wildcard) |
||
36 | */ |
||
37 | protected $registrationIds = null; |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param ClientSession $session |
||
43 | */ |
||
44 | public function __construct(ClientSession $session) |
||
49 | |||
50 | /** |
||
51 | * Initializes the subscription to the meta-events. |
||
52 | */ |
||
53 | View Code Duplication | protected function initSetupCalls() |
|
|
|||
54 | { |
||
55 | // @var \Tidal\WampWatch\Subscription\Collection |
||
56 | $collection = $this->getMetaSubscriptionCollection(); |
||
57 | |||
58 | $collection->addSubscription(self::REGISTRATION_CREATE_TOPIC, $this->getSubscriptionHandler('create')); |
||
59 | $collection->addSubscription(self::REGISTRATION_DELETE_TOPIC, $this->getSubscriptionHandler('delete')); |
||
60 | $collection->addSubscription(self::REGISTRATION_REG_TOPIC, $this->getSubscriptionHandler('register')); |
||
61 | $collection->addSubscription(self::REGISTRATION_UNREG_TOPIC, $this->getSubscriptionHandler('unregister')); |
||
62 | |||
63 | $this->setInitialCall(self::REGISTRATION_LIST_TOPIC, $this->getSubscriptionIdRetrievalCallback()); |
||
64 | } |
||
65 | |||
66 | protected function setList($list) |
||
67 | { |
||
68 | $this->registrationIds = $list; |
||
69 | } |
||
70 | |||
71 | protected function getList() |
||
75 | } |
||
76 |
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.