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 |
||
10 | class NetAffiliationEx extends NetAffiliationOara |
||
11 | { |
||
12 | protected $_serverNumber = 6; |
||
13 | protected $_merchantIdList = array(); // To avoid repeated calls to \Oara\Utilities::getMerchantIdMapFromMerchantList |
||
14 | |||
15 | /** |
||
16 | * Call protected/private method of a class. |
||
17 | * |
||
18 | * @param object &$object Instantiated object that we will run method on. |
||
19 | * @param string $methodName Method name to call |
||
20 | * @param array $parameters Array of parameters to pass into method. |
||
21 | * |
||
22 | * @return mixed Method return. |
||
23 | */ |
||
24 | View Code Duplication | public function invokeMethod(&$object,$methodName, array $parameters = array()) |
|
31 | |||
32 | /** |
||
33 | * Call protected/private property of a class. |
||
34 | * @param $object |
||
35 | * @param $propertyName |
||
36 | * |
||
37 | * @return mixed |
||
38 | */ |
||
39 | View Code Duplication | public function invokeProperty(&$object,$propertyName) |
|
46 | |||
47 | /** |
||
48 | * @param $credentials |
||
49 | * @throws \Exception |
||
50 | * @throws \Oara\Curl\Exception |
||
51 | */ |
||
52 | /*public function login($credentials){ |
||
53 | $this->_credentials = $credentials; |
||
54 | $this->_client = new \Oara\Curl\Access($credentials); |
||
55 | |||
56 | }*/ |
||
57 | |||
58 | /** |
||
59 | * @return bool |
||
60 | */ |
||
61 | /*public function checkConnection() |
||
62 | { |
||
63 | $connection = false; |
||
64 | |||
65 | try{ |
||
66 | $valuesFormExport[] = new \Oara\Curl\Parameter('authl', $this->_credentials["user"]); |
||
67 | $valuesFormExport[] = new \Oara\Curl\Parameter('authv', $this->_credentials["apiPassword"]); |
||
68 | $urls = array(); |
||
69 | $urls[] = new \Oara\Curl\Request('https://stat.netaffiliation.com/requete.php?', $valuesFormExport); |
||
70 | |||
71 | $exportReport = $this->_client->get($urls); |
||
72 | $exportData = str_getcsv($exportReport[0], "\n"); |
||
73 | if (substr($exportData[0],0,2)=='OK'){ |
||
74 | $connection=true; |
||
75 | } |
||
76 | }catch (\Exception $exception){ |
||
77 | |||
78 | }finally{ |
||
79 | |||
80 | } |
||
81 | |||
82 | |||
83 | return $connection; |
||
84 | }*/ |
||
85 | /** |
||
86 | * @param string $idSite |
||
87 | */ |
||
88 | public function addAllowedSite(string $idSite){ |
||
91 | /** |
||
92 | * @param null $merchantList |
||
93 | * @param \DateTime|null $dStartDate |
||
94 | * @param \DateTime|null $dEndDate |
||
95 | * @return array |
||
96 | * @throws Exception |
||
97 | */ |
||
98 | public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
||
169 | } |
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.