Completed
Push — master ( 117943...1799df )
by
unknown
06:31
created

NetAffiliationEx::invokeProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
/**
3
 * Copyright (c) Padosoft.com 2017.
4
 */
5
6
7
namespace Padosoft\AffiliateNetwork;
8
use Oara\Network\Publisher\NetAffiliation as NetAffiliationOara;
9
10
class NetAffiliationEx extends NetAffiliationOara
11
{
12
    protected $_serverNumber = 6;
13
    /**
14
     * Call protected/private method of a class.
15
     *
16
     * @param object &$object    Instantiated object that we will run method on.
17
     * @param string $methodName Method name to call
18
     * @param array  $parameters Array of parameters to pass into method.
19
     *
20
     * @return mixed Method return.
21
     */
22
    public function invokeMethod(&$object,$methodName, array $parameters = array())
23
    {
24
        $reflection = new \ReflectionClass(get_class($object));
25
        $method = $reflection->getMethod($methodName);
26
        $method->setAccessible(true);
27
        return $method->invokeArgs($object, $parameters);
28
    }
29
30
    /**
31
     * Call protected/private property of a class.
32
     * @param $object
33
     * @param $propertyName
34
     *
35
     * @return mixed
36
     */
37 View Code Duplication
    public function invokeProperty(&$object,$propertyName)
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...
38
    {
39
        $reflection = new \ReflectionClass(get_class($object));
40
        $property = $reflection->getProperty($propertyName);
41
        $property->setAccessible(true);
42
        return $property->getValue($object);
43
    }
44
45
    /**
46
     * @param $credentials
47
     * @throws \Exception
48
     * @throws \Oara\Curl\Exception
49
     */
50
    /*public function login($credentials){
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% 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...
51
        $this->_credentials = $credentials;
52
        $this->_client = new \Oara\Curl\Access($credentials);
53
54
    }*/
55
56
    /**
57
     * @return bool
58
     */
59
    /*public function checkConnection()
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
60
    {
61
        $connection = false;
62
63
        try{
64
            $valuesFormExport[] = new \Oara\Curl\Parameter('authl', $this->_credentials["user"]);
65
            $valuesFormExport[] = new \Oara\Curl\Parameter('authv', $this->_credentials["apiPassword"]);
66
            $urls = array();
67
            $urls[] = new \Oara\Curl\Request('https://stat.netaffiliation.com/requete.php?', $valuesFormExport);
68
69
            $exportReport = $this->_client->get($urls);
70
            $exportData = str_getcsv($exportReport[0], "\n");
71
            if (substr($exportData[0],0,2)=='OK'){
72
                $connection=true;
73
            }
74
        }catch (\Exception $exception){
75
76
        }finally{
77
78
        }
79
80
81
        return $connection;
82
    }*/
83
    /**
84
     * @param string $idSite
85
     */
86
    public function addAllowedSite(string $idSite){
87
        $this->_sitesAllowed[]=$idSite;
88
    }
89
    /**
90
     * @param null $merchantList
91
     * @param \DateTime|null $dStartDate
92
     * @param \DateTime|null $dEndDate
93
     * @return array
94
     * @throws Exception
95
     */
96
    public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
97
    {
98
        $totalTransactions = array();
99
        $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
100
101
        $valuesFormExport = array();
102
        $valuesFormExport[] = new \Oara\Curl\Parameter('authl', $this->_credentials["user"]);
103
        $valuesFormExport[] = new \Oara\Curl\Parameter('authv', $this->_credentials["apiPassword"]);
104
        $valuesFormExport[] = new \Oara\Curl\Parameter('champs', 'idprogramme,date,etat,argsite,montant,gains,monnaie,idsite,id');
105
        $valuesFormExport[] = new \Oara\Curl\Parameter('debut', $dStartDate->format("Y-m-d"));
0 ignored issues
show
Bug introduced by
It seems like $dStartDate is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
106
        $valuesFormExport[] = new \Oara\Curl\Parameter('fin', $dEndDate->format("Y-m-d"));
0 ignored issues
show
Bug introduced by
It seems like $dEndDate is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
107
        $urls = array();
108
        $urls[] = new \Oara\Curl\Request('https://stat.netaffiliation.com/requete.php?', $valuesFormExport);
109
110
        $exportReport = $this->_client->get($urls);
111
112
113
114
        //sales
115
        $exportData = str_getcsv($exportReport[0], "\n");
116
        $num = count($exportData);
117
        for ($i = 1; $i < $num; $i++) {
118
            $transactionExportArray = str_getcsv($exportData[$i], ";");
119
            if (\count($this->_sitesAllowed) == 0 || \in_array($transactionExportArray[7], $this->_sitesAllowed)) {
120
                if (count($merchantIdList)<1 || isset($merchantIdList[$transactionExportArray[0]])) {
121
                    $transaction = Array();
122
                    $transaction['merchantId'] = $transactionExportArray[0];
123
                    //$transactionDate = \DateTime::createFromFormat("d/m/Y H:i:s", $transactionExportArray[1]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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['date'] = $transactionExportArray[1];
125
                    $transaction['title'] = '';
126
127
                    if ($transactionExportArray[3] != null) {
128
                        $transaction['custom_id'] = $transactionExportArray[3];
129
                    }
130
131
                    if (\strstr($transactionExportArray[2], 'v')) {
132
                        $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
133
                    } else
134
                        if (\strstr($transactionExportArray[2], 'r')) {
135
                            $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
136
                        } else if (\strstr($transactionExportArray[2], 'a')) {
137
                            $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
138
                        } else {
139
                            throw new \Exception ("Status not found");
140
                        }
141
                    $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[4]);
142
                    $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[5]);
143
144
                    $transaction['currency'] = $transactionExportArray[6];
145
                    $transaction['unique_id'] = $transactionExportArray[8];
146
                    $totalTransactions[] = $transaction;
147
                }
148
            }
149
        }
150
        return $totalTransactions;
151
    }
152
153
154
}