Completed
Push — master ( 117943...1799df )
by
unknown
06:31
created

Publicideas::getTrackingParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
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\Merchant;
7
use Padosoft\AffiliateNetwork\Stat;
8
use Padosoft\AffiliateNetwork\Deal;
9
use Padosoft\AffiliateNetwork\AbstractNetwork;
10
use Padosoft\AffiliateNetwork\NetworkInterface;
11
use Padosoft\AffiliateNetwork\DealsResultset;
12
13
// require "../vendor/fubralimited/php-oara/Oara/Network/Publisher/Publicideas/Zapi/ApiClient.php";
14
15
/**
16
 * Class Publicideas
17
 * @package Padosoft\AffiliateNetwork\Networks
18
 */
19
class Publicideas extends AbstractNetwork implements NetworkInterface
20
{
21
    /**
22
     * @var object
23
     */
24
    private $_network = null;
25
    private $_username = '';
26
    private $_password = '';
27
    private $_token = '';
28
    private $_partner_id = '';
29
    private $_logged    = false;
30
    protected $_tracking_parameter    = 'cb';
31
    /**
32
     * @method __construct
33
     */
34
    public function __construct(string $username, string $password, string $token='',string $partner_id='')
35
    {
36
        $this->_network = new \Oara\Network\Publisher\Publicidees;
37
        $this->_username = $username;
38
        $this->_password = $password;
39
        $this->_token = $token;
40
        $this->_partner_id = $partner_id;
41
        $this->login( $this->_username, $this->_password );
42
    }
43
44 View Code Duplication
    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...
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;
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
        $this->_network->login($credentials);
56
        if ($this->_network->checkConnection()) {
57
            $this->_logged = true;
58
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
    public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset
94
    {
95
        $url = 'http://publisher.publicideas.com/xmlProgAff.php?partid='.$this->_partner_id.'&key='.$this->_token.'&noDownload=yes';
96
        $xml = file_get_contents($url);
97
        $arrResult = array();
98
        $arrResponse = xml2array($xml);
99
        if(!is_array($arrResponse) || count($arrResponse) <= 0) {
100
            return $arrResult;
101
        }
102
        $arrPartner = $arrResponse['partner'];
103
        echo '<pre>';
104
        var_dump($arrPartner);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($arrPartner); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
105
        echo '</pre>';
106
107
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
108
        foreach($arrPartner as $partner) {
109
            $Deal = Deal::createInstance();
110
            $Deal->program_name;
111
            if($merchantID > 0) {
112
                if($merchantID == $admediumItems['program']['@id']) {
113
                    $arrResult[] = $Deal;
114
                }
115
            }
116
            else {
117
                $arrResult[] = $Deal;
118
            }
119
        }
120
        */
121
122
123
124
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
125
        $this->_apiClient->setConnectId($this->_username);
126
        $this->_apiClient->setSecretKey($this->_password);
127
        $arrResponse = json_decode($this->_apiClient->getAdmedia(), true);
128
        $arrAdmediumItems = $arrResponse['admediumItems']['admediumItem'];
129
        $arrResult = array();
130
        foreach($arrAdmediumItems as $admediumItems) {
131
            $Deal = Deal::createInstance();
132
            $Deal->deal_ID = (int)$admediumItems['@id'];
133
            $Deal->name = $admediumItems['name'];
134
            $Deal->deal_type = $admediumItems['admediumType'];
135
            $Deal->merchant_ID = (int)$admediumItems['program']['@id'];
136
            $Deal->ppv = $admediumItems['trackingLinks']['trackingLink'][0]['ppv'];
137
            $Deal->ppc = $admediumItems['trackingLinks']['trackingLink'][0]['ppc'];
138
            if($merchantID > 0) {
139
                if($merchantID == $admediumItems['program']['@id']) {
140
                    $arrResult[] = $Deal;
141
                }
142
            }
143
            else {
144
                $arrResult[] = $Deal;
145
            }
146
        }
147
148
        return $arrResult;
149
        */
150
151
        return array();
152
153
    }
154
155
    /**
156
     * @param \DateTime $dateFrom
157
     * @param \DateTime $dateTo
158
     * @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...
159
     * @return array of Transaction
160
     */
161
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array
162
    {
163
        if (!$this->checkLogin()) {
164
            return array();
165
        }
166
        $arrResult = array();
167 View Code Duplication
        if (count( $arrMerchantID ) < 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
168
            $merchants = $this->getMerchants();
169
            foreach ($merchants as $merchant) {
170
                $arrMerchantID[$merchant->merchant_ID] = ['cid' => $merchant->merchant_ID, 'name' => $merchant->name];
171
            }
172
        }
173
        $transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom);
174
        foreach($transcationList as $transaction) {
175
            $Transaction = Transaction::createInstance();
176
            $Transaction->currency = $transaction['currency'];
177
            $Transaction->status = $transaction['status'];
178
            $Transaction->amount = $transaction['amount'];
179
            $Transaction->custom_ID = $transaction['custom_id'];
180
            $Transaction->title = $transaction['title'];
181
            $Transaction->unique_ID = $transaction['unique_id'];
182
            $Transaction->commission = $transaction['commission'];
183
            $date = new \DateTime($transaction['date']);
184
            $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...
185
            $Transaction->merchant_ID = $transaction['merchantId'];
186
            $Transaction->approved = $transaction['approved'];
187
            $arrResult[] = $Transaction;
188
        }
189
190
        return $arrResult;
191
    }
192
193
    /**
194
     * @param \DateTime $dateFrom
195
     * @param \DateTime $dateTo
196
     * @param int $merchantID
197
     * @return array of Stat
198
     */
199
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
200
    {
201
        return array();
202
        /*
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...
203
        $this->_apiClient->setConnectId($this->_username);
204
        $this->_apiClient->setSecretKey($this->_password);
205
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
206
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
207
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
208
        $arrResponse = json_decode($response, true);
209
        $reportItems = $arrResponse['reportItems'];
210
        $Stat = Stat::createInstance();
211
        $Stat->reportItems = $reportItems;
212
213
        return array($Stat);
214
        */
215
    }
216
217
    public function getTrackingParameter(){
218
        return $this->_tracking_parameter;
219
    }
220
}
221