Completed
Push — master ( a83d77...6141b3 )
by
unknown
06:36
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 View Code Duplication
    public function invokeMethod(&$object,$methodName, array $parameters = 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...
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
    /**
85
     * @param null $merchantList
86
     * @param \DateTime|null $dStartDate
87
     * @param \DateTime|null $dEndDate
88
     * @return array
89
     * @throws Exception
90
     */
91
    public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
92
    {
93
        $totalTransactions = array();
94
        $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
95
96
        $valuesFormExport = array();
97
        $valuesFormExport[] = new \Oara\Curl\Parameter('authl', $this->_credentials["user"]);
98
        $valuesFormExport[] = new \Oara\Curl\Parameter('authv', $this->_credentials["apiPassword"]);
99
        $valuesFormExport[] = new \Oara\Curl\Parameter('champs', 'idprogramme,date,etat,argsite,montant,gains,monnaie,idsite,id');
100
        $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...
101
        $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...
102
        $urls = array();
103
        $urls[] = new \Oara\Curl\Request('https://stat.netaffiliation.com/requete.php?', $valuesFormExport);
104
105
        $exportReport = $this->_client->get($urls);
106
107
108
109
        //sales
110
        $exportData = str_getcsv($exportReport[0], "\n");
111
        $num = count($exportData);
112
        for ($i = 1; $i < $num; $i++) {
113
            $transactionExportArray = str_getcsv($exportData[$i], ";");
114
            if (\count($this->_sitesAllowed) == 0 || \in_array($transactionExportArray[7], $this->_sitesAllowed)) {
115
                if (count($merchantIdList)<1 || isset($merchantIdList[$transactionExportArray[0]])) {
116
                    $transaction = Array();
117
                    $transaction['merchantId'] = $transactionExportArray[0];
118
                    //$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...
119
                    $transaction['date'] = $transactionExportArray[1];
120
                    $transaction['title'] = '';
121
122
                    if ($transactionExportArray[3] != null) {
123
                        $transaction['custom_id'] = $transactionExportArray[3];
124
                    }
125
126
                    if (\strstr($transactionExportArray[2], 'v')) {
127
                        $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
128
                    } else
129
                        if (\strstr($transactionExportArray[2], 'r')) {
130
                            $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
131
                        } else if (\strstr($transactionExportArray[2], 'a')) {
132
                            $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
133
                        } else {
134
                            throw new \Exception ("Status not found");
135
                        }
136
                    $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[4]);
137
                    $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[5]);
138
139
                    $transaction['currency'] = $transactionExportArray[6];
140
                    $transaction['unique_id'] = $transactionExportArray[8];
141
                    $totalTransactions[] = $transaction;
142
                }
143
            }
144
        }
145
        return $totalTransactions;
146
    }
147
148
149
}