Completed
Push — 1.7 ( 02bd6f...0983e5 )
by Kamil
05:42
created

ChannelFactory::createNamed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\Component\Core\Factory;
15
16
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
17
use Sylius\Component\Channel\Model\ChannelInterface;
18
use Sylius\Component\Core\Model\ChannelInterface as CoreChannelInterface;
19
use Sylius\Component\Resource\Factory\FactoryInterface;
20
21
final class ChannelFactory implements ChannelFactoryInterface
22
{
23
    /** @var FactoryInterface */
24
    private $decoratedFactory;
25
26
    /** @var string */
27
    private $defaultCalculationStrategy;
28
29
    public function __construct(FactoryInterface $decoratedFactory, string $defaultCalculationStrategy)
30
    {
31
        $this->decoratedFactory = $decoratedFactory;
32
        $this->defaultCalculationStrategy = $defaultCalculationStrategy;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function createNew(): ChannelInterface
39
    {
40
        /** @var CoreChannelInterface $channel */
41
        $channel = $this->decoratedFactory->createNew();
42
        $channel->setTaxCalculationStrategy($this->defaultCalculationStrategy);
43
44
        return $channel;
45
    }
46
47
    /**
48
     * @return CoreChannelInterface
49
     */
50
    public function createNamed(string $name): ChannelInterface
51
    {
52
        $channel = $this->createNew();
53
        $channel->setName($name);
54
55
        return $channel;
56
    }
57
}
58