Completed
Push — master ( 4c7b9c...e919dc )
by Kamil
21:11
created

IndexPage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 7
nc 1
nop 4
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\Shop\Account\Order;
13
14
use Behat\Mink\Session;
15
use Sylius\Behat\Page\SymfonyPage;
16
use Sylius\Behat\Service\Accessor\TableAccessorInterface;
17
use Symfony\Component\Routing\RouterInterface;
18
19
/**
20
 * @author Grzegorz Sadowski <[email protected]>
21
 */
22
class IndexPage extends SymfonyPage implements IndexPageInterface
23
{
24
    /**
25
     * @var TableAccessorInterface
26
     */
27
    private $tableAccessor;
28
29
    /**
30
     * @param Session $session
31
     * @param array $parameters
32
     * @param RouterInterface $router
33
     * @param TableAccessorInterface $tableAccessor
34
     */
35
    public function __construct(
36
        Session $session,
37
        array $parameters,
38
        RouterInterface $router,
39
        TableAccessorInterface $tableAccessor
40
    ) {
41
        parent::__construct($session, $parameters, $router);
42
43
        $this->tableAccessor = $tableAccessor;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getRouteName()
50
    {
51
        return 'sylius_shop_account_order_index';
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function countOrders()
58
    {
59
        return $this->tableAccessor->countTableBodyRows($this->getElement('customer_orders'));
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function isOrderWithNumberInTheList($number)
66
    {
67
        try {
68
            $rows = $this->tableAccessor->getRowsWithFields(
69
                $this->getElement('customer_orders'),
70
                ['number' => $number]
71
            );
72
73
            return 1 === count($rows);
74
75
        } catch (\InvalidArgumentException $exception) {
76
            return false;
77
        }
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    protected function getDefinedElements()
84
    {
85
        return array_merge(parent::getDefinedElements(), [
86
            'customer_orders' => '#sylius-customer-orders',
87
        ]);
88
    }
89
}
90