Completed
Push — checkout-consistent-prices ( af49ca )
by Kamil
13:24
created

ChannelsCurrenciesExtension::getAllCurrencies()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
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 Sylius\Component\Core\Model\ChannelInterface;
18
use Twig\Extension\AbstractExtension;
19
use Twig\TwigFunction;
20
21
final class ChannelsCurrenciesExtension extends AbstractExtension
22
{
23
    /** @var ChannelRepositoryInterface */
24
    private $channelRepository;
25
26
    public function __construct(ChannelRepositoryInterface $channelRepository)
27
    {
28
        $this->channelRepository = $channelRepository;
29
    }
30
31
    public function getFunctions(): array
32
    {
33
        return [
34
            new TwigFunction('sylius_channels_currencies', [$this, 'getAllCurrencies']),
35
        ];
36
    }
37
38
    public function getAllCurrencies(): array
39
    {
40
        $currencies = [];
41
42
        /** @var ChannelInterface $channel */
43
        foreach ($this->channelRepository->findAll() as $channel) {
44
            $currencies[$channel->getCode()] = $channel->getBaseCurrency()->getCode();
45
        }
46
47
        return $currencies;
48
    }
49
}
50