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

DetailsElement   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getProductCode() 0 4 1
A hasChannel() 0 13 3
A getProductCurrentStock() 0 4 1
A getProductTaxCategory() 0 4 1
A getDefinedElements() 0 9 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 DetailsElement extends Element implements DetailsElementInterface
20
{
21
    public function getProductCode(): string
22
    {
23
        return $this->getElement('product_code')->getText();
24
    }
25
26
    public function hasChannel(string $channelName): bool
27
    {
28
        $channels = $this->getElement('channels');
29
30
        /** @var NodeElement $channel */
31
        foreach ($channels->findAll('css', 'span') as $channel) {
32
            if ($channel->getText() === $channelName) {
33
                return true;
34
            }
35
        }
36
37
        return false;
38
    }
39
40
    public function getProductCurrentStock(): int
41
    {
42
        return (int) $this->getElement('current_stock')->getText();
43
    }
44
45
    public function getProductTaxCategory(): string
46
    {
47
        return $this->getElement('tax_category')->getText();
48
    }
49
50
    protected function getDefinedElements(): array
51
    {
52
        return array_merge(parent::getDefinedElements(), [
53
            'channels' => '#details tr:contains("Channels") td:nth-child(2)',
54
            'current_stock' => '#details tr:contains("Current stock") td:nth-child(2)',
55
            'product_code' => '#details tr:contains("Code") td:nth-child(2)',
56
            'tax_category' => '#details tr:contains("Tax category") td:nth-child(2)',
57
        ]);
58
    }
59
}
60