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

AppController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateToken() 0 7 2
A __construct() 0 2 1
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