Completed
Pull Request — 1.5 (#761)
by Paweł
17:05
created

RouteContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A theFollowingRoutes() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Behat\Contexts;
6
7
use Behat\Behat\Context\Context;
8
use Behat\Gherkin\Node\TableNode;
9
use Doctrine\ORM\EntityManagerInterface;
10
use SWP\Bundle\ContentBundle\Factory\RouteFactoryInterface;
11
use SWP\Bundle\ContentBundle\Model\RouteInterface;
12
use SWP\Bundle\ContentBundle\Model\RouteRepositoryInterface;
13
use SWP\Bundle\ContentBundle\Service\RouteServiceInterface;
14
15
final class RouteContext extends AbstractContext implements Context
16
{
17
    private $entityManager;
18
19
    private $routeFactory;
20
21
    private $routeRepository;
22
23
    private $routeService;
24
25
    public function __construct(
26
        EntityManagerInterface $entityManager,
27
        RouteFactoryInterface $routeFactory,
28
        RouteRepositoryInterface $routeRepository,
29
        RouteServiceInterface $routeService
30
    ) {
31
        $this->entityManager = $entityManager;
32
        $this->routeFactory = $routeFactory;
33
        $this->routeRepository = $routeRepository;
34
        $this->routeService = $routeService;
35
    }
36
37
    /**
38
     * @Given the following Routes:
39
     */
40
    public function theFollowingRoutes(TableNode $table)
41
    {
42
        foreach ($table as $row => $columns) {
43
            /** @var RouteInterface $route */
44
            $route = $this->routeFactory->create();
45
            $this->fillObject($route, $columns);
46
            $this->routeService->createRoute($route);
47
48
            $this->entityManager->persist($route);
49
        }
50
51
        $this->entityManager->flush();
52
    }
53
}
54