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

ShippingCategoryContext   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getShippingCategoryByName() 0 12 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\Transform;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Component\Resource\Repository\RepositoryInterface;
16
use Webmozart\Assert\Assert;
17
18
/**
19
 * @author Anna Walasek <[email protected]>
20
 */
21
class ShippingCategoryContext implements Context
22
{
23
    /**
24
     * @var RepositoryInterface
25
     */
26
    private $shippingCategoryRepository;
27
28
    /**
29
     * @param RepositoryInterface $shippingCategoryRepository
30
     */
31
    public function __construct(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...
32
    {
33
        $this->shippingCategoryRepository = $shippingCategoryRepository;
34
    }
35
36
    /**
37
     * @Transform /^"([^"]+)" shipping category/
38
     */
39
    public function getShippingCategoryByName($shippingCategoryName)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
40
    {
41
        $shippingCategories = $this->shippingCategoryRepository->findBy(['name' => $shippingCategoryName]);
42
43
        Assert::eq(
44
            1,
45
            count($shippingCategories),
46
            sprintf('%d shipping category has been found with name "%s".', count($shippingCategories), $shippingCategoryName)
47
        );
48
49
        return $shippingCategories[0];
50
    }
51
}
52