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

IndexPage::isCurrencyEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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