Completed
Push — master ( 11675b...e88f05 )
by
unknown
01:43
created

WebGains::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
/**
13
 * Class WebGains
14
 * @package Padosoft\AffiliateNetwork\Networks
15
 */
16
class WebGains extends AbstractNetwork implements NetworkInterface
17
{
18
    /**
19
     * @var object
20
     */
21
    private $_network = null;
22
    private $_username = '';
23
    private $_password = '';
24
    private $_apiClient = null;
25
26
    /**
27
     * @method __construct
28
     */
29
    public function __construct(string $username, string $password)
30
    {
31
        $this->_network = new \Oara\Network\Publisher\WebGains;
32
        $this->_username = $username;
33
        $this->_password = $password;
34
        $apiUrl = 'http://ws.webgains.com/aws.php';
35
        $this->_apiClient = new \SoapClient($apiUrl,
36
            array('login' => $this->_username,
37
                'encoding' => 'UTF-8',
38
                'password' => $this->_password,
39
                'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
40
                'soap_version' => SOAP_1_1)
41
        );
42
    }
43
44
    /**
45
     * @return bool
46
     */
47 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...
48
    {
49
        $credentials = array();
50
        $credentials["user"] = $this->_username;
51
        $credentials["password"] = $this->_password;
52
        $this->_network->login($credentials);
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
        $arrResult = array();
84
        $arrResponse = $this->_apiClient->getFullEarnings(null, null, null, $this->_username, $this->_password);
85
        foreach($arrResponse as $response) {
86
            $Deal = Deal::createInstance();
87
            $Deal->transaction_ID = $response->transactionID;
0 ignored issues
show
Bug introduced by
The property transaction_ID does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
88
            $Deal->affiliate_ID = $response->affiliate_ID;
0 ignored issues
show
Bug introduced by
The property affiliate_ID does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
89
            $Deal->campaign_name = $response->campaignName;
0 ignored issues
show
Bug introduced by
The property campaign_name does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
90
            $Deal->campaign_ID = $response->campaignID;
0 ignored issues
show
Bug introduced by
The property campaign_ID does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
91
            $date = new \DateTime($response->date);
0 ignored issues
show
Unused Code introduced by
$date is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
92
            $Deal->date = $response->date;
0 ignored issues
show
Bug introduced by
The property date does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
93
            $Deal->programName = $response->program_name;
0 ignored issues
show
Bug introduced by
The property programName does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
94
            $Deal->merchant_ID = $response->programID;
95
            $Deal->commission = $response->commission;
0 ignored issues
show
Bug introduced by
The property commission does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
96
            $Deal->amount = $response->saleValue;
0 ignored issues
show
Bug introduced by
The property amount does not seem to exist. Did you mean discount_amount?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
97
            $Deal->status = $response->status;
0 ignored issues
show
Bug introduced by
The property status does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
98
            $Deal->referrer = $response->referrer;
0 ignored issues
show
Bug introduced by
The property referrer does not seem to exist in Padosoft\AffiliateNetwork\Deal.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
99
            if($merchantID > 0) {
100
                if($merchantID == $response->programID) {
101
                    $arrResult[] = $Deal;
102
                }
103
            }
104
            else {
105
                $arrResult[] = $Deal;
106
            }
107
        }
108
109
        return $arrResult;
110
    }
111
112
    /**
113
     * @param \DateTime $dateFrom
114
     * @param \DateTime $dateTo
115
     * @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...
116
     * @return array of Transaction
117
     */
118 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...
119
    {
120
        $arrResult = array();
121
        $transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom);
122
        foreach($transcationList as $transaction) {
123
            $Transaction = Transaction::createInstance();
124
            $Transaction->currency = $transaction['currency'];
125
            $Transaction->status = $transaction['status'];
126
            $Transaction->amount = $transaction['amount'];
127
            $Transaction->custom_ID = $transaction['custom_id'];
128
            $Transaction->title = $transaction['title'];
129
            $Transaction->unique_ID = $transaction['unique_id'];
130
            $Transaction->commission = $transaction['commission'];
131
            $date = new \DateTime($transaction['date']);
132
            $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...
133
            $Transaction->merchant_ID = $transaction['merchantId'];
134
            $Transaction->approved = $transaction['approved'];
135
            $arrResult[] = $Transaction;
136
        }
137
138
        return $arrResult;
139
    }
140
141
    /**
142
     * @param \DateTime $dateFrom
143
     * @param \DateTime $dateTo
144
     * @param int $merchantID
145
     * @return array of Stat
146
     */
147
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
148
    {
149
        return array();
150
        /*
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...
151
        $this->_apiClient->setConnectId($this->_username);
152
        $this->_apiClient->setSecretKey($this->_password);
153
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
154
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
155
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
156
        $arrResponse = json_decode($response, true);
157
        $reportItems = $arrResponse['reportItems'];
158
        $Stat = Stat::createInstance();
159
        $Stat->reportItems = $reportItems;
160
161
        return array($Stat);
162
        */
163
    }
164
}
165