Completed
Push — master ( 4f5d4f...3a337c )
by
unknown
01:34
created

Effiliation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
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/Effiliation/Zapi/ApiClient.php";
13
14
/**
15
 * Class Effiliation
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class Effiliation extends AbstractNetwork implements NetworkInterface
19
{
20
    /**
21
     * @var object
22
     */
23
    private $_network = null;
24
    private $_apiClient = null;
25
    private $_password = '';
26
27
    /**
28
     * @method __construct
29
     */
30
    public function __construct(string $password)
31
    {
32
        $this->_network = new \Oara\Network\Publisher\Effiliation;
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["apipassword"] = $this->_password;
44
        $this->_network->login($credentials);
45
        if ($this->_network->checkConnection()) {
46
            return true;
47
        }
48
49
        return false;
50
    }
51
52
    /**
53
     * @return array of Merchants
54
     */
55
    public function getMerchants() : array
56
    {
57
        $arrResult = array();
58
        $url = 'http://api.effiliation.com/apiv2/programs.xml?key=' . $this->_password . "&filter=all";
59
        $content = @\file_get_contents($url);
60
        $xml = \simplexml_load_string($content, null, LIBXML_NOERROR | LIBXML_NOWARNING);
61
        foreach ($xml->program as $merchant) {
62
            $Merchant = Merchant::createInstance();
63
            $Merchant->merchant_ID = (string)$merchant->id_programme;
0 ignored issues
show
Documentation Bug introduced by
The property $merchant_ID was declared of type integer, but (string) $merchant->id_programme is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
64
            $Merchant->name = (string)$merchant->nom;
65
            $arrResult[] = $Merchant;
66
        }
67
68
        return $arrResult;
69
    }
70
71
    /**
72
     * @param int $merchantID
73
     * @return array of Deal
74
     */
75
    public function getDeals(int $merchantID = 0) : array
76
    {
77
        $url = 'http://apiv2.effiliation.com/apiv2/programs.json?filter=mines&key='.$this->_password;
78
        $json = file_get_contents($url);
79
        $arrResult = array();
80
        $arrResponse = json_decode($json, true);
81
        if(!is_array($arrResponse) || count($arrResponse) <= 0) {
82
            return $arrResult;
83
        }
84
        $arrPrograms = $arrResponse['programs'];
85 View Code Duplication
        foreach($arrPrograms as $item) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
86
            $Deal = Deal::createInstance();
87
            $Deal->merchant_ID = $item['id_programme'];
88
            $Deal->code = $item['code'];
89
            $Deal->name = $item['nom'];
90
            $Deal->startDate = $item['date_debut'];
91
            $Deal->description = $item['description'];
92
            $Deal->url = $item['url_tracke'];
93
            if($merchantID > 0) {
94
                if($merchantID == $item['id_programme']) {
95
                    $arrResult[] = $Deal;
96
                }
97
            }
98
            else {
99
                $arrResult[] = $Deal;
100
            }
101
        }
102
103
        return $arrResult;
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
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array
113
    {
114
        $arrResult = array();
115
        $transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom);
116
        foreach($transcationList as $transaction) {
117
            $Transaction = Transaction::createInstance();
118
            $Transaction->merchant_ID = $transaction['merchantId'];
119
            $date = new \DateTime($transaction['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...
120
            $Transaction->unique_ID = $transaction['unique_id'];
121
            $Transaction->custom_ID = $transaction['custom_id'];
122
            $Transaction->status = $transaction['status'];
123
            $Transaction->amount = $transaction['amount'];
124
            $Transaction->commission = $transaction['commission'];
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