Completed
Push — sf-44 ( 026126...08883d )
by Kamil
79:34 queued 56:57
created

CreatePage::specifyMenuTaxon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Page\Admin\Channel;
15
16
use Behat\Mink\Element\NodeElement;
17
use Sylius\Behat\Behaviour\DescribesIt;
18
use Sylius\Behat\Behaviour\NamesIt;
19
use Sylius\Behat\Behaviour\SpecifiesItsCode;
20
use Sylius\Behat\Behaviour\Toggles;
21
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
22
use Sylius\Behat\Service\AutocompleteHelper;
23
24
class CreatePage extends BaseCreatePage implements CreatePageInterface
25
{
26
    use NamesIt;
27
    use SpecifiesItsCode;
28
    use DescribesIt;
29
    use Toggles;
30
31
    public function setHostname(string $hostname): void
32
    {
33
        $this->getDocument()->fillField('Hostname', $hostname);
34
    }
35
36
    public function setContactEmail(string $contactEmail): void
37
    {
38
        $this->getDocument()->fillField('Contact email', $contactEmail);
39
    }
40
41
    public function defineColor(string $color): void
42
    {
43
        $this->getDocument()->fillField('Color', $color);
44
    }
45
46
    public function chooseCurrency(string $currencyCode): void
47
    {
48
        $this->getDocument()->selectFieldOption('Currencies', $currencyCode);
49
    }
50
51
    public function chooseLocale(string $language): void
52
    {
53
        $this->getDocument()->selectFieldOption('Locales', $language);
54
    }
55
56
    public function chooseDefaultTaxZone(string $taxZone): void
57
    {
58
        $this->getDocument()->selectFieldOption('Default tax zone', $taxZone);
59
    }
60
61
    public function chooseDefaultLocale(?string $locale): void
62
    {
63
        if (null !== $locale) {
64
            $this->getElement('default_locale')->selectOption($locale);
65
        }
66
    }
67
68
    public function chooseBaseCurrency(?string $currency): void
69
    {
70
        if (null !== $currency) {
71
            $this->getElement('currencies')->selectOption($currency);
72
            $this->getElement('base_currency')->selectOption($currency);
73
        }
74
    }
75
76
    public function chooseTaxCalculationStrategy(string $taxZone): void
77
    {
78
        $this->getDocument()->selectFieldOption('Tax calculation strategy', $taxZone);
79
    }
80
81
    public function allowToSkipShippingStep(): void
82
    {
83
        $this->getDocument()->checkField('Skip shipping step if only one shipping method is available?');
84
    }
85
86
    public function allowToSkipPaymentStep(): void
87
    {
88
        $this->getDocument()->checkField('Skip payment step if only one payment method is available?');
89
    }
90
91
    public function setType(string $type): void
92
    {
93
        $this->getElement('type')->selectOption($type);
94
    }
95
96
    public function specifyMenuTaxon(string $menuTaxon): void
97
    {
98
        $menuTaxonElement = $this->getElement('menu_taxon')->getParent();
99
100
        AutocompleteHelper::chooseValue($this->getSession(), $menuTaxonElement, $menuTaxon);
0 ignored issues
show
Bug introduced by
It seems like $menuTaxonElement defined by $this->getElement('menu_taxon')->getParent() on line 98 can be null; however, Sylius\Behat\Service\Aut...teHelper::chooseValue() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
101
    }
102
103
    protected function getToggleableElement(): NodeElement
104
    {
105
        return $this->getElement('enabled');
106
    }
107
108
    protected function getDefinedElements(): array
109
    {
110
        return array_merge(parent::getDefinedElements(), [
111
            'base_currency' => '#sylius_channel_baseCurrency',
112
            'code' => '#sylius_channel_code',
113
            'currencies' => '#sylius_channel_currencies',
114
            'default_locale' => '#sylius_channel_defaultLocale',
115
            'enabled' => '#sylius_channel_enabled',
116
            'locales' => '#sylius_channel_locales',
117
            'menu_taxon' => '#sylius_channel_menuTaxon',
118
            'name' => '#sylius_channel_name',
119
            'type' => '#sylius_channel_type',
120
        ]);
121
    }
122
}
123