Completed
Push — master ( 60378a...c53dc7 )
by
unknown
05:02
created

Publicideas::getDeals()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 61
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 9.5147
c 0
b 0
f 0
cc 3
eloc 12
nc 2
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
12
// require "../vendor/fubralimited/php-oara/Oara/Network/Publisher/Publicideas/Zapi/ApiClient.php";
13
14
/**
15
 * Class Publicideas
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class Publicideas extends AbstractNetwork implements NetworkInterface
19
{
20
    /**
21
     * @var object
22
     */
23
    private $_network = null;
24
    private $_username = '';
25
    private $_password = '';
26
    private $_token = '';
27
    private $_partner_id = '';
28
29
    /**
30
     * @method __construct
31
     */
32
    public function __construct(string $username, string $password, string $token, string $partner_id)
33
    {
34
        $this->_network = new \Oara\Network\Publisher\Publicidees;
35
        $this->_username = $username;
36
        $this->_password = $password;
37
        $this->_token = $token;
38
        $this->_partner_id = $partner_id;
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function checkLogin() : bool
45
    {
46
        $credentials = array();
47
        $credentials["user"] = $this->_username;
48
        $credentials["password"] = $this->_password;
49
        $this->_network->login($credentials);
50
51
        var_dump($this->_network->checkConnection());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($this->_network->checkConnection()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
52
53
        if ($this->_network->checkConnection()) {
54
            return true;
55
        }
56
57
        return false;
58
    }
59
60
    /**
61
     * @return array of Merchants
62
     */
63
    public function getMerchants() : array
64
    {
65
        $arrResult = array();
66
        $merchantList = $this->_network->getMerchantList();
67
        foreach($merchantList as $merchant) {
68
            $Merchant = Merchant::createInstance();
69
            $Merchant->merchant_ID = $merchant['cid'];
70
            $Merchant->name = $merchant['name'];
71
            $arrResult[] = $Merchant;
72
        }
73
74
        return $arrResult;
75
    }
76
77
    /**
78
     * @param int $merchantID
79
     * @return array of Deal
80
     */
81
    public function getDeals(int $merchantID = 0) : array
82
    {
83
        $url = 'http://publisher.publicideas.com/xmlProgAff.php?partid='.$this->_partner_id.'&key='.$this->_token.'&noDownload=yes';
84
        $xml = file_get_contents($url);
85
        $arrResult = array();
86
        $arrResponse = xml2array($xml);
87
        if(!is_array($arrResponse) || count($arrResponse) <= 0) {
88
            return $arrResult;
89
        }
90
        $arrPartner = $arrResponse['partner'];
91
        echo '<pre>';
92
        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...
93
        echo '</pre>';
94
95
        /*
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...
96
        foreach($arrPartner as $partner) {
97
            $Deal = Deal::createInstance();
98
            $Deal->program_name;
99
            if($merchantID > 0) {
100
                if($merchantID == $admediumItems['program']['@id']) {
101
                    $arrResult[] = $Deal;
102
                }
103
            }
104
            else {
105
                $arrResult[] = $Deal;
106
            }
107
        }
108
        */
109
110
111
112
        /*
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...
113
        $this->_apiClient->setConnectId($this->_username);
114
        $this->_apiClient->setSecretKey($this->_password);
115
        $arrResponse = json_decode($this->_apiClient->getAdmedia(), true);
116
        $arrAdmediumItems = $arrResponse['admediumItems']['admediumItem'];
117
        $arrResult = array();
118
        foreach($arrAdmediumItems as $admediumItems) {
119
            $Deal = Deal::createInstance();
120
            $Deal->deal_ID = (int)$admediumItems['@id'];
121
            $Deal->name = $admediumItems['name'];
122
            $Deal->deal_type = $admediumItems['admediumType'];
123
            $Deal->merchant_ID = (int)$admediumItems['program']['@id'];
124
            $Deal->ppv = $admediumItems['trackingLinks']['trackingLink'][0]['ppv'];
125
            $Deal->ppc = $admediumItems['trackingLinks']['trackingLink'][0]['ppc'];
126
            if($merchantID > 0) {
127
                if($merchantID == $admediumItems['program']['@id']) {
128
                    $arrResult[] = $Deal;
129
                }
130
            }
131
            else {
132
                $arrResult[] = $Deal;
133
            }
134
        }
135
136
        return $arrResult;
137
        */
138
139
       return array();
140
141
    }
142
143
    /**
144
     * @param \DateTime $dateFrom
145
     * @param \DateTime $dateTo
146
     * @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...
147
     * @return array of Transaction
148
     */
149 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...
150
    {
151
        $arrResult = array();
152
        $transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom);
153
        foreach($transcationList as $transaction) {
154
            $Transaction = Transaction::createInstance();
155
            $Transaction->currency = $transaction['currency'];
156
            $Transaction->status = $transaction['status'];
157
            $Transaction->amount = $transaction['amount'];
158
            $Transaction->custom_ID = $transaction['custom_id'];
159
            $Transaction->title = $transaction['title'];
160
            $Transaction->unique_ID = $transaction['unique_id'];
161
            $Transaction->commission = $transaction['commission'];
162
            $date = new \DateTime($transaction['date']);
163
            $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...
164
            $Transaction->merchant_ID = $transaction['merchantId'];
165
            $Transaction->approved = $transaction['approved'];
166
            $arrResult[] = $Transaction;
167
        }
168
169
        return $arrResult;
170
    }
171
172
    /**
173
     * @param \DateTime $dateFrom
174
     * @param \DateTime $dateTo
175
     * @param int $merchantID
176
     * @return array of Stat
177
     */
178
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
179
    {
180
        return array();
181
        /*
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...
182
        $this->_apiClient->setConnectId($this->_username);
183
        $this->_apiClient->setSecretKey($this->_password);
184
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
185
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
186
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
187
        $arrResponse = json_decode($response, true);
188
        $reportItems = $arrResponse['reportItems'];
189
        $Stat = Stat::createInstance();
190
        $Stat->reportItems = $reportItems;
191
192
        return array($Stat);
193
        */
194
    }
195
}
196