Completed
Push — master ( 671329...ca78f5 )
by
unknown
02:18
created

AdCell::getSales()   B

Complexity

Conditions 10
Paths 33

Size

Total Lines 40

Duplication

Lines 40
Ratio 100 %

Importance

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