Completed
Push — master ( 860366...55daec )
by Kamil
19:37
created

DefaultChannelFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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\Test\Services;
13
14
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
15
use Sylius\Component\Resource\Repository\RepositoryInterface;
16
17
/**
18
 * @author Mateusz Zalewski <[email protected]>
19
 */
20
class DefaultChannelFactory implements DefaultChannelFactoryInterface
21
{
22
    const DEFAULT_CHANNEL_NAME = 'Default';
23
    const DEFAULT_CHANNEL_CODE = 'DEFAULT';
24
25
    /**
26
     * @var ChannelFactoryInterface
27
     */
28
    private $channelFactory;
29
30
    /**
31
     * @var RepositoryInterface
32
     */
33
    private $channelRepository;
34
35
    /**
36
     * @param ChannelFactoryInterface $channelFactory
37
     * @param RepositoryInterface $channelRepository
38
     */
39
    public function __construct(ChannelFactoryInterface $channelFactory, RepositoryInterface $channelRepository)
40
    {
41
        $this->channelFactory = $channelFactory;
42
        $this->channelRepository = $channelRepository;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function create()
49
    {
50
        $channel = $this->channelFactory->createNamed(self::DEFAULT_CHANNEL_NAME);
51
        $channel->setCode(self::DEFAULT_CHANNEL_CODE);
52
53
        $this->channelRepository->add($channel);
54
55
        return ['channel' => $channel];
56
    }
57
}
58