Groupon::getStats()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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