Completed
Push — symfony3-fqcn-sylius-3 ( 1d8d47...2ae323 )
by Kamil
38:58 queued 18:19
created

theStoreHasShippingCategoryIdentifiedBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\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
     * @Given the store has :shippingCategoryName shipping category identified by :shippingCategoryCode
77
     */
78
    public function theStoreHasShippingCategoryIdentifiedBy($shippingCategoryName, $shippingCategoryCode)
79
    {
80
        $this->createShippingCategory($shippingCategoryName, $shippingCategoryCode);
81
    }
82
83
    /**
84
     * @param string $shippingCategoryName
85
     * @param string $shippingCategoryCode
0 ignored issues
show
Documentation introduced by
Should the type for parameter $shippingCategoryCode not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
86
     */
87
    private function createShippingCategory($shippingCategoryName, $shippingCategoryCode = null)
88
    {
89
        /** @var ShippingCategoryInterface $shippingCategory */
90
        $shippingCategory =  $this->shippingCategoryFactory->createNew();
91
        $shippingCategory->setName($shippingCategoryName);
92
        $shippingCategory->setCode($shippingCategoryCode);
93
94
        if(null === $shippingCategoryCode) {
95
            $shippingCategory->setCode(StringInflector::nameToCode($shippingCategoryName));
96
        }
97
98
        $this->shippingCategoryRepository->add($shippingCategory);
99
        $this->sharedStorage->set('shipping_category', $shippingCategory);
100
    }
101
}
102