Completed
Push — master ( 01e9a3...b0156c )
by Kamil
18:54
created

SymfonyPage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 57
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getUrl() 0 11 2
A makePathAbsoluteWithBehatParameter() 0 6 2
A getPath() 0 3 1
getRouteName() 0 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\Page;
13
14
use Behat\Mink\Session;
15
use Symfony\Component\Routing\RouterInterface;
16
17
/**
18
 * @author Arkadiusz Krakowiak <[email protected]>
19
 */
20
abstract class SymfonyPage extends Page
21
{
22
    /**
23
     * @var RouterInterface
24
     */
25
    protected $router;
26
27
    /**
28
     * @param Session $session
29
     * @param array $parameters
30
     * @param RouterInterface $router
31
     */
32
    public function __construct(Session $session, array $parameters, RouterInterface $router)
33
    {
34
        parent::__construct($session, $parameters);
35
36
        $this->router = $router;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function getUrl(array $urlParameters = [])
43
    {
44
        if (null === $this->getRouteName()) {
45
            throw new \RuntimeException('You need to provide route name, null given');
46
        }
47
48
        $url = $this->router->generate($this->getRouteName(), $urlParameters);
49
        $url = $this->makePathAbsoluteWithBehatParameter($url);
50
51
        return $url;
52
    }
53
54
    /**
55
     * @param string $path
56
     *
57
     * @return string
58
     */
59
    protected function makePathAbsoluteWithBehatParameter($path)
60
    {
61
        $baseUrl = rtrim($this->getParameter('base_url'), '/').'/';
62
63
        return 0 !== strpos($path, 'http') ? $baseUrl.ltrim($path, '/') : $path;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     *
69
     * Not used by Symfony page.
70
     */
71
    protected function getPath()
72
    {
73
    }
74
75
    abstract protected function getRouteName();
76
}
77