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 |
||
16 | abstract class CookieDomainCheckAbstract extends CheckAbstract |
||
17 | { |
||
18 | protected $class = 'abstract'; |
||
19 | |||
20 | public function initConfigPaths() |
||
25 | |||
26 | /** |
||
27 | * @param Result $result |
||
28 | * @param \Mage_Core_Model_Store $store |
||
29 | * @param string $baseUrl setting |
||
30 | * @param string $cookieDomain setting |
||
31 | */ |
||
32 | protected function checkSettings(Result $result, \Mage_Core_Model_Store $store, $baseUrl, $cookieDomain) |
||
60 | |||
61 | /** |
||
62 | * simplified cookie domain against base-URL validation |
||
63 | * |
||
64 | * it follows the following (incomplete) verification: |
||
65 | * |
||
66 | * - the site-domain is extracted from the base-url |
||
67 | * - site-domain and cookie-domain are normalized by making them lowercase |
||
68 | * - if the site-domain is empty, the check returns false because it's moot |
||
69 | * - if the cookie-domain is smaller than three, the check returns false because it's moot |
||
70 | * - if the cookie-domain does not start with a dot ("."), and the whole matches site-domain return true. |
||
71 | * - otherwise the dot is removed and the cookie-domain is now with removed starting dot. |
||
72 | * - the cookie domain must be the suffix of the site-domain and the remaining prefix of site-domain must end with |
||
73 | * a dot. returns true/false |
||
74 | * |
||
75 | * @param string $cookieDomain |
||
76 | * @param string $siteUrl |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | public function validateCookieDomainAgainstUrl($cookieDomain, $siteUrl) |
||
126 | } |
||
127 |
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.