Completed
Push — master ( eeff33...1702a2 )
by Kamil
41:57 queued 20:40
created

TaxContext::getTaxCategoryByName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
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\Transform;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Component\Resource\Repository\RepositoryInterface;
16
17
/**
18
 * @author Łukasz Chruściel <[email protected]>
19
 */
20
final class TaxContext implements Context
21
{
22
    /**
23
     * @var RepositoryInterface
24
     */
25
    private $taxCategoryRepository;
26
27
    /**
28
     * @param RepositoryInterface $taxCategoryRepository
29
     */
30
    public function __construct(RepositoryInterface $taxCategoryRepository)
31
    {
32
        $this->taxCategoryRepository = $taxCategoryRepository;
33
    }
34
35
    /**
36
     * @Transform /^"([^"]+)" tax category$/
37
     * @Transform /^tax category "([^"]+)"$/
38
     * @Transform :taxCategory tax category
39
     */
40
    public function getTaxCategoryByName($taxCategoryName)
41
    {
42
        $taxCategory = $this->taxCategoryRepository->findOneBy(['name' => $taxCategoryName]);
43
        if (null === $taxCategory) {
44
            throw new \InvalidArgumentException('Tax category with name "'.$taxCategoryName.'" does not exist');
45
        }
46
47
        return $taxCategory;
48
    }
49
}
50