Completed
Push — master ( 377808...51707d )
by
unknown
02:49
created

AffilinetEx::getTransactionList()   C

Complexity

Conditions 10
Paths 102

Size

Total Lines 62
Code Lines 45

Duplication

Lines 9
Ratio 14.52 %

Importance

Changes 0
Metric Value
dl 9
loc 62
rs 6.3714
c 0
b 0
f 0
cc 10
eloc 45
nc 102
nop 3

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Padosoft\AffiliateNetwork;
3
4
use Oara\Network\Publisher\Affilinet as AffilinetOara;
5
6
class AffilinetEx extends AffilinetOara
7
{
8
    /**
9
     * @param null $merchantList
10
     * @param \DateTime|null $dStartDate
11
     * @param \DateTime|null $dEndDate
12
     * @return array
13
     * @throws Exception
14
     */
15
    public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
16
    {
17
        $totalTransactions = array();
18
19
        // Don't need merchant list here
20
        // $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
21
22
        try {
23
            $publisherStatisticsServiceUrl = 'https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl';
24
            $publisherStatisticsService = new \SoapClient($publisherStatisticsServiceUrl, array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, 'soap_version' => SOAP_1_1));
25
26
            $params = array(
27
                'StartDate' => \strtotime($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...
28
                'EndDate' => \strtotime($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...
29
                'TransactionStatus' => 'All',
30
                'ValuationType' => 'DateOfConfirmation'     // Only modified transactions within date range - <PN> - 2017-06-26
31
            );
32
            $currentPage = 1;
33
            $transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage);
34
35
            while (isset($transactionList->TotalRecords) && $transactionList->TotalRecords > 0 && isset($transactionList->TransactionCollection->Transaction)) {
36
                $transactionCollection = array();
37
                if (!\is_array($transactionList->TransactionCollection->Transaction)) {
38
                    $transactionCollection[] = $transactionList->TransactionCollection->Transaction;
39
                } else {
40
                    $transactionCollection = $transactionList->TransactionCollection->Transaction;
41
                }
42
43
                foreach ($transactionCollection as $transactionObject) {
44
45
                    $transaction = array();
46
                    $transaction["status"] = $transactionObject->TransactionStatus;
47
                    $transaction["unique_id"] = $transactionObject->TransactionId;
48
                    $transaction["commission"] = $transactionObject->PublisherCommission;
49
                    $transaction["amount"] = $transactionObject->NetPrice;
50
                    $transaction["date"] = $transactionObject->RegistrationDate;
51
                    $transaction["click_date"] = $transactionObject->ClickDate;         // Future use - <PN>
52
                    $transaction["udpate_date"] = $transactionObject->CheckDate;        // Future use - <PN>
53
                    $transaction["merchantId"] = $transactionObject->ProgramId;
54
                    $transaction["custom_id"] = $transactionObject->SubId;
55 View Code Duplication
                    if ($transaction['status'] == 'Confirmed') {
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...
56
                        $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
57
                    } else
58
                        if ($transaction['status'] == 'Open') {
59
                            $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
60
                        } else
61
                            if ($transaction['status'] == 'Cancelled') {
62
                                $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
63
                            }
64
                    $totalTransactions[] = $transaction;
65
                }
66
                $currentPage++;
67
                $transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage);
68
            }
69
        } catch (\Exception $e) {
70
            // Avoid lost of transactions if one call failed
71
            echo PHP_EOL . "AffilinetEx - getTransactionList err: ".$e->getMessage().PHP_EOL;
72
            throw new \Exception($e);
73
        }
74
        echo (New \DateTime())->format("d/m/Y H:i:s") . " - AffilinetEx getTransactionList - return " . count($totalTransactions) . " transactions" . PHP_EOL;
75
        return $totalTransactions;
76
    }
77
}
78