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

PrinterService::getSessionReport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 2
b 0
f 0
1
<?php
2
3
namespace Siak\Tontine\Service\Report\Pdf;
4
5
use function view;
6
7
class PrinterService
8
{
9
    /**
10
     * @param array $config
11
     */
12
    public function __construct(private array $config)
13
    {}
14
15
    /**
16
     * @param string $templatePath
17
     * @param array $config
18
     *
19
     * @return string
20
     */
21
    private function getPdf(string $templatePath, array $config = []): string
22
    {
23
        $config = [
24
            ...$this->config,
25
            ...$config,
26
            'headerTemplate' => (string)view("$templatePath.tpl.header"),
27
            'footerTemplate' => (string)view("$templatePath.tpl.footer"),
28
        ];
29
        return GeneratorFacade::getPdf((string)view($templatePath), $config);
30
    }
31
32
    /**
33
     * @param string $template
34
     *
35
     * @return string
36
     */
37
    public function getSessionReport(string $template): string
38
    {
39
        return $this->getPdf("tontine.report.$template.session");
40
    }
41
42
    /**
43
     * @param string $template
44
     *
45
     * @return string
46
     */
47
    public function getProfitsReport(string $template): string
48
    {
49
        return $this->getPdf("tontine.report.$template.profits");
50
    }
51
52
    /**
53
     * @param string $template
54
     *
55
     * @return string
56
     */
57
    public function getRoundReport(string $template): string
58
    {
59
        return $this->getPdf("tontine.report.$template.round");
60
    }
61
}
62