Completed
Push — master ( 4e9462...2570d1 )
by Kamil
18:48
created

IndexPage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 1
cbo 3
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A isThereShippingMethodNamed() 0 14 3
A getRouteName() 0 4 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\Admin\ShippingMethod;
13
14
use Behat\Mink\Session;
15
use Sylius\Behat\Page\SymfonyPage;
16
use Sylius\Behat\TableManipulatorInterface;
17
use Symfony\Component\Routing\RouterInterface;
18
19
/**
20
 * @author Jan Góralski <[email protected]>
21
 */
22
class IndexPage extends SymfonyPage implements IndexPageInterface
23
{
24
    /**
25
     * @var TableManipulatorInterface
26
     */
27
    private $tableManipulator;
28
29
    /**
30
     * {@inheritdoc}
31
     *
32
     * @param TableManipulatorInterface $tableManipulator
33
     */
34
    public function __construct(
35
        Session $session,
36
        array $parameters,
37
        RouterInterface $router,
38
        TableManipulatorInterface $tableManipulator
39
    ) {
40
        parent::__construct($session, $parameters, $router);
41
42
        $this->tableManipulator = $tableManipulator;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function isThereShippingMethodNamed($name)
49
    {
50
        if (null === $table = $this->getDocument()->find('css', 'table')) {
51
            return false;
52
        }
53
54
        try {
55
            $row = $this->tableManipulator->getRowWithFields($table, ['name' => $name]);
56
        } catch (\InvalidArgumentException $exception) {
57
            return false;
58
        }
59
60
        return 1 === $row;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    protected function getRouteName()
67
    {
68
        return 'sylius_backend_shipping_method_index';
69
    }
70
}
71