Completed
Pull Request — master (#54)
by Konrad
07:28 queued 03:14
created

SlugTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A transform() 0 7 2
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusElasticsearchPlugin\Transformer\Product;
14
15
use Sylius\Component\Core\Model\ProductInterface;
16
use Symfony\Component\Routing\RouterInterface;
17
18
final class SlugTransformer implements TransformerInterface
19
{
20
    /** @var RouterInterface */
21
    private $router;
22
23
    public function __construct(RouterInterface $router)
24
    {
25
        $this->router = $router;
26
    }
27
28
    public function transform(ProductInterface $product): ?string
29
    {
30
        if (null === $product->getSlug()) {
31
            return null;
32
        }
33
34
        return $this->router->generate('sylius_shop_product_show', ['slug' => $product->getSlug()]);
35
    }
36
}
37