Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TaxSettingsWebController
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 index
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Tax\Presentation\Web;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Instance\Application\Service\InstanceContextManagerInterface;
12use App\Modules\Tax\Application\Service\TaxApplicationService;
13use Nyholm\Psr7\Factory\Psr17Factory;
14use Psr\Http\Message\ResponseInterface;
15use Psr\Http\Message\ServerRequestInterface;
16use Twig\Environment as TwigEnvironment;
17
18/**
19 * Web Controller for Tax Settings management accessible from App Admin in client context.
20 */
21final readonly class TaxSettingsWebController
22{
23    private const string HTML_CONTENT_TYPE = 'text/html; charset=utf-8';
24
25    /**
26     * TaxSettingsWebController constructor.
27     */
28    public function __construct(
29        private TaxApplicationService $taxService,
30        private TwigEnvironment $twig,
31        private Psr17Factory $psr17Factory,
32        private ?InstanceContextManagerInterface $instanceManager = null,
33    ) {
34    }
35
36    /**
37     * Display Tax Settings Management Center (GET /settings/taxes).
38     */
39    public function index(): ResponseInterface
40    {
41        $activeInstance = $this->instanceManager?->getActiveInstance();
42
43        $rates = $this->taxService->getTaxRates();
44        $groups = $this->taxService->getTaxGroups();
45        $rules = $this->taxService->getTaxRules();
46
47        $html = $this->twig->render('tax/index.twig', [
48            'rates' => $rates,
49            'groups' => $groups,
50            'rules' => $rules,
51            'page_title' => 'Tax & VAT Management',
52            'active_instance' => $activeInstance,
53        ]);
54
55        $response = $this->psr17Factory->createResponse(200)
56            ->withHeader('Content-Type', self::HTML_CONTENT_TYPE);
57        $response->getBody()->write($html);
58
59        return $response;
60    }
61}