Completed
Push — master ( f906b5...0ffad1 )
by Kamil
17s
created

IndexPage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isCurrencyDisabled() 0 4 1
A isCurrencyEnabled() 0 4 1
A checkCurrencyStatus() 0 10 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\Currency;
13
14
use Sylius\Behat\Page\Admin\Crud\IndexPage as BaseIndexPage;
15
use Sylius\Component\Currency\Model\CurrencyInterface;
16
17
/**
18
 * @author Anna Walasek <[email protected]>
19
 */
20
class IndexPage extends BaseIndexPage implements IndexPageInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function isCurrencyDisabled(CurrencyInterface $currency)
26
    {
27
        return $this->checkCurrencyStatus($currency, 'Disabled');
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function isCurrencyEnabled(CurrencyInterface $currency)
34
    {
35
        return $this->checkCurrencyStatus($currency, 'Enabled');
36
    }
37
38
    /**
39
     * @param CurrencyInterface $currency
40
     * @param string $status
41
     *
42
     * @return bool
43
     *
44
     * @throws \InvalidArgumentException
45
     */
46
    private function checkCurrencyStatus(CurrencyInterface $currency, $status)
47
    {
48
        $tableAccessor = $this->getTableAccessor();
49
        $table = $this->getElement('table');
50
51
        $row = $tableAccessor->getRowWithFields($table, ['code' => $currency->getCode()]);
52
        $enabledField = $tableAccessor->getFieldFromRow($table, $row, 'Enabled');
53
54
        return $enabledField->getText() === $status;
55
    }
56
}
57