GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TransactionTable::getTransactions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Awin\ReportTask\Bundle\ReportBundle\Model;
4
5
/**
6
 * Source of transactions, read data.csv directly for simplicity sake,
7
 * It can filter by the merchant_id or date
8
 *
9
 * @date       24/06/2017
10
 * @time       16:35
11
 * @author     Peng Yue <[email protected]>
12
 * @copyright  2004-2017 Peng Yue
13
 */
14
15
class TransactionTable
16
{
17
    /**
18
     * @var TransactionStorageInterface
19
     */
20
    private $transactionStorage;
21
22
    /**
23
     * TransactionTable constructor.
24
     *
25
     * @param string $csvFilePath
26
     */
27 6
    public function __construct($csvFilePath)
28
    {
29 6
        $this->transactionStorage = new TransactionCsvStorage($csvFilePath);
30 6
    }
31
32
    /**
33
     * Get the transactions from data source, for simplicity, no pagination on getting transactions
34
     * @param int $offset the start position to read
35
     * @param int $limit  the item number to read
36
     *
37
     * @return array
38
     */
39 4
    public function getTransactions($offset = 1, $limit = 15)
40
    {
41 4
        $results = [];
42 4
        $data = $this->transactionStorage->getData($offset, $limit);
43 4
        foreach ($data as $item) {
44 4
            $symbol = mb_substr($item[2], 0, 1, 'UTF-8');
45 4
            $amount = mb_substr($item[2], 1);
46 4
            $temp   = array_merge($item, [$symbol, $amount]);
47 4
            $results[] = $temp;
48
        }
49
50 4
        return $results;
51
    }
52
53
    /**
54
     * Get the transactions by date
55
     *
56
     * @param string|null $date
57
     *
58
     * @return array
59
     */
60 1
    public function getTransactionsByDate($date = null)
61
    {
62 1
        $results = [];
63
        //for simplicity, no pagination here neither
64 1
        $data = $this->transactionStorage->getData(1, 15);
65
66 1
        $dateWorker = new \DateTime();
67 1
        $formattedDate = (null === $date)
68 1
            ? null
69 1
            : $dateWorker->createFromFormat('d/m/Y', $date)->format('Y-m-d H:i:s');
70
71 1
        foreach ($data as $item) {
72 1
            $itemTime = $dateWorker->createFromFormat('d/m/Y', $item[1])->format('Y-m-d H:i:s');
73 1
            if (null === $formattedDate || strtotime($formattedDate) - strtotime($itemTime) >= 0 ) {
74 1
                $symbol = mb_substr($item[2], 0, 1, 'UTF-8');
75 1
                $amount = mb_substr($item[2], 1);
76 1
                $temp   = array_merge($item, [$symbol, $amount]);
77 1
                $results[] = $temp;
78
            }
79
        }
80
81 1
        return $results;
82
    }
83
}