Adtraction   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 161
Duplicated Lines 21.12 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 4
dl 34
loc 161
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A login() 0 23 4
A checkLogin() 0 4 1
A getMerchants() 25 25 5
A getDeals() 0 4 1
A getSales() 0 25 4
A getStats() 0 4 1
A getProducts() 0 5 1
A getTrackingParameter() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace Padosoft\AffiliateNetwork\Networks;
4
5
use Padosoft\AffiliateNetwork\Transaction;
6
use Padosoft\AffiliateNetwork\DealsResultset;
7
use Padosoft\AffiliateNetwork\Merchant;
8
use Padosoft\AffiliateNetwork\Stat;
9
use Padosoft\AffiliateNetwork\Deal;
10
use Padosoft\AffiliateNetwork\AbstractNetwork;
11
use Padosoft\AffiliateNetwork\NetworkInterface;
12
use Padosoft\AffiliateNetwork\AdtractionEx;
13
use Padosoft\AffiliateNetwork\ProductsResultset;
14
15
if (!defined('COOKIES_BASE_DIR')){
16
    define('COOKIES_BASE_DIR',public_path('upload/report'));
17
}
18
/**
19
 * Class Adtraction
20
 * @package Padosoft\AffiliateNetwork\Networks
21
 */
22
class Adtraction extends AbstractNetwork implements NetworkInterface
23
{
24
    /**
25
     * @var object
26
     */
27
    private $_network = null;
28
    private $_apiClient = null;
29
    private $_username = '';
30
    private $_password = '';
31
    private $_idSite = '';
32
    private $_logged    = false;
33
    protected $_tracking_parameter    = 'epi';
34
35
    /**
36
	 * Adtraction constructor.
37
	 * @param string $username
38
	 * @param string $password
39
	 * @param string $idSite
40
	 */
41 View Code Duplication
    public function __construct(string $username, string $password, string $idSite = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
42
    {
43
        $this->_network = new \Oara\Network\Publisher\Adtraction;
44
        $this->_username = $username;
45
        $this->_password = $password;
46
	    $this->_idSite = $idSite;
47
        $this->_apiClient = null;
48
        $this->login( $this->_username, $this->_password, $this->_idSite );
49
    }
50
51
    public function login(string $username, string $password, string $idSite = ''): bool
52
    {
53
        $this->_logged = false;
54
        if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) {
55
56
            return false;
57
        }
58
        $this->_username = $username;
59
        $this->_password = $password;
60
        $this->_idSite = $idSite;
61
        $credentials = array();
62
        $credentials["user"] = null; // not used
63
        $credentials["password"] = $this->_password;
64
        $credentials["idSite"] = null; // not used
65
        $this->_network->login( $credentials );
66
67
        if ($this->_network->checkConnection()) {
68
            $this->_logged = true;
69
70
        }
71
72
        return $this->_logged;
73
    }
74
75
    /**
76
     * @return bool
77
     */
78
    public function checkLogin() : bool
79
    {
80
        return $this->_logged;
81
    }
82
83
    /**
84
     * @return array of Merchants
85
     */
86 View Code Duplication
    public function getMerchants() : array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
87
    {
88
        if (!$this->checkLogin()) {
89
            return array();
90
        }
91
        $arrResult = array();
92
        $merchantList = $this->_network->getMerchantList();
93
        foreach($merchantList as $merchant) {
94
            $Merchant = Merchant::createInstance();
95
            $Merchant->merchant_ID = $merchant['cid'];
96
            $Merchant->name = $merchant['name'];
97
            $Merchant->status = $merchant['status'];
98
            if (!empty($merchant['launch_date'])) {
99
                $date = new \DateTime($merchant['launch_date']);
100
                $Merchant->launch_date = $date;
0 ignored issues
show
Documentation Bug introduced by
It seems like $date of type object<DateTime> is incompatible with the declared type string of property $launch_date.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
101
            }
102
            if (!empty($merchant['application_date'])) {
103
                $date = new \DateTime($merchant['application_date']);
104
                $Merchant->application_date = $date;
0 ignored issues
show
Documentation Bug introduced by
It seems like $date of type object<DateTime> is incompatible with the declared type string of property $application_date.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
105
            }
106
            $arrResult[] = $Merchant;
107
        }
108
109
        return $arrResult;
110
    }
111
112
    /**
113
     * @param int|null $merchantID
114
     * @param int $page
115
     * @param int $items_per_page
116
     *
117
     * @return DealsResultset
118
     */
119
    public function getDeals($merchantID,int $page=0,int $items_per_page=10) : DealsResultset
120
    {
121
        throw new \Exception("Not implemented yet");
122
    }
123
124
    /**
125
     * @param \DateTime $dateFrom
126
     * @param \DateTime $dateTo
127
     * @param int $merchantID
0 ignored issues
show
Documentation introduced by
There is no parameter named $merchantID. Did you maybe mean $arrMerchantID?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
128
     * @return array of Transaction
129
     */
130
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array
131
    {
132
        if (!$this->checkLogin()) {
133
            return array();
134
        }
135
        $arrResult = array();
136
        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
137
        foreach($transactionList as $transaction) {
138
            $Transaction = Transaction::createInstance();
139
            $Transaction->merchant_ID = $transaction['merchantId'];
140
            $date = new \DateTime($transaction['date']);
141
            $Transaction->date = $date; // $date->format('Y-m-d H:i:s');
0 ignored issues
show
Documentation Bug introduced by
It seems like $date of type object<DateTime> is incompatible with the declared type string of property $date.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
142
            $Transaction->unique_ID = $transaction['unique_id'];
143
            $Transaction->transaction_ID = $transaction['unique_id'];
144
            array_key_exists_safe( $transaction,
145
                'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
146
            $Transaction->status = $transaction['status'];
147
            $Transaction->amount = $transaction['amount'];
148
            $Transaction->commission = $transaction['commission'];
149
            $Transaction->currency = $transaction['currency'];
150
            $arrResult[] = $Transaction;
151
        }
152
153
        return $arrResult;
154
    }
155
156
    /**
157
     * @param \DateTime $dateFrom
158
     * @param \DateTime $dateTo
159
     * @param int $merchantID
160
     * @return array of Stat
161
     */
162
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
163
    {
164
        return array();
165
    }
166
167
168
    /**
169
     * @param  array $params
170
     *
171
     * @return ProductsResultset
172
     */
173
    public function getProducts(array $params = []): ProductsResultset
174
    {
175
        // TODO: Implement getProducts() method.
176
        throw new \Exception("Not implemented yet");
177
    }
178
179
    public function getTrackingParameter(){
180
        return $this->_tracking_parameter;
181
    }
182
}
183