Completed
Push — master ( 155c16...880d18 )
by Kamil
26:05
created

ChannelBasedThemeContext::getTheme()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 13
rs 9.4285
c 2
b 0
f 1
cc 3
eloc 8
nc 5
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
namespace Sylius\Component\Core\Theme;
13
14
use Doctrine\DBAL\DBALException;
15
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
16
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
17
use Sylius\Component\Channel\Context\ChannelContextInterface;
18
use Sylius\Component\Channel\Context\ChannelNotFoundException;
19
use Sylius\Component\Core\Model\ChannelInterface;
20
21
/**
22
 * @author Kamil Kokot <[email protected]>
23
 */
24
final class ChannelBasedThemeContext implements ThemeContextInterface
25
{
26
    /**
27
     * @var ChannelContextInterface
28
     */
29
    private $channelContext;
30
31
    /**
32
     * @param ChannelContextInterface $channelContext
33
     */
34
    public function __construct(ChannelContextInterface $channelContext)
35
    {
36
        $this->channelContext = $channelContext;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getTheme()
43
    {
44
        try {
45
            /** @var ChannelInterface $channel */
46
            $channel = $this->channelContext->getChannel();
47
48
            return $channel->getTheme();
49
        } catch (ChannelNotFoundException $exception) {
50
            return null;
51
        } catch (\Exception $exception) {
52
            return null;
53
        }
54
    }
55
}
56