Passed
Pull Request — main (#54)
by Thierry
13:54
created

ReportController::round()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 4
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Response;
7
use Illuminate\View\View;
8
use Siak\Tontine\Service\Report\Pdf\PrinterService;
9
use Siak\Tontine\Service\Report\ReportService;
10
use Siak\Tontine\Service\TenantService;
11
use Siak\Tontine\Service\Tontine\TontineService;
12
use Sqids\SqidsInterface;
13
14
use function base64_decode;
15
use function response;
16
use function view;
17
18
class ReportController extends Controller
19
{
20
    /**
21
     * @param TenantService $tenantService
22
     * @param ReportService $reportService
23
     * @param PrinterService $printerService
24
     */
25
    public function __construct(private TenantService $tenantService,
26
        private ReportService $reportService, private TontineService $tontineService,
27
        private PrinterService $printerService)
28
    {}
29
30
    /**
31
     * @param Request $request
32
     * @param int $sessionId
33
     *
34
     * @return View|Response
35
     */
36
    public function sessionById(Request $request, int $sessionId)
37
    {
38
        $template = $this->tontineService->getReportTemplate();
39
        $session = $this->tenantService->getSession($sessionId);
40
        view()->share($this->reportService->getSessionReport($session));
0 ignored issues
show
Bug introduced by
It seems like $session can also be of type null; however, parameter $session of Siak\Tontine\Service\Rep...ice::getSessionReport() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        view()->share($this->reportService->getSessionReport(/** @scrutinizer ignore-type */ $session));
Loading history...
41
        // Show the html page
42
        if($request->has('html'))
43
        {
44
            return view("tontine.report.$template.session");
45
        }
46
47
        // Print the pdf
48
        $filename = $this->reportService->getSessionReportFilename($session);
0 ignored issues
show
Bug introduced by
It seems like $session can also be of type null; however, parameter $session of Siak\Tontine\Service\Rep...SessionReportFilename() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        $filename = $this->reportService->getSessionReportFilename(/** @scrutinizer ignore-type */ $session);
Loading history...
49
        return response(base64_decode($this->printerService->getSessionReport($template)), 200)
50
            ->header('Content-Description', 'Session Report')
51
            ->header('Content-Type', 'application/pdf')
52
            ->header('Content-Disposition', "inline; filename=$filename")
53
            ->header('Content-Transfer-Encoding', 'binary')
54
            ->header('Expires', '0')
55
            ->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
56
            ->header('Pragma', 'public');
57
    }
58
59
    /**
60
     * @param Request $request
61
     * @param SqidsInterface $sqids
62
     * @param string $sessionId
63
     *
64
     * @return View|Response
65
     */
66
    public function session(Request $request, SqidsInterface $sqids, string $sessionSqid)
67
    {
68
        [$sessionId] = $sqids->decode($sessionSqid);
69
        return $this->sessionById($request, $sessionId);
70
    }
71
72
    /**
73
     * @param Request $request
74
     * @param SqidsInterface $sqids
75
     * @param string $sessionId
76
     *
77
     * @return View|Response
78
     */
79
    public function profits(Request $request, SqidsInterface $sqids, string $sessionSqid)
80
    {
81
        [$sessionId] = $sqids->decode($sessionSqid);
82
        $template = $this->tontineService->getReportTemplate();
83
        $session = $this->tenantService->getSession($sessionId);
84
        view()->share($this->reportService->getProfitsReport($session));
0 ignored issues
show
Bug introduced by
It seems like $session can also be of type null; however, parameter $session of Siak\Tontine\Service\Rep...ice::getProfitsReport() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

84
        view()->share($this->reportService->getProfitsReport(/** @scrutinizer ignore-type */ $session));
Loading history...
85
        // Show the html page
86
        if($request->has('html'))
87
        {
88
            return view("tontine.report.$template.profits");
89
        }
90
91
        // Print the pdf
92
        $filename = $this->reportService->getProfitsReportFilename($session);
0 ignored issues
show
Bug introduced by
It seems like $session can also be of type null; however, parameter $session of Siak\Tontine\Service\Rep...ProfitsReportFilename() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

92
        $filename = $this->reportService->getProfitsReportFilename(/** @scrutinizer ignore-type */ $session);
Loading history...
93
        return response(base64_decode($this->printerService->getProfitsReport($template)), 200)
94
            ->header('Content-Description', 'Profits Report')
95
            ->header('Content-Type', 'application/pdf')
96
            ->header('Content-Disposition', "inline; filename=$filename")
97
            ->header('Content-Transfer-Encoding', 'binary')
98
            ->header('Expires', '0')
99
            ->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
100
            ->header('Pragma', 'public');
101
    }
102
103
    /**
104
     * @param Request $request
105
     * @param int $roundId
106
     *
107
     * @return View|Response
108
     */
109
    public function roundById(Request $request, int $roundId)
110
    {
111
        $template = $this->tontineService->getReportTemplate();
112
        $round = $this->tenantService->getRound($roundId);
113
        view()->share($this->reportService->getRoundReport($round));
0 ignored issues
show
Bug introduced by
It seems like $round can also be of type null; however, parameter $round of Siak\Tontine\Service\Rep...rvice::getRoundReport() does only seem to accept Siak\Tontine\Model\Round, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

113
        view()->share($this->reportService->getRoundReport(/** @scrutinizer ignore-type */ $round));
Loading history...
114
        // Show the html page
115
        if($request->has('html'))
116
        {
117
            return view("tontine.report.$template.round");
118
        }
119
120
        // Print the pdf
121
        $filename = $this->reportService->getRoundReportFilename($round);
0 ignored issues
show
Bug introduced by
It seems like $round can also be of type null; however, parameter $round of Siak\Tontine\Service\Rep...etRoundReportFilename() does only seem to accept Siak\Tontine\Model\Round, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

121
        $filename = $this->reportService->getRoundReportFilename(/** @scrutinizer ignore-type */ $round);
Loading history...
122
        return response(base64_decode($this->printerService->getRoundReport($template)), 200)
123
            ->header('Content-Description', 'Round Report')
124
            ->header('Content-Type', 'application/pdf')
125
            ->header('Content-Disposition', "inline; filename=$filename")
126
            ->header('Content-Transfer-Encoding', 'binary')
127
            ->header('Expires', '0')
128
            ->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
129
            ->header('Pragma', 'public');
130
    }
131
132
    /**
133
     * @param Request $request
134
     * @param SqidsInterface $sqids
135
     * @param string $roundSqid
136
     *
137
     * @return View|Response
138
     */
139
    public function round(Request $request, SqidsInterface $sqids, string $roundSqid)
140
    {
141
        [$roundId] = $sqids->decode($roundSqid);
142
        return $this->roundById($request, $roundId);
143
    }
144
}
145