Completed
Push — master ( 50cf04...fd7959 )
by
unknown
02:43
created

Brandreward::getStats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Padosoft\AffiliateNetwork\Networks;
4
5
use Padosoft\AffiliateNetwork\Transaction;
6
use Padosoft\AffiliateNetwork\DealsResultset;
7
use Padosoft\AffiliateNetwork\Merchant;
8
use Padosoft\AffiliateNetwork\Stat;
9
use Padosoft\AffiliateNetwork\Deal;
10
use Padosoft\AffiliateNetwork\AbstractNetwork;
11
use Padosoft\AffiliateNetwork\NetworkInterface;
12
use Padosoft\AffiliateNetwork\ProductsResultset;
13
14
/**
15
 * Class Brandreward
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18 View Code Duplication
class Brandreward extends AbstractNetwork implements NetworkInterface
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
    /**
21
     * @var object
22
     */
23
    private $_network = null;
24
    private $_username = '';
25
    private $_password = '';
26
    private $_idSite = '';
27
28
    /**
29
     * @method __construct
30
     */
31
    public function __construct(string $username, string $password, string $idSite='')
32
    {
33
        $this->_network = new \Oara\Network\Publisher\Brandreward;
34
        $this->_username = $username;
35
        $this->_password = $password;
36
        $this->_idSite = $idSite;
37
38
        $this->login( $this->_username, $this->_password, $idSite );
39
    }
40
41
    public function login(string $username, string $password,string $idSite=''): bool{
42
        $this->_logged = false;
0 ignored issues
show
Bug introduced by
The property _logged 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...
43
        if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) {
44
45
            return false;
46
        }
47
        $this->_username = $username;
48
        $this->_password = $password;
49
        $this->_idSite = $idSite;
50
        $credentials = array();
51
        $credentials["user"] = $this->_username;
52
        $credentials["password"] = $this->_password;
53
        $credentials["idSite"] = $this->_idSite;
54
        $this->_network->login($credentials);
55
        if ($this->_network->checkConnection()) {
56
            $this->_logged = true;
57
        }
58
59
        return $this->_logged;
60
    }
61
62
    /**
63
     * @return bool
64
     */
65
    public function checkLogin() : bool
66
    {
67
        return $this->_logged;
68
    }
69
70
    /**
71
	 * @return array of Merchants
72
	 * @throws \Exception
73
	 */
74
    public function getMerchants() : array
75
    {
76
        throw new \Exception("Not implemented yet");
77
    }
78
79
    /**
80
	 * @param null $merchantID
81
	 * @param int $page
82
	 * @param int $items_per_page
83
	 * @return DealsResultset  array of Deal
84
	 * @throws \Exception
85
	 */
86
    public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=100 ): DealsResultset
87
    {
88
        throw new \Exception("Not implemented yet");
89
90
    }
91
92
   	/**
93
	 * @param \DateTime $dateFrom
94
	 * @param \DateTime $dateTo
95
	 * @param array $arrMerchantID
96
	 * @return array of Transaction
97
	 * @throws \Exception
98
	 */
99
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array
100
    {
101
102
        $arrResult = array();
103
        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
104
        foreach($transactionList as $transaction) {
105
            $Transaction = Transaction::createInstance();
106
            if (isset($transaction['currency']) && !empty($transaction['currency'])) {
107
                $Transaction->currency = $transaction['currency'];
108
            } else {
109
                $Transaction->currency = "USD";
110
            }
111
            $Transaction->status = $transaction['status'];
112
            $Transaction->amount = 0; //value set default to 0, attribute does not exist in the API
0 ignored issues
show
Documentation Bug introduced by
The property $amount was declared of type double, but 0 is of type integer. 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...
113
            array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
114
            $Transaction->title = '';
115
            $Transaction->unique_ID = $transaction['unique_id'];
116
            $Transaction->commission = $transaction['commission'];
117
            $Transaction->date = $transaction['date'];
118
            $Transaction->click_date = $transaction['click_date'];
119
            $Transaction->update_date = $transaction['update_date'];
120
            $Transaction->program_name =  $transaction['merchantName'];
121
            $Transaction->approved = false;
122
            if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED){
123
                $Transaction->approved = true;
124
            }
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
    }
141
142
143
    /**
144
	 * @param array $params
145
	 * @return ProductsResultset
146
	 * @throws \Exception
147
	 */
148
    public function getProducts(array $params = []): ProductsResultset
149
    {
150
        throw new \Exception("Not implemented yet");
151
    }
152
153
154
155
156
}
157