Completed
Push — core-test-reorganisation ( 880d88 )
by Kamil
44:19 queued 07:25
created

TestPromotionFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 11 1
A createForChannel() 0 7 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\Behat\Service;
13
14
use Sylius\Component\Core\Formatter\StringInflector;
15
use Sylius\Component\Core\Model\ChannelInterface;
16
use Sylius\Component\Resource\Factory\FactoryInterface;
17
18
/**
19
 * @author Mateusz Zalewski <[email protected]>
20
 */
21
final class TestPromotionFactory implements TestPromotionFactoryInterface
22
{
23
    /**
24
     * @var FactoryInterface
25
     */
26
    private $promotionFactory;
27
28
    /**
29
     * @param FactoryInterface $promotionFactory
30
     */
31
    public function __construct(FactoryInterface $promotionFactory)
32
    {
33
        $this->promotionFactory = $promotionFactory;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function create($name)
40
    {
41
        $promotion = $this->promotionFactory->createNew();
42
43
        $promotion->setName($name);
44
        $promotion->setCode(StringInflector::nameToLowercaseCode($name));
45
        $promotion->setStartsAt(new \DateTime('-3 days'));
46
        $promotion->setEndsAt(new \DateTime('+3 days'));
47
48
        return $promotion;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function createForChannel($name, ChannelInterface $channel)
55
    {
56
        $promotion = $this->create($name);
57
        $promotion->addChannel($channel);
58
59
        return $promotion;
60
    }
61
}
62