Completed
Push — master ( 6f4a85...60378a )
by
unknown
02:04
created

Publicideas::getMerchants()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
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
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
27
    /**
28
     * @method __construct
29
     */
30
    public function __construct(string $username, string $password)
31
    {
32
        $this->_network = new \Oara\Network\Publisher\Publicidees;
33
        $this->_username = $username;
34
        $this->_password = $password;
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
    public function getMerchants() : array
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 View Code Duplication
    public function getDeals(int $merchantID = 0) : 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...
75
    {
76
        $this->_apiClient->setConnectId($this->_username);
0 ignored issues
show
Bug introduced by
The property _apiClient does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
77
        $this->_apiClient->setSecretKey($this->_password);
78
        $arrResponse = json_decode($this->_apiClient->getAdmedia(), true);
79
        $arrAdmediumItems = $arrResponse['admediumItems']['admediumItem'];
80
        $arrResult = array();
81
        foreach($arrAdmediumItems as $admediumItems) {
82
            $Deal = Deal::createInstance();
83
            $Deal->deal_ID = (int)$admediumItems['@id'];
84
            $Deal->name = $admediumItems['name'];
85
            $Deal->deal_type = $admediumItems['admediumType'];
86
            $Deal->merchant_ID = (int)$admediumItems['program']['@id'];
87
            $Deal->ppv = $admediumItems['trackingLinks']['trackingLink'][0]['ppv'];
88
            $Deal->ppc = $admediumItems['trackingLinks']['trackingLink'][0]['ppc'];
89
            if($merchantID > 0) {
90
                if($merchantID == $admediumItems['program']['@id']) {
91
                    $arrResult[] = $Deal;
92
                }
93
            }
94
            else {
95
                $arrResult[] = $Deal;
96
            }
97
        }
98
99
        return $arrResult;
100
    }
101
102
    /**
103
     * @param \DateTime $dateFrom
104
     * @param \DateTime $dateTo
105
     * @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...
106
     * @return array of Transaction
107
     */
108 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...
109
    {
110
        $arrResult = array();
111
        $transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom);
112
        foreach($transcationList as $transaction) {
113
            $Transaction = Transaction::createInstance();
114
            $Transaction->currency = $transaction['currency'];
115
            $Transaction->status = $transaction['status'];
116
            $Transaction->amount = $transaction['amount'];
117
            $Transaction->custom_ID = $transaction['custom_id'];
118
            $Transaction->title = $transaction['title'];
119
            $Transaction->unique_ID = $transaction['unique_id'];
120
            $Transaction->commission = $transaction['commission'];
121
            $date = new \DateTime($transaction['date']);
122
            $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...
123
            $Transaction->merchant_ID = $transaction['merchantId'];
124
            $Transaction->approved = $transaction['approved'];
125
            $arrResult[] = $Transaction;
126
        }
127
128
        return $arrResult;
129
    }
130
131
    /**
132
     * @param \DateTime $dateFrom
133
     * @param \DateTime $dateTo
134
     * @param int $merchantID
135
     * @return array of Stat
136
     */
137
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
138
    {
139
        return array();
140
        /*
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...
141
        $this->_apiClient->setConnectId($this->_username);
142
        $this->_apiClient->setSecretKey($this->_password);
143
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
144
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
145
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
146
        $arrResponse = json_decode($response, true);
147
        $reportItems = $arrResponse['reportItems'];
148
        $Stat = Stat::createInstance();
149
        $Stat->reportItems = $reportItems;
150
151
        return array($Stat);
152
        */
153
    }
154
}
155