Completed
Pull Request — demo (#202)
by Loïc
02:17
created

ArticleContext   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getArticleByTitle() 0 12 1
1
<?php
2
3
/*
4
 * This file is part of monofony.
5
 *
6
 * (c) Mobizel
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
declare(strict_types=1);
13
14
namespace App\Behat\Context\Transform;
15
16
use App\Entity\Article;
17
use Behat\Behat\Context\Context;
18
use Sylius\Component\Resource\Repository\RepositoryInterface;
19
use Webmozart\Assert\Assert;
20
21
final class ArticleContext implements Context
22
{
23
    /** @var RepositoryInterface */
24
    private $articleRepository;
25
26
    public function __construct(RepositoryInterface $articleRepository)
27
    {
28
        $this->articleRepository = $articleRepository;
29
    }
30
31
    /**
32
     * @Transform /^article "([^"]+)"$/
33
     * @Transform :article
34
     */
35
    public function getArticleByTitle(string $title)
36
    {
37
        /** @var Article $article */
38
        $article = $this->articleRepository->findOneBy(['title' => $title]);
39
40
        Assert::notNull(
41
            $article,
42
            sprintf('Article with title "%s" does not exist', $title)
43
        );
44
45
        return $article;
46
    }
47
}
48