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 |
||
| 18 | class Daisycon extends AbstractNetwork implements NetworkInterface |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var object |
||
| 22 | */ |
||
| 23 | private $_network = null; |
||
| 24 | private $_username = ''; |
||
| 25 | private $_password = ''; |
||
| 26 | private $_apiClient = null; |
||
| 27 | protected $_tracking_parameter = 'ws'; |
||
| 28 | private $_idSite = ''; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @method __construct |
||
| 32 | */ |
||
| 33 | public function __construct(string $username, string $password, string $idSite = '') |
||
|
|
|||
| 34 | { |
||
| 35 | $this->_network = new \Oara\Network\Publisher\Daisycon; |
||
| 36 | $this->_username = $username; |
||
| 37 | $this->_password = $password; |
||
| 38 | $idSite = $this->_idSite; |
||
| 39 | $this->login( $this->_username, $this->_password, $idSite ); |
||
| 40 | } |
||
| 41 | |||
| 42 | View Code Duplication | public function login(string $username, string $password,string $idSite=''): bool{ |
|
| 43 | $this->_logged = false; |
||
| 44 | if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
||
| 45 | |||
| 46 | return false; |
||
| 47 | } |
||
| 48 | $this->_username = $username; |
||
| 49 | $this->_password = $password; |
||
| 50 | $credentials = array(); |
||
| 51 | $credentials["user"] = $this->_username; |
||
| 52 | $credentials["password"] = $this->_password; |
||
| 53 | $credentials["idSite"] = $idSite; |
||
| 54 | $this->_network->login($credentials); |
||
| 55 | if ($this->_network->checkConnection()) { |
||
| 56 | $this->_logged = true; |
||
| 57 | } |
||
| 58 | return $this->_logged; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return bool |
||
| 63 | */ |
||
| 64 | public function checkLogin() : bool |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return array of Merchants |
||
| 71 | */ |
||
| 72 | public function getMerchants() : array |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @param int $merchantID |
||
| 108 | * @return array of Deal |
||
| 109 | */ |
||
| 110 | public function getDeals($merchantID = null,int $page = 0,int $items_per_page = 100 ): DealsResultset |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param \DateTime $dateFrom |
||
| 153 | * @param \DateTime $dateTo |
||
| 154 | * @param int $merchantID |
||
| 155 | * @return array of Transaction |
||
| 156 | */ |
||
| 157 | View Code Duplication | public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
| 195 | |||
| 196 | /** |
||
| 197 | * @param \DateTime $dateFrom |
||
| 198 | * @param \DateTime $dateTo |
||
| 199 | * @param int $merchantID |
||
| 200 | * @return array of Stat |
||
| 201 | */ |
||
| 202 | public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
||
| 206 | |||
| 207 | |||
| 208 | /** |
||
| 209 | * @param array $params |
||
| 210 | * |
||
| 211 | * @return ProductsResultset |
||
| 212 | */ |
||
| 213 | public function getProducts(array $params = []): ProductsResultset |
||
| 218 | |||
| 219 | public function getTrackingParameter(){ |
||
| 222 | } |
||
| 223 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.