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.

ReportService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 109
ccs 23
cts 23
cp 1
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getReportFilePath() 0 3 1
A generate() 0 14 1
A attach() 0 5 1
A setReportFilePath() 0 5 1
A notify() 0 8 2
A detach() 0 7 1
1
<?php
2
3
namespace Awin\ReportTask\Bundle\ReportBundle\Service;
4
5
use Awin\ReportTask\Bundle\ReportBundle\Service\Observer\ReportObserver;
6
use Awin\ReportTask\Bundle\ReportBundle\Service\Observer\ReportObserverInterface;
7
use Awin\ReportTask\Bundle\ReportBundle\Model\TransactionStorageInterface;
8
9
/**
10
 * The report service class for generating the report.
11
 * It use observer pattern to convert the currencies,
12
 * it also could introduce other observers such as email, fraud-check validation alert, etc
13
 *
14
 * @date       24/06/2017
15
 * @time       20:18
16
 * @author     Peng Yue <[email protected]>
17
 * @copyright  2004-2017 Peng Yue
18
 */
19
20
class ReportService implements ReportServiceInterface
21
{
22
    /**
23
     * @var array|ReportObserverInterface[]
24
     */
25
    private $observers = [];
26
27
    /**
28
     * The report csv file path
29
     *
30
     * @var string
31
     */
32
    private $reportFilePath = 'var/storage/report.csv';
33
34
    /**
35
     * Generate the report
36
     *
37
     * @param MerchantTransactionServiceInterface   $merchantTransactionService
38
     * @param CurrencyServiceInterface              $currencyService
39
     * @param TransactionStorageInterface           $transactionStorage
40
     * @param int|null                              $merchantId
41
     * @param string|null                           $date
42
     *
43
     * @return bool
44
     */
45 2
    public function generate(
46
        MerchantTransactionServiceInterface $merchantTransactionService,
47
        CurrencyServiceInterface $currencyService,
48
        TransactionStorageInterface $transactionStorage,
49
        $merchantId,
50
        $date = null
51
    ) {
52
        $data = $merchantTransactionService
53 2
            ->filterTransactionsByMerchantId($merchantId)
54 2
            ->filterTransactionsByDate($date)
55 2
            ->getReportData();
56 2
        $results = $this->notify($data, $currencyService);
57
58 2
        return $transactionStorage->setData($results)->save($this->getReportFilePath());
59
    }
60
61
    /**
62
     * Set the report file path
63
     *
64
     * @param string $filePath
65
     *
66
     * @return $this
67
     */
68 2
    public function setReportFilePath($filePath)
69
    {
70 2
        $this->reportFilePath = $filePath;
71
72 2
        return $this;
73
    }
74
75
    /**
76
     * Get the csv file path
77
     *
78
     * @return string
79
     */
80 2
    public function getReportFilePath()
81
    {
82 2
        return $this->reportFilePath;
83
    }
84
85
    /**
86
     * Attach an observer for report generation
87
     *
88
     * @param ReportObserverInterface $observer
89
     *
90
     * @return $this
91
     */
92 4
    public function attach(ReportObserverInterface $observer)
93
    {
94 4
        $this->observers[] = $observer;
95
96 4
        return $this;
97
    }
98
99
    /**
100
     * detach an observer for report generation
101
     *
102
     * @param ReportObserverInterface $observer
103
     *
104
     * @return $this
105
     */
106 1
    public function detach(ReportObserverInterface $observer)
107
    {
108 1
        $key = array_search($observer, $this->observers);
109
110 1
        unset($this->observers[$key]);
111
112 1
        return $this;
113
    }
114
115
    /**
116
     * @param array           $data
117
     * @param CurrencyServiceInterface $currencyService
118
     *
119
     * @return array
120
     */
121 3
    public function notify(array $data, CurrencyServiceInterface $currencyService)
122
    {
123 3
        $result = [];
124 3
        foreach ($this->observers as $observer) {
125 3
            $result = $observer->listenReportGeneration($data, $currencyService);
126
        }
127
128 3
        return $result;
129
    }
130
}