Completed
Push — master ( 2bbb6c...4f5d4f )
by
unknown
01:47
created

NetAffiliation::getStats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
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
/**
13
 * Class NetAffiliation
14
 * @package Padosoft\AffiliateNetwork\Networks
15
 */
16
class NetAffiliation extends AbstractNetwork implements NetworkInterface
17
{
18
    /**
19
     * @var object
20
     */
21
    private $_network = null;
22
    private $_username = '';
23
    private $_password = '';
24
25
    /**
26
     * @method __construct
27
     */
28
    public function __construct(string $username, string $password)
29
    {
30
        $this->_network = new \Oara\Network\Publisher\NetAffiliation;
31
        $this->_username = $username;
32
        $this->_password = $password;
33
    }
34
35
    /**
36
     * @return bool
37
     */
38 View Code Duplication
    public function checkLogin() : 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...
39
    {
40
        $credentials = array();
41
        $credentials["user"] = $this->_username;
42
        $credentials["password"] = $this->_password;
43
        $this->_network->login($credentials);
44
        if ($this->_network->checkConnection()) {
45
            return true;
46
        }
47
48
        return false;
49
    }
50
51
    /**
52
     * @return array of Merchants
53
     */
54 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...
55
    {
56
        $arrResult = array();
57
        $merchantList = $this->_network->getMerchantList();
58
        foreach($merchantList as $merchant) {
59
            $Merchant = Merchant::createInstance();
60
            $Merchant->merchant_ID = $merchant['cid'];
61
            $Merchant->name = $merchant['name'];
62
            $arrResult[] = $Merchant;
63
        }
64
65
        return $arrResult;
66
    }
67
68
    /**
69
     * @param int $merchantID
70
     * @return array of Deal
71
     */
72
    public function getDeals(int $merchantID = 0) : array
73
    {
74
        $url = 'http://flux.netaffiliation.com/rsscp.php?sec=417771E811773642F4E017';
75
        $xml = file_get_contents($url);
76
        $arrResult = array();
77
        $arrResponse = xml2array($xml);
78
        if(!is_array($arrResponse) || count($arrResponse) <= 0) {
79
            return $arrResult;
80
        }
81
82
        $arrItems = $arrResponse['rss']['channel']['item'];
83
        foreach($arrItems as $item) {
84
            $Deal = Deal::createInstance();
85
            $Deal->merchant_ID = $item['idcamp'];
86
            $Deal->code = $item['code'];
87
            $Deal->name = $item['title'];
88
            $Deal->startDate = $item['startdate'];
89
            $Deal->endDate = $item['enddate'];
90
            $Deal->description = $item['description'];
91
            $Deal->url = $item['link'];
92
            if($merchantID > 0) {
93
                if($merchantID == $item['idcamp']) {
94
                    $arrResult[] = $Deal;
95
                }
96
            }
97
            else {
98
                $arrResult[] = $Deal;
99
            }
100
        }
101
102
        return $arrResult;
103
104
    }
105
106
    /**
107
     * @param \DateTime $dateFrom
108
     * @param \DateTime $dateTo
109
     * @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...
110
     * @return array of Transaction
111
     */
112 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...
113
    {
114
        $arrResult = array();
115
        $transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom);
116
        foreach($transcationList as $transaction) {
117
            $Transaction = Transaction::createInstance();
118
            $Transaction->status = $transaction['status'];
119
            $Transaction->amount = $transaction['amount'];
120
            $Transaction->custom_ID = $transaction['custom_id'];
121
            $Transaction->title = $transaction['title'];
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
        /*
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...
143
        $this->_apiClient->setConnectId($this->_username);
144
        $this->_apiClient->setSecretKey($this->_password);
145
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
146
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
147
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
148
        $arrResponse = json_decode($response, true);
149
        $reportItems = $arrResponse['reportItems'];
150
        $Stat = Stat::createInstance();
151
        $Stat->reportItems = $reportItems;
152
153
        return array($Stat);
154
        */
155
    }
156
157
}
158