Completed
Push — master ( f54067...ca4d28 )
by
unknown
02:37
created

LeadAlliance::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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