Completed
Push — master ( 1799df...df6994 )
by
unknown
07:34 queued 05:10
created

EffiliationEx::getTransactionList()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 41
Code Lines 30

Duplication

Lines 7
Ratio 17.07 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 41
rs 6.7272
cc 7
eloc 30
nc 10
nop 3
1
<?php
2
/**
3
 * Copyright (c) Padosoft.com 2017.
4
 */
5
namespace Padosoft\AffiliateNetwork;
6
use Oara\Network\Publisher\Effiliation as EffiliationOara;
7
8
class EffiliationEx extends EffiliationOara{
9
    /**
10
     * @param null $merchantList
11
     * @param \DateTime|null $dStartDate
12
     * @param \DateTime|null $dEndDate
13
     * @return array
14
     */
15
    public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
16
    {
17
        $totalTransactions = array();
18
19
        $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
20
21
        $url = 'http://api.effiliation.com/apiv2/transaction.csv?key=' . $this->_credentials["apiPassword"] . '&start=' . $dStartDate->format("d/m/Y") . '&end=' . $dEndDate->format("d/m/Y") . '&type=date&all=yes';
0 ignored issues
show
Bug introduced by
The property _credentials cannot be accessed from this context as it is declared private in class Oara\Network\Publisher\Effiliation.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
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...
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...
22
        $content = \utf8_encode(\file_get_contents($url));
23
        $exportData = \str_getcsv($content, "\n");
24
        $num = \count($exportData);
25
26
        for ($i = 1; $i < $num; $i++) {
27
            $transactionExportArray = \str_getcsv($exportData[$i], "|");
28
            if (isset($merchantIdList[(int)$transactionExportArray[2]])) {
29
30
                $transaction = Array();
31
                $merchantId = (int)$transactionExportArray[2];
32
                $transaction['merchantId'] = $merchantId;
33
                $transaction['date'] = $transactionExportArray[10];
34
                $transaction['unique_id'] = $transactionExportArray[0];
35
                $transaction['custom_id'] = '';
36
                if ($transactionExportArray[4] != null) {
37
                    $transaction['custom_id'] = $transactionExportArray[4];
38
                }
39
40
                if ($transactionExportArray[9] == 'Valide') {
41
                    $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
42 View Code Duplication
                } else
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...
43
                    if ($transactionExportArray[9] == 'Attente') {
44
                        $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
45
                    } else
46
                        if ($transactionExportArray[9] == 'Refus�') {
47
                            $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
48
                        }
49
                $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[7]);
50
                $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[8]);
51
                $totalTransactions[] = $transaction;
52
            }
53
        }
54
        return $totalTransactions;
55
    }
56
}