Completed
Push — master ( d6ee27...51558c )
by
unknown
04:20
created

Ebay::getSales()   D

Complexity

Conditions 10
Paths 33

Size

Total Lines 39
Code Lines 28

Duplication

Lines 39
Ratio 100 %

Importance

Changes 0
Metric Value
dl 39
loc 39
rs 4.8196
c 0
b 0
f 0
cc 10
eloc 28
nc 33
nop 3

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
use Padosoft\AffiliateNetwork\EbayEx;
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    = 'clickref';
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  EbayEx;
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
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
        $apiUrl = 'http://ws.webgains.com/aws.php';
44
        $this->_apiClient = new \SoapClient($apiUrl,
45
            array('login' => $this->_username,
46
                'encoding' => 'UTF-8',
47
                'password' => $this->_password,
48
                'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
49
                'soap_version' => SOAP_1_1)
50
        );
51
        */
52
        $this->login( $this->_username, $this->_password );
53
    }
54
55
    public function addAllowedSite($idSite){
56
        if (trim($idSite)!=''){
57
            $this->_network->addAllowedSite($idSite);
58
        }
59
    }
60
61 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...
62
        $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...
63
        if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) {
64
65
            return false;
66
        }
67
        $this->_username = $username;
68
        $this->_password = $password;
69
        if (trim($idSite)!=''){
70
            // Ebay needs Site to filter countries
71
            $this->addAllowedSite($idSite);
72
        }
73
        $credentials = array();
74
        $credentials["user"] = $this->_username;
75
        $credentials["password"] = $this->_password;
76
        $this->_network->login($credentials);
77
        if ($this->_network->checkConnection()) {
78
            $this->_logged = true;
79
        }
80
81
        return $this->_logged;
82
    }
83
84
    /**
85
     * @return bool
86
     */
87
    public function checkLogin() : bool
88
    {
89
        return $this->_logged;
90
    }
91
92
    /**
93
     * @return array of Merchants
94
     */
95
    public function getMerchants() : array
96
    {
97
        $arrResult = array();
98
        return $arrResult;
99
    }
100
101
    /**
102
     * @param int $merchantID
103
     * @return array of Deal
104
     */
105
    public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset
106
    {
107
        $arrResult = array();
108
        return $arrResult;
109
    }
110
111
    /**
112
     * @param \DateTime $dateFrom
113
     * @param \DateTime $dateTo
114
     * @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...
115
     * @return array of Transaction
116
     */
117 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...
118
    {
119
        $arrResult = array();
120
        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
121
        foreach($transactionList as $transaction) {
122
            $Transaction = Transaction::createInstance();
123
124
            if (isset($transaction['currency']) && !empty($transaction['currency'])) {
125
                $Transaction->currency = $transaction['currency'];
126
            } else {
127
                $Transaction->currency = "EUR";
128
            }
129
            $Transaction->status = $transaction['status'];
130
            $Transaction->amount = $transaction['amount'];
131
            array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
132
            $Transaction->title = '';
133
            $Transaction->unique_ID = $transaction['unique_id'];
134
            $Transaction->commission = $transaction['commission'];
135
            $date = new \DateTime($transaction['date']);
136
            $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...
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
137
            // Future use - Only few providers returns these dates values - <PN> - 2017-06-29
138
            if (isset($transaction['click_date']) && !empty($transaction['click_date'])) {
139
                $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...
140
            }
141
            if (isset($transaction['post_date']) && !empty($transaction['post_date'])) {
142
                $Transaction->update_date = new \DateTime($transaction['post_date']);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime($transaction['post_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...
143
            }
144
            $Transaction->merchant_ID = $transaction['merchantId'];
145
            $Transaction->campaign_name =  $transaction['merchantName'];
146
            // $Transaction->IP =  $transaction['IP'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
147
            $Transaction->approved = false;
148
            if ($Transaction->status==\Oara\Utilities::STATUS_CONFIRMED){
149
                $Transaction->approved = true;
150
            }
151
            $arrResult[] = $Transaction;
152
        }
153
154
        return $arrResult;
155
    }
156
157
    /**
158
     * @param \DateTime $dateFrom
159
     * @param \DateTime $dateTo
160
     * @param int $merchantID
161
     * @return array of Stat
162
     */
163
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
164
    {
165
        // TODO
166
        return array();
167
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
168
        $this->_apiClient->setConnectId($this->_username);
169
        $this->_apiClient->setSecretKey($this->_password);
170
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
171
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
172
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
173
        $arrResponse = json_decode($response, true);
174
        $reportItems = $arrResponse['reportItems'];
175
        $Stat = Stat::createInstance();
176
        $Stat->reportItems = $reportItems;
177
178
        return array($Stat);
179
        */
180
    }
181
182
183
    /**
184
     * @param  array $params
185
     *
186
     * @return ProductsResultset
187
     */
188
    public function getProducts(array $params = []): ProductsResultset
189
    {
190
        // TODO: Implement getProducts() method.
191
        throw new \Exception("Not implemented yet");
192
    }
193
194
    public function getTrackingParameter(){
195
        return $this->_tracking_parameter;
196
    }
197
}
198