Completed
Push — symfony3-fqcn-sylius ( 26083b...02605f )
by Kamil
20:07
created

ShippingCategoryContext::createShippingCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
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
namespace Sylius\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use Doctrine\Common\Persistence\ObjectManager;
16
use Sylius\Behat\Service\SharedStorageInterface;
17
use Sylius\Component\Core\Formatter\StringInflector;
18
use Sylius\Component\Resource\Factory\FactoryInterface;
19
use Sylius\Component\Resource\Repository\RepositoryInterface;
20
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
21
22
/**
23
 * @author Anna Walasek <[email protected]>
24
 */
25
final class ShippingCategoryContext implements Context
26
{
27
    /**
28
     * @var SharedStorageInterface
29
     */
30
    private $sharedStorage;
31
32
    /**
33
     * @var FactoryInterface
34
     */
35
    private $shippingCategoryFactory;
36
37
    /**
38
     * @var RepositoryInterface
39
     */
40
    private $shippingCategoryRepository;
41
42
    /**
43
     * @var ObjectManager
44
     */
45
    private $shippingCategoryManager;
46
47
    /**
48
     * @param SharedStorageInterface $sharedStorage
49
     * @param FactoryInterface $shippingCategoryFactory
50
     * @param RepositoryInterface $shippingCategoryRepository
51
     * @param ObjectManager $shippingCategoryManager
52
     */
53
    public function __construct(
54
        SharedStorageInterface $sharedStorage,
55
        FactoryInterface $shippingCategoryFactory,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $shippingCategoryFactory exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
56
        RepositoryInterface $shippingCategoryRepository,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $shippingCategoryRepository exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
57
        ObjectManager $shippingCategoryManager
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $shippingCategoryManager exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
58
    ) {
59
        $this->sharedStorage = $sharedStorage;
60
        $this->shippingCategoryFactory = $shippingCategoryFactory;
61
        $this->shippingCategoryRepository = $shippingCategoryRepository;
62
        $this->shippingCategoryManager = $shippingCategoryManager;
63
    }
64
65
    /**
66
     * @Given the store has :firstShippingCategoryName shipping category
67
     * @Given the store has :firstShippingCategoryName and :secondShippingCategoryName shipping category
68
     */
69
    public function theStoreHasAndShippingCategory($firstShippingCategoryName, $secondShippingCategoryName = null)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $firstShippingCategoryName exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
Comprehensibility Naming introduced by
The variable name $secondShippingCategoryName exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
70
    {
71
        $this->createShippingCategory($firstShippingCategoryName);
72
        (null === $secondShippingCategoryName)? : $this->createShippingCategory($secondShippingCategoryName);
73
    }
74
75
    /**
76
     * @param string $shippingCategoryName
77
     */
78
    private function createShippingCategory($shippingCategoryName)
79
    {
80
        /** @var ShippingCategoryInterface $shippingCategory */
81
        $shippingCategory =  $this->shippingCategoryFactory->createNew();
82
        $shippingCategory->setName($shippingCategoryName);
83
        $shippingCategory->setCode(StringInflector::nameToCode($shippingCategoryName));
84
85
        $this->shippingCategoryRepository->add($shippingCategory);
86
        $this->sharedStorage->set('shipping_category', $shippingCategory);
87
    }
88
}
89