Ebay   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 160
Duplicated Lines 38.13 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 25
lcom 1
cbo 3
dl 61
loc 160
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A addAllowedSite() 0 6 2
A login() 22 23 5
A checkLogin() 0 4 1
A getMerchants() 0 5 1
A getDeals() 0 5 1
B getSales() 39 39 10
A getStats() 0 6 1
A getProducts() 0 5 1
A getTrackingParameter() 0 4 1
A __construct() 0 11 2

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
/**
16
 * Class Ebay
17
 * @package Padosoft\AffiliateNetwork\Networks
18
 */
19
class Ebay extends AbstractNetwork implements NetworkInterface
20
{
21
    /**
22
     * @var object
23
     */
24
    private $_network = null;
25
    private $_username = '';
26
    private $_password = '';
27
    protected $_apiClient = null;
28
    protected $_tracking_parameter = 'customid';
29
30
    /**
31
     * @method __construct
32
     */
33
    public function __construct(string $username, string $password, string $idSite = '')
34
    {
35
        $this->_network = new \Oara\Network\Publisher\Ebay();
36
        $this->_username = $username;
37
        $this->_password = $password;
38
        if (trim($idSite) != '') {
39
            // Ebay needs Site to filter countries
40
            $this->addAllowedSite($idSite);
41
        }
42
        $this->login($this->_username, $this->_password);
43
    }
44
45
    public function addAllowedSite($idSite)
46
    {
47
        if (trim($idSite) != '') {
48
            $this->_network->addAllowedSite($idSite);
49
        }
50
    }
51
52 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...
53
    {
54
        $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...
55
        if (isNullOrEmpty($username) || isNullOrEmpty($password)) {
56
57
            return false;
58
        }
59
        $this->_username = $username;
60
        $this->_password = $password;
61
        if (trim($idSite) != '') {
62
            // Ebay needs Site to filter countries
63
            $this->addAllowedSite($idSite);
64
        }
65
        $credentials = array();
66
        $credentials["user"] = $this->_username;
67
        $credentials["password"] = $this->_password;
68
        $this->_network->login($credentials);
69
        if ($this->_network->checkConnection()) {
70
            $this->_logged = true;
71
        }
72
73
        return $this->_logged;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function checkLogin(): bool
80
    {
81
        return $this->_logged;
82
    }
83
84
    /**
85
     * @return array of Merchants
86
     */
87
    public function getMerchants(): array
88
    {
89
        $arrResult = array();
90
        return $arrResult;
91
    }
92
93
    /**
94
     * @param int $merchantID
95
     * @return array of Deal
96
     */
97
    public function getDeals($merchantID = NULL, int $page = 0, int $items_per_page = 10): DealsResultset
98
    {
99
        $arrResult = array();
100
        return $arrResult;
101
    }
102
103
    /**
104
     * @param \DateTime $dateFrom
105
     * @param \DateTime $dateTo
106
     * @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...
107
     * @return array of Transaction
108
     */
109 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...
110
    {
111
        $arrResult = array();
112
        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
113
        foreach ($transactionList as $transaction) {
114
            $Transaction = Transaction::createInstance();
115
116
            if (isset($transaction['currency']) && !empty($transaction['currency'])) {
117
                $Transaction->currency = $transaction['currency'];
118
            } else {
119
                $Transaction->currency = "EUR";
120
            }
121
            $Transaction->status = $transaction['status'];
122
            $Transaction->amount = $transaction['amount'];
123
            array_key_exists_safe($transaction, 'custom_id') ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
124
            $Transaction->title = '';
125
            $Transaction->unique_ID = $transaction['unique_id'];
126
            $Transaction->commission = $transaction['commission'];
127
            $date = new \DateTime($transaction['date']);
128
            $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...
129
            // Future use - Only few providers returns these dates values - <PN> - 2017-06-29
130
            if (isset($transaction['click_date']) && !empty($transaction['click_date'])) {
131
                $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...
132
            }
133
            if (isset($transaction['update_date']) && !empty($transaction['update_date'])) {
134
                $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...
135
            }
136
            $Transaction->merchant_ID = $transaction['merchantId'];
137
            $Transaction->campaign_name = $transaction['merchantName'];
138
            // $Transaction->IP =  $transaction['IP'];
139
            $Transaction->approved = false;
140
            if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED) {
141
                $Transaction->approved = true;
142
            }
143
            $arrResult[] = $Transaction;
144
        }
145
146
        return $arrResult;
147
    }
148
149
    /**
150
     * @param \DateTime $dateFrom
151
     * @param \DateTime $dateTo
152
     * @param int $merchantID
153
     * @return array of Stat
154
     */
155
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0): array
156
    {
157
        // TODO
158
        return array();
159
160
    }
161
162
163
    /**
164
     * @param array $params
165
     * @return ProductsResultset
166
     * @throws \Exception
167
     */
168
    public function getProducts(array $params = []): ProductsResultset
169
    {
170
        // TODO: Implement getProducts() method.
171
        throw new \Exception("Not implemented yet");
172
    }
173
174
    public function getTrackingParameter()
175
    {
176
        return $this->_tracking_parameter;
177
    }
178
}
179