Passed
Push — trunk ( a19795...45f743 )
by Christian
17:17 queued 03:17
created

AppController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Storefront\Controller;
4
5
use Shopware\Core\Framework\App\Api\AppJWTGenerateRoute;
6
use Shopware\Core\Framework\App\AppException;
7
use Shopware\Core\Framework\Log\Package;
8
use Shopware\Core\System\SalesChannel\SalesChannelContext;
9
use Symfony\Component\HttpFoundation\JsonResponse;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\Routing\Annotation\Route;
12
13
/**
14
 * @internal
15
 */
16
#[Route(defaults: ['_routeScope' => ['storefront']])]
17
#[Package('storefront')]
18
final class AppController
19
{
20
    public function __construct(private readonly AppJWTGenerateRoute $appJWTGenerateRoute)
21
    {
22
    }
23
24
    #[Route(path: '/app-system/{name}/generate-token', name: 'frontend.app-system.generate-token', defaults: ['_noStore' => true], methods: ['POST'])]
25
    public function generateToken(string $name, SalesChannelContext $context): Response
26
    {
27
        try {
28
            return $this->appJWTGenerateRoute->generate($name, $context);
29
        } catch (AppException $e) {
30
            return new JsonResponse(['message' => $e->getMessage()], $e->getStatusCode());
31
        }
32
    }
33
}
34