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

DefaultChannelFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 9 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
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