Completed
Push — master ( 3b3ab6...960226 )
by
unknown
03:53
created

Digidip   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 167
Duplicated Lines 40.72 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 3
dl 68
loc 167
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A login() 20 20 4
A checkLogin() 0 4 1
A getMerchants() 0 4 1
A getDeals() 0 5 1
B getSales() 39 39 10
A getStats() 0 18 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\ProductsResultset;
13
14
/**
15
 * Class Digidip
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class Digidip 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    = '';
28
    private $_idSite = '';
29
30
    /**
31
     * @method __construct
32
     */
33 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...
34
    {
35
        $this->_network = new \Oara\Network\Publisher\Digidip;
36
        $this->_username = $username;
37
        $this->_password = $password;
38
        $this->_idSite = $idSite;
39
40
        $this->login( $this->_username, $this->_password, $this->_idSite );
41
    }
42
43 View Code Duplication
    public function login(string $username, string $password, string $idSite = ''): bool{
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...
44
        $this->_logged = false;
0 ignored issues
show
Bug introduced by
The property _logged does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
        if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) {
46
47
            return false;
48
        }
49
        $this->_username = $username;
50
        $this->_password = $password;
51
        $this->_idSite = $idSite;
52
        $credentials = array();
53
        $credentials["user"] = $this->_username;
54
        $credentials["password"] = $this->_password;
55
        $credentials["idSite"] = $this->_idSite;
56
        $this->_network->login($credentials);
57
        if ($this->_network->checkConnection()) {
58
            $this->_logged = true;
59
        }
60
61
        return $this->_logged;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function checkLogin() : bool
68
    {
69
        return $this->_logged;
70
    }
71
72
    /**
73
	 * @return array of Merchants
74
	 * @throws \Exception
75
	 */
76
    public function getMerchants() : array
77
    {
78
	    throw new \Exception("Not implemented yet");
79
    }
80
81
    /**
82
	 * @param null $merchantID
83
	 * @param int $page
84
	 * @param int $items_per_page
85
	 * @return DealsResultset  array of Deal
86
	 * @throws \Exception
87
	 */
88
    public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=100 ): DealsResultset
89
    {
90
	    throw new \Exception("Not implemented yet");
91
92
    }
93
94
   	/**
95
	 * @param \DateTime $dateFrom
96
	 * @param \DateTime $dateTo
97
	 * @param array $arrMerchantID
98
	 * @return array of Transaction
99
	 * @throws \Exception
100
	 */
101 View Code Duplication
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : 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...
102
    {
103
104
        $arrResult = array();
105
        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
106
        foreach($transactionList as $transaction) {
107
            $Transaction = Transaction::createInstance();
108
            if (isset($transaction['currency']) && !empty($transaction['currency'])) {
109
                $Transaction->currency = $transaction['currency'];
110
            } else {
111
                $Transaction->currency = "EUR";
112
            }
113
            $Transaction->status = $transaction['status'];
114
            $Transaction->amount = $transaction['amount'];
115
            array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
116
            $Transaction->title = '';
117
            $Transaction->unique_ID = $transaction['unique_id'];
118
            $Transaction->commission = $transaction['commission'];
119
            $date = new \DateTime($transaction['date']);
120
            $Transaction->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 $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...
121
            // Future use - Only few providers returns these dates values - <PN> - 2017-06-29
122
            if (isset($transaction['click_date']) && !empty($transaction['click_date'])) {
123
                $Transaction->click_date = new \DateTime($transaction['click_date']);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime($transaction['click_date']) of type object<DateTime> is incompatible with the declared type string of property $click_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...
124
            }
125
            if (isset($transaction['update_date']) && !empty($transaction['update_date'])) {
126
                $Transaction->update_date = new \DateTime($transaction['update_date']);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime($transaction['update_date']) of type object<DateTime> is incompatible with the declared type string of property $update_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...
127
            }
128
            $Transaction->merchant_ID = $transaction['merchantId'];
129
            $Transaction->campaign_name =  $transaction['merchantName'];
130
            $Transaction->IP =  $transaction['IP'];
131
            $Transaction->approved = false;
132
            if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED){
133
                $Transaction->approved = true;
134
            }
135
            $arrResult[] = $Transaction;
136
        }
137
138
        return $arrResult;
139
    }
140
141
    /**
142
     * @param \DateTime $dateFrom
143
     * @param \DateTime $dateTo
144
     * @param int $merchantID
145
     * @return array of Stat
146
     */
147
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
148
    {
149
        // TODO
150
        return array();
151
        /*
152
        $this->_apiClient->setConnectId($this->_username);
153
        $this->_apiClient->setSecretKey($this->_password);
154
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
155
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
156
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
157
        $arrResponse = json_decode($response, true);
158
        $reportItems = $arrResponse['reportItems'];
159
        $Stat = Stat::createInstance();
160
        $Stat->reportItems = $reportItems;
161
162
        return array($Stat);
163
        */
164
    }
165
166
167
    /**
168
	 * @param array $params
169
	 * @return ProductsResultset
170
	 * @throws \Exception
171
	 */
172
    public function getProducts(array $params = []): ProductsResultset
173
    {
174
        // TODO: Implement getProducts() method.
175
        throw new \Exception("Not implemented yet");
176
    }
177
178
    public function getTrackingParameter(){
179
        return $this->_tracking_parameter;
180
    }
181
182
183
184
}