Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DiscountSettingsWebController
100.00% covered (success)
100.00%
13 / 13
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%
12 / 12
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\Discount\Presentation\Web;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Instance\Application\Service\InstanceContextManagerInterface;
12use App\Modules\Discount\Application\Service\DiscountApplicationService;
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 Discount Settings management accessible from App Admin in client context.
20 */
21final readonly class DiscountSettingsWebController
22{
23    private const string HTML_CONTENT_TYPE = 'text/html; charset=utf-8';
24
25    /**
26     * DiscountSettingsWebController constructor.
27     */
28    public function __construct(
29        private DiscountApplicationService $discountService,
30        private TwigEnvironment $twig,
31        private Psr17Factory $psr17Factory,
32        private ?InstanceContextManagerInterface $instanceManager = null,
33        private string $appProfile = 'admin',
34    ) {
35    }
36
37    /**
38     * Display Discount Settings Management Center (GET /settings/discounts).
39     */
40    public function index(): ResponseInterface
41    {
42        $activeInstance = $this->instanceManager?->getActiveInstance();
43        $discounts = $this->discountService->getDiscounts();
44
45        $html = $this->twig->render('discount/index.twig', [
46            'discounts' => $discounts,
47            'page_title' => 'Discounts & Offers Management',
48            'active_instance' => $activeInstance,
49            'app_profile' => $this->appProfile,
50        ]);
51
52        $response = $this->psr17Factory->createResponse(200)
53            ->withHeader('Content-Type', self::HTML_CONTENT_TYPE);
54        $response->getBody()->write($html);
55
56        return $response;
57    }
58}