Completed
Push — checkout-consistent-prices ( af49ca )
by Kamil
13:24
created

TaxonomyElement   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getProductMainTaxon() 0 4 1
A hasProductTaxon() 0 13 3
A getDefinedElements() 0 7 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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Element\Product\ShowPage;
15
16
use Behat\Mink\Element\NodeElement;
17
use FriendsOfBehat\PageObjectExtension\Element\Element;
18
19
final class TaxonomyElement extends Element implements TaxonomyElementIterface
20
{
21
    public function getProductMainTaxon(): string
22
    {
23
        return $this->getElement('main_taxon')->getText();
24
    }
25
26
    public function hasProductTaxon(string $taxonName): bool
27
    {
28
        $taxons = $this->getElement('product_taxon');
29
30
        /** @var NodeElement $taxon */
31
        foreach ($taxons->findAll('css', 'li') as $taxon) {
32
            if ($taxon->getText() === $taxonName) {
33
                return true;
34
            }
35
        }
36
37
        return false;
38
    }
39
40
    protected function getDefinedElements(): array
41
    {
42
        return array_merge(parent::getDefinedElements(), [
43
            'main_taxon' => '#taxonomy tr:contains("Main taxon") td:nth-child(2)',
44
            'product_taxon' => '#taxonomy tr:contains("Product taxon") td:nth-child(2)',
45
        ]);
46
    }
47
}
48