TradeTracker::getMerchants()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 13
loc 13
rs 9.8333
cc 2
nc 2
nop 0
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 TradeTracker
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class TradeTracker extends AbstractNetwork implements NetworkInterface
19
{
20
    /**
21
     * @var object
22
     */
23
    private $_network = null;
24
    private $_username = '';
25
    private $_password = '';
26
    private $_apiClient = null;
27
    protected $_tracking_parameter    = 'clickref';
28
29
    /**
30
     * @method __construct
31
     */
32 View Code Duplication
    public function __construct(string $username, string $password, string $idSite='')
0 ignored issues
show
Unused Code introduced by
The parameter $idSite is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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\TradeTracker;
35
        $this->_username = $username;
36
        $this->_password = $password;
37
        /*
38
        $apiUrl = 'http://ws.webgains.com/aws.php';
39
        $this->_apiClient = new \SoapClient($apiUrl,
40
            array('login' => $this->_username,
41
                'encoding' => 'UTF-8',
42
                'password' => $this->_password,
43
                'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
44
                'soap_version' => SOAP_1_1)
45
        );
46
        */
47
        $this->login( $this->_username, $this->_password );
48
    }
49
50
    public function login(string $username, string $password,string $idSite=''): bool{
0 ignored issues
show
Unused Code introduced by
The parameter $idSite is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
        $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...
52
        if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) {
53
54
            return false;
55
        }
56
        $this->_username = $username;
57
        $this->_password = $password;
58
        $credentials = array();
59
        $credentials["user"] = $this->_username;
60
        $credentials["password"] = $this->_password;
61
        $this->_network->login($credentials);
62
        if ($this->_network->checkConnection()) {
63
            $this->_logged = true;
64
        }
65
66
        return $this->_logged;
67
    }
68
69
    /**
70
     * @return bool
71
     */
72
    public function checkLogin() : bool
73
    {
74
        return $this->_logged;
75
    }
76
77
    /**
78
     * @return array of Merchants
79
     */
80 View Code Duplication
    public function getMerchants() : 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...
81
    {
82
        $arrResult = array();
83
        $merchantList = $this->_network->getMerchantList();
84
        foreach($merchantList as $merchant) {
85
            $Merchant = Merchant::createInstance();
86
            $Merchant->merchant_ID = $merchant['cid'];
87
            $Merchant->name = $merchant['name'];
88
            $arrResult[] = $Merchant;
89
        }
90
91
        return $arrResult;
92
    }
93
94
    /**
95
     * @param int $merchantID
96
     * @return array of Deal
97
     */
98
    public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset
99
    {
100
        $arrResult = array();
101
        $arrResponse = $this->_apiClient->getFullEarnings(null, null, null, $this->_username, $this->_password);
102
        foreach($arrResponse as $response) {
103
            $Deal = Deal::createInstance();
104
            $Deal->transaction_ID = $response->transactionID;
0 ignored issues
show
Bug introduced by
The property transaction_ID does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
105
            $Deal->affiliate_ID = $response->affiliate_ID;
0 ignored issues
show
Bug introduced by
The property affiliate_ID does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
106
            $Deal->campaign_name = $response->campaignName;
0 ignored issues
show
Bug introduced by
The property campaign_name does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
107
            $Deal->campaign_ID = $response->campaignID;
0 ignored issues
show
Bug introduced by
The property campaign_ID does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
108
            $date = new \DateTime($response->date);
0 ignored issues
show
Unused Code introduced by
$date is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
109
            $Deal->date = $response->date;
0 ignored issues
show
Bug introduced by
The property date does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
110
            $Deal->programName = $response->program_name;
0 ignored issues
show
Bug introduced by
The property programName does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
111
            $Deal->merchant_ID = $response->programID;
112
            $Deal->commission = $response->commission;
0 ignored issues
show
Bug introduced by
The property commission does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
113
            $Deal->amount = $response->saleValue;
0 ignored issues
show
Bug introduced by
The property amount does not seem to exist. Did you mean discount_amount?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
114
            $Deal->status = $response->status;
0 ignored issues
show
Bug introduced by
The property status does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
115
            $Deal->referrer = $response->referrer;
0 ignored issues
show
Bug introduced by
The property referrer does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
116
            if($merchantID > 0) {
117
                if($merchantID == $response->programID) {
118
                    $arrResult[] = $Deal;
119
                }
120
            }
121
            else {
122
                $arrResult[] = $Deal;
123
            }
124
        }
125
126
        return $arrResult;
127
    }
128
129
    /**
130
     * @param \DateTime $dateFrom
131
     * @param \DateTime $dateTo
132
     * @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...
133
     * @return array of Transaction
134
     */
135 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...
136
    {
137
        /*
138
        if (count( $arrMerchantID ) < 1) {
139
            $merchants = $this->getMerchants();
140
            foreach ($merchants as $merchant) {
141
                $arrMerchantID[$merchant->merchant_ID] = ['cid' => $merchant->merchant_ID, 'name' => $merchant->name];
142
            }
143
        }
144
        */
145
        $arrResult = array();
146
        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
147
        foreach($transactionList as $transaction) {
148
            $Transaction = Transaction::createInstance();
149
            if (isset($transaction['currency']) && !empty($transaction['currency'])) {
150
                $Transaction->currency = $transaction['currency'];
151
            } else {
152
                $Transaction->currency = "EUR";
153
            }
154
            $Transaction->status = $transaction['status'];
155
            $Transaction->amount = $transaction['amount'];
156
            array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
157
            $Transaction->title = '';
158
            $Transaction->unique_ID = $transaction['unique_id'];
159
            $Transaction->commission = $transaction['commission'];
160
            $date = new \DateTime($transaction['date']);
161
            $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...
162
            // Future use - Only few providers returns these dates values - <PN> - 2017-06-29
163
            if (isset($transaction['click_date']) && !empty($transaction['click_date'])) {
164
                $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...
165
            }
166
            if (isset($transaction['update_date']) && !empty($transaction['update_date'])) {
167
                $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...
168
            }
169
            $Transaction->merchant_ID = $transaction['merchantId'];
170
            $Transaction->campaign_name =  $transaction['merchantName'];
171
            $Transaction->IP =  $transaction['IP'];
172
            $Transaction->approved = false;
173
            if ($Transaction->status==\Oara\Utilities::STATUS_CONFIRMED){
174
                $Transaction->approved = true;
175
            }
176
            $arrResult[] = $Transaction;
177
        }
178
179
        return $arrResult;
180
    }
181
182
    /**
183
     * @param \DateTime $dateFrom
184
     * @param \DateTime $dateTo
185
     * @param int $merchantID
186
     * @return array of Stat
187
     */
188
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
189
    {
190
        // TODO
191
        return array();
192
        /*
193
        $this->_apiClient->setConnectId($this->_username);
194
        $this->_apiClient->setSecretKey($this->_password);
195
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
196
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
197
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
198
        $arrResponse = json_decode($response, true);
199
        $reportItems = $arrResponse['reportItems'];
200
        $Stat = Stat::createInstance();
201
        $Stat->reportItems = $reportItems;
202
203
        return array($Stat);
204
        */
205
    }
206
207
208
    /**
209
     * @param  array $params
210
     *
211
     * @return ProductsResultset
212
     */
213
    public function getProducts(array $params = []): ProductsResultset
214
    {
215
        // TODO: Implement getProducts() method.
216
        throw new \Exception("Not implemented yet");
217
    }
218
219
    public function getTrackingParameter(){
220
        return $this->_tracking_parameter;
221
    }
222
}
223