Completed
Push — master ( ec5411...629401 )
by Kamil
31:49 queued 16:57
created

ChannelNameExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFilters() 0 6 1
A getChannelNameByCode() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\AdminBundle\Twig;
15
16
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
17
use Twig\Extension\AbstractExtension;
18
use Twig\TwigFilter;
19
20
final class ChannelNameExtension extends AbstractExtension
21
{
22
    /** @var ChannelRepositoryInterface */
23
    private $channelRepository;
24
25
    public function __construct(ChannelRepositoryInterface $channelRepository)
26
    {
27
        $this->channelRepository = $channelRepository;
28
    }
29
30
    public function getFilters(): array
31
    {
32
        return [
33
            new TwigFilter('sylius_channel_name', [$this, 'getChannelNameByCode']),
34
        ];
35
    }
36
37
    public function getChannelNameByCode(string $code): string
38
    {
39
        return $this->channelRepository->findOneByCode($code)->getName();
40
    }
41
}
42