Completed
Push — example/managing-articles ( b68239 )
by Loïc
02:46
created

ArticleContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A thereIsAnAdministratorIdentifiedBy() 0 4 1
A createArticle() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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 App\Behat\Context\Setup;
13
14
use App\Behat\Service\SharedStorageInterface;
15
use App\Entity\Article;
16
use App\Fixture\Factory\ExampleFactoryInterface;
17
use Behat\Behat\Context\Context;
18
use Sylius\Component\Resource\Repository\RepositoryInterface;
19
20
class ArticleContext implements Context
21
{
22
    /**
23
     * @var SharedStorageInterface
24
     */
25
    private $sharedStorage;
26
27
    /**
28
     * @var ExampleFactoryInterface
29
     */
30
    private $articleFactory;
31
32
    /**
33
     * @var RepositoryInterface
34
     */
35
    private $articleRepository;
36
37
    /**
38
     * @param SharedStorageInterface  $sharedStorage
39
     * @param ExampleFactoryInterface $articleFactory
40
     * @param RepositoryInterface     $articleRepository
41
     */
42
    public function __construct(
43
        SharedStorageInterface $sharedStorage,
44
        ExampleFactoryInterface $articleFactory,
45
        RepositoryInterface $articleRepository
46
    ) {
47
        $this->sharedStorage = $sharedStorage;
48
        $this->articleFactory = $articleFactory;
49
        $this->articleRepository = $articleRepository;
50
    }
51
52
    /**
53
     * @Given there is (also )an article titled :title
54
     */
55
    public function thereIsAnAdministratorIdentifiedBy(string $title): void
56
    {
57
        $this->createArticle(['title' => $title]);
58
    }
59
60
    /**
61
     * @param array $options
62
     */
63
    private function createArticle(array $options): void
64
    {
65
        /** @var Article $article */
66
        $article = $this->articleFactory->create($options);
67
        $this->articleRepository->add($article);
68
        $this->sharedStorage->set('article', $article);
69
    }
70
}
71