Completed
Push — master ( 8abc4c...257aca )
by
unknown
01:57
created

Zanox::getStats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
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/Zanox/Zapi/ApiClient.php";
13
14
/**
15
 * Class Zanox
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class Zanox extends AbstractNetwork implements NetworkInterface
19
{
20
    /**
21
     * @var object
22
     */
23
    private $_network = null;
24
    private $_apiClient = null;
25
    private $_username = '';
26
    private $_password = '';
27
28
    /**
29
     * @method __construct
30
     */
31
    public function __construct(string $username, string $password)
32
    {
33
        $this->_network = new \Oara\Network\Publisher\Zanox;
34
        $this->_username = $username;
35
        $this->_password = $password;
36
        $this->_apiClient = \ApiClient::factory(PROTOCOL_JSON);
37
    }
38
39
    /**
40
     * @return bool
41
     */
42
    public function checkLogin() : bool
43
    {
44
        $credentials = array();
45
        $credentials["connectid"] = $this->_username;
46
        $credentials["secretkey"] = $this->_password;
47
        $this->_network->login($credentials);
48
        if ($this->_network->checkConnection()) {
49
            return true;
50
        }
51
52
        return false;
53
    }
54
55
    /**
56
     * @return array of Merchants
57
     */
58
    public function getMerchants() : array
59
    {
60
        $arrResult = array();
61
        $merchantList = $this->_network->getMerchantList();
62
        foreach($merchantList as $merchant) {
63
            $Merchant = Merchant::createInstance();
64
            $Merchant->merchant_ID = $merchant['cid'];
65
            $Merchant->name = $merchant['name'];
66
            $arrResult[] = $Merchant;
67
        }
68
69
        return $arrResult;
70
    }
71
72
    /**
73
     * @param int $merchantID
74
     * @return array of Deal
75
     */
76
    public function getDeals(int $merchantID = 0) : array
77
    {
78
        $this->_apiClient->setConnectId($this->_username);
79
        $this->_apiClient->setSecretKey($this->_password);
80
        $arrResponse = json_decode($this->_apiClient->getAdmedia(), true);
81
        $arrAdmediumItems = $arrResponse['admediumItems']['admediumItem'];
82
        $arrResult = array();
83
        foreach($arrAdmediumItems as $admediumItems) {
84
            $Deal = Deal::createInstance();
85
            $Deal->deal_ID = (int)$admediumItems['@id'];
86
            $Deal->name = $admediumItems['name'];
87
            $Deal->deal_type = $admediumItems['admediumType'];
88
            $Deal->merchant_ID = (int)$admediumItems['program']['@id'];
89
            $Deal->ppv = $admediumItems['trackingLinks']['trackingLink'][0]['ppv'];
90
            $Deal->ppc = $admediumItems['trackingLinks']['trackingLink'][0]['ppc'];
91
            if($merchantID > 0) {
92
                if($merchantID == $admediumItems['program']['@id']) {
93
                    $arrResult[] = $Deal;
94
                }
95
            }
96
            else {
97
                $arrResult[] = $Deal;
98
            }
99
        }
100
101
        return $arrResult;
102
    }
103
104
    /**
105
     * @param \DateTime $dateFrom
106
     * @param \DateTime $dateTo
107
     * @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...
108
     * @return array of Transaction
109
     */
110
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array
111
    {
112
        $arrResult = array();
113
        $transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom);
114
        foreach($transcationList as $transaction) {
115
            $Transaction = Transaction::createInstance();
116
            $Transaction->currency = $transaction['currency'];
117
            $Transaction->status = $transaction['status'];
118
            $Transaction->amount = $transaction['amount'];
119
            $Transaction->custom_ID = $transaction['custom_id'];
120
            $Transaction->title = $transaction['title'];
121
            $Transaction->unique_ID = $transaction['unique_id'];
122
            $Transaction->commission = $transaction['commission'];
123
            $date = new \DateTime($transaction['date']);
124
            $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...
125
            $Transaction->merchant_ID = $transaction['merchantId'];
126
            $Transaction->approved = $transaction['approved'];
127
            $arrResult[] = $Transaction;
128
        }
129
130
        return $arrResult;
131
    }
132
133
    /**
134
     * @param \DateTime $dateFrom
135
     * @param \DateTime $dateTo
136
     * @param int $merchantID
137
     * @return array of Stat
138
     */
139
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
140
    {
141
        return array();
142
143
        /*
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...
144
        $this->_apiClient->setConnectId($this->_username);
145
        $this->_apiClient->setSecretKey($this->_password);
146
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
147
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
148
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
149
        $arrResponse = json_decode($response, true);
150
        $reportItems = $arrResponse['reportItems'];
151
        $Stat = Stat::createInstance();
152
        $Stat->reportItems = $reportItems;
153
154
        return array($Stat);
155
        */
156
    }
157
}
158