Completed
Push — master ( 8da333...8f94e6 )
by Kamil
05:27 queued 12s
created

DetailsElement   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getProductCode() 0 4 1
A hasChannel() 0 13 3
A countChannels() 0 10 2
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 countChannels(): int
41
    {
42
        if (!$this->hasElement('channels')) {
43
            return 0;
44
        }
45
46
        $channels = $this->getElement('channels')->findAll('css', 'span.channel-name');
47
48
        return \count($channels);
49
    }
50
51
    public function getProductCurrentStock(): int
52
    {
53
        return (int) $this->getElement('current_stock')->getText();
54
    }
55
56
    public function getProductTaxCategory(): string
57
    {
58
        return $this->getElement('tax_category')->getText();
59
    }
60
61
    protected function getDefinedElements(): array
62
    {
63
        return array_merge(parent::getDefinedElements(), [
64
            'channels' => '#details tr:contains("Channels") td:nth-child(2)',
65
            'current_stock' => '#details tr:contains("Current stock") td:nth-child(2)',
66
            'product_code' => '#details tr:contains("Code") td:nth-child(2)',
67
            'tax_category' => '#details tr:contains("Tax category") td:nth-child(2)',
68
        ]);
69
    }
70
}
71