PageSlugController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateAction() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Controller;
12
13
use Sylius\Component\Product\Generator\SlugGeneratorInterface;
14
use Symfony\Component\HttpFoundation\JsonResponse;
15
use Symfony\Component\HttpFoundation\Request;
16
use Webmozart\Assert\Assert;
17
18
final class PageSlugController
19
{
20
    /** @var SlugGeneratorInterface */
21
    private $slugGenerator;
22
23
    public function __construct(SlugGeneratorInterface $slugGenerator)
24
    {
25
        $this->slugGenerator = $slugGenerator;
26
    }
27
28
    public function generateAction(Request $request): JsonResponse
29
    {
30
        $name = $request->query->get('name');
31
        Assert::string($name);
32
33
        return new JsonResponse([
34
            'slug' => $this->slugGenerator->generate($name),
35
        ]);
36
    }
37
}
38