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

TradeDoubler::getStats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
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 TradeDoubler
14
 * @package Padosoft\AffiliateNetwork\Networks
15
 */
16
class TradeDoubler extends AbstractNetwork implements NetworkInterface
17
{
18
    /**
19
     * @var object
20
     */
21
    private $_network = null;
22
    private $_apiClient = null;
23
    private $_username = '';
24
    private $_password = '';
25
26
    /**
27
     * @method __construct
28
     */
29
    public function __construct(string $username, string $password)
30
    {
31
        $this->_network = new \Oara\Network\Publisher\TradeDoubler;
32
        $this->_username = $username;
33
        $this->_password = $password;
34
        $this->_apiClient = null;
35
    }
36
37
    /**
38
     * @return bool
39
     */
40 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...
41
    {
42
        $credentials = array();
43
        $credentials["user"] = $this->_username;
44
        $credentials["password"] = $this->_password;
45
        $this->_network->login($credentials);
46
        if ($this->_network->checkConnection()) {
47
            return true;
48
        }
49
50
        return false;
51
    }
52
53
    /**
54
     * @return array of Merchants
55
     */
56 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...
57
    {
58
        $arrResult = array();
59
        $merchantList = $this->_network->getMerchantList();
60
        foreach($merchantList as $merchant) {
61
            $Merchant = Merchant::createInstance();
62
            $Merchant->merchant_ID = $merchant['cid'];
63
            $Merchant->name = $merchant['name'];
64
            $arrResult[] = $Merchant;
65
        }
66
67
        return $arrResult;
68
    }
69
70
    /**
71
     * @param int $merchantID
72
     * @return array of Deal
73
     */
74
    public function getDeals(int $merchantID = 0) : array
75
    {
76
        $arrResult = array();
77
        $jsonVouchers = file_get_contents("https://api.tradedoubler.com/1.0/vouchers.json;voucherTypeId=1?token=".$_ENV['TRADEDOUBLER_TOKEN']);
78
        $arrVouchers = json_decode($jsonVouchers, true);
79
80
        foreach($arrVouchers as $vouchers) {
81
            $Deal = Deal::createInstance();
82
            $Deal->deal_ID = $vouchers['id'];
83
            $Deal->merchant_ID = $vouchers['programId'];
84
            $Deal->merchant_name = $vouchers['programName'];
85
            $Deal->code = $vouchers['code'];
86
            $Deal->name = $vouchers['title'];
87
            $Deal->short_description = $vouchers['shortDescription'];
88
            $Deal->description = $vouchers['description'];
89
            $Deal->deal_type = $vouchers['voucherTypeId'];
90
            $Deal->default_track_uri = $vouchers['defaultTrackUri'];
91
            $Deal->default_track_uri = $vouchers['landingUrl'];
92
            $Deal->discount_amount = $vouchers['discountAmount'];
93
            $Deal->is_percentage = $vouchers['isPercentage'];
94
            $Deal->currency_initial = $vouchers['currencyId'];
95
            $Deal->logo_path = $vouchers['logoPath'];
96
            if($merchantID > 0) {
97
                if($vouchers['programId'] == $merchantID) {
98
                    $arrResult[] = $Deal;
99
                }
100
            }
101
            else {
102
                $arrResult[] = $Deal;
103
            }
104
        }
105
106
        return $arrResult;
107
    }
108
109
    /**
110
     * @param \DateTime $dateFrom
111
     * @param \DateTime $dateTo
112
     * @param int $merchantID
0 ignored issues
show
Bug introduced by
There is no parameter named $merchantID. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
113
     * @return array of Transaction
114
     */
115 View Code Duplication
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchant = 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...
116
    {
117
        $arrResult = array();
118
        $transcationList = $this->_network->getTransactionList($arrMerchant, $dateFrom, $dateTo);
119
        foreach($transcationList as $transaction) {
120
            $Transaction = Transaction::createInstance();
121
            $Transaction->merchant_ID = $transaction['merchantId'];
122
            $date = new \DateTime($transaction['date']);
123
            $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...
124
            $Transaction->unique_ID = $transaction['unique_id'];
125
            $Transaction->custom_ID = $transaction['custom_id'];
126
            $Transaction->status = $transaction['status'];
127
            $Transaction->amount = $transaction['amount'];
128
            $Transaction->commission = $transaction['commission'];
129
            $arrResult[] = $Transaction;
130
        }
131
132
        return $arrResult;
133
    }
134
135
    /**
136
     * @param \DateTime $dateFrom
137
     * @param \DateTime $dateTo
138
     * @param int $merchantID
139
     * @return array of Stat
140
     */
141
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
142
    {
143
        return array();        
144
    }
145
}
146