Completed
Push — master ( 01b86e...5a74f2 )
by
unknown
04:57
created

LinkShare::getTrackingParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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 LinkShare
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class LinkShare 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    = '';
28
    private $_idSite = '';
29
30
    /**
31
     * @method __construct
32
     */
33 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...
34
    {
35
        $this->_network = new \Oara\Network\Publisher\LinkShare;
36
        $this->_username = $username;
37
        $this->_password = $password;
38
        $this->_password = $password;
39
        $idSite = $this->_idSite;
40
41
        $this->login( $this->_username, $this->_password, $idSite );
42
    }
43
44 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...
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
        $credentials = array();
53
        $credentials["user"] = $this->_username;
54
        $credentials["password"] = $this->_password;
55
        $credentials["idSite"] = $idSite;
56
        $this->_network->login($credentials);
57
        if ($this->_network->checkConnection()) {
58
            $this->_logged = true;
59
        }
60
61
        return $this->_logged;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function checkLogin() : bool
68
    {
69
        return $this->_logged;
70
    }
71
72
    /**
73
     * @return array of Merchants
74
     */
75
    public function getMerchants() : array
76
    {
77
        $arrResult = array();
78
        $merchantList = $this->_network->getMerchantList();
79
        foreach($merchantList as $merchant) {
80
            $Merchant = Merchant::createInstance();
81
            $Merchant->merchant_ID = $merchant['cid'];
82
            $Merchant->name = $merchant['name'];
83
            $arrResult[] = $Merchant;
84
        }
85
86
        return $arrResult;
87
    }
88
89
    /**
90
     * @param int $merchantID
91
     * @return array of Deal
92
     */
93 View Code Duplication
    public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset
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...
94
    {
95
        $arrResult = array();
96
        $arrResponse = $this->_apiClient->getFullEarnings(null, null, null, $this->_username, $this->_password);
97
        foreach($arrResponse as $response) {
98
            $Deal = Deal::createInstance();
99
            $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...
100
            $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...
101
            $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...
102
            $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...
103
            $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...
104
            $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...
105
            $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...
106
            $Deal->merchant_ID = $response->programID;
107
            $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...
108
            $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...
109
            $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...
110
            $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...
111
            if($merchantID > 0) {
112
                if($merchantID == $response->programID) {
113
                    $arrResult[] = $Deal;
114
                }
115
            }
116
            else {
117
                $arrResult[] = $Deal;
118
            }
119
        }
120
121
        return $arrResult;
122
    }
123
124
    /**
125
     * @param \DateTime $dateFrom
126
     * @param \DateTime $dateTo
127
     * @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...
128
     * @return array of Transaction
129
     */
130 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...
131
    {
132
133
        $arrResult = array();
134
        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
135
        foreach($transactionList as $transaction) {
136
            $Transaction = Transaction::createInstance();
137
            if (isset($transaction['currency']) && !empty($transaction['currency'])) {
138
                $Transaction->currency = $transaction['currency'];
139
            } else {
140
                $Transaction->currency = "EUR";
141
            }
142
            $Transaction->status = $transaction['status'];
143
            $Transaction->amount = $transaction['amount'];
144
            array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
145
            $Transaction->title = '';
146
            $Transaction->unique_ID = $transaction['unique_id'];
147
            $Transaction->commission = $transaction['commission'];
148
            $date = new \DateTime($transaction['date']);
149
            $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...
150
            // Future use - Only few providers returns these dates values - <PN> - 2017-06-29
151
            if (isset($transaction['click_date']) && !empty($transaction['click_date'])) {
152
                $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...
153
            }
154
            if (isset($transaction['update_date']) && !empty($transaction['update_date'])) {
155
                $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...
156
            }
157
            $Transaction->merchant_ID = $transaction['merchantId'];
158
            $Transaction->campaign_name =  $transaction['merchantName'];
159
            $Transaction->IP =  $transaction['IP'];
160
            $Transaction->approved = false;
161
            if ($Transaction->status==\Oara\Utilities::STATUS_CONFIRMED){
162
                $Transaction->approved = true;
163
            }
164
            $arrResult[] = $Transaction;
165
        }
166
167
        return $arrResult;
168
    }
169
170
    /**
171
     * @param \DateTime $dateFrom
172
     * @param \DateTime $dateTo
173
     * @param int $merchantID
174
     * @return array of Stat
175
     */
176
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
177
    {
178
        // TODO
179
        return array();
180
        /*
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...
181
        $this->_apiClient->setConnectId($this->_username);
182
        $this->_apiClient->setSecretKey($this->_password);
183
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
184
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
185
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
186
        $arrResponse = json_decode($response, true);
187
        $reportItems = $arrResponse['reportItems'];
188
        $Stat = Stat::createInstance();
189
        $Stat->reportItems = $reportItems;
190
191
        return array($Stat);
192
        */
193
    }
194
195
196
    /**
197
     * @param  array $params
198
     *
199
     * @return ProductsResultset
200
     */
201
    public function getProducts(array $params = []): ProductsResultset
202
    {
203
        // TODO: Implement getProducts() method.
204
        throw new \Exception("Not implemented yet");
205
    }
206
207
    public function getTrackingParameter(){
208
        return $this->_tracking_parameter;
209
    }
210
}
211