Completed
Push — symfony3-validation-fail ( 1a4398 )
by Kamil
26:23 queued 08:51
created

UpdatePage::specifyFirstName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\Order;
13
14
use Behat\Mink\Element\NodeElement;
15
use Behat\Mink\Exception\ElementNotFoundException;
16
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
17
use Sylius\Component\Addressing\Model\AddressInterface;
18
19
/**
20
 * @author Grzegorz Sadowski <[email protected]>
21
 */
22
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
23
{
24
    const TYPE_BILLING = 'billing';
25
    const TYPE_SHIPPING = 'shipping';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function specifyBillingAddress(AddressInterface $address)
31
    {
32
        $this->specifyAddress($address, UpdatePage::TYPE_BILLING);
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function specifyShippingAddress(AddressInterface $address)
39
    {
40
        $this->specifyAddress($address, UpdatePage::TYPE_SHIPPING);
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
41
    }
42
    
43
    /**
44
     * {@inheritdoc}
45
     */
46
    private function specifyAddress(AddressInterface $address, $addressType)
47
    {
48
        $this->specifyElementValue($addressType.'_first_name', $address->getFirstName());
49
        $this->specifyElementValue($addressType.'_last_name', $address->getLastName());
50
        $this->specifyElementValue($addressType.'_street', $address->getStreet());
51
        $this->specifyElementValue($addressType.'_city', $address->getCity());
52
        $this->specifyElementValue($addressType.'_postcode', $address->getPostcode());
53
54
        $this->chooseCountry($address->getCountryCode(), $addressType);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     *
60
     * @throws ElementNotFoundException
61
     */
62
    public function checkValidationMessageFor($element, $message)
0 ignored issues
show
Coding Style introduced by
function checkValidationMessageFor() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
63
    {
64
        $foundElement = $this->getFieldElement($element);
65
        if (null === $foundElement) {
66
            throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error');
67
        }
68
69
        $validationMessage = $foundElement->find('css', '.sylius-validation-error');
70
        if (null === $validationMessage) {
71
            throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error');
72
        }
73
74
        return $message === $validationMessage->getText();
75
    }
76
    
77
    /**
78
     * {@inheritdoc}
79
     */
80
    protected function getDefinedElements()
81
    {
82
        return array_merge(parent::getDefinedElements(), [
83
            'billing_city' => '#sylius_order_billingAddress_city',
84
            'billing_country' => '#sylius_order_billingAddress_countryCode',
85
            'billing_first_name' => '#sylius_order_billingAddress_firstName',
86
            'billing_last_name' => '#sylius_order_billingAddress_lastName',
87
            'billing_postcode' => '#sylius_order_billingAddress_postcode',
88
            'billing_street' => '#sylius_order_billingAddress_street',
89
            'shipping_city' => '#sylius_order_shippingAddress_city',
90
            'shipping_country' => '#sylius_order_shippingAddress_countryCode',
91
            'shipping_first_name' => '#sylius_order_shippingAddress_firstName',
92
            'shipping_last_name' => '#sylius_order_shippingAddress_lastName',
93
            'shipping_postcode' => '#sylius_order_shippingAddress_postcode',
94
            'shipping_street' => '#sylius_order_shippingAddress_street',
95
        ]);
96
    }
97
98
    /**
99
     * @param string $elementName
100
     * @param string $value
101
     *
102
     * @throws ElementNotFoundException
103
     */
104
    private function specifyElementValue($elementName, $value)
105
    {
106
        $this->getElement($elementName)->setValue($value);
107
    }
108
109
    /**
110
     * @param string $country
111
     * @param string $addressType
112
     *
113
     * @throws ElementNotFoundException
114
     */
115
    private function chooseCountry($country, $addressType)
116
    {
117
        $this->getElement($addressType.'_country')->selectOption((null !== $country) ? $country : 'Select');
118
    }
119
120
    /**
121
     * @param string $element
122
     *
123
     * @return NodeElement|null
124
     *
125
     * @throws ElementNotFoundException
126
     */
127
    private function getFieldElement($element)
0 ignored issues
show
Bug introduced by
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
128
    {
129
        $element = $this->getElement($element);
130
        while (null !== $element && !($element->hasClass('field'))) {
131
            $element = $element->getParent();
132
        }
133
134
        return $element;
135
    }
136
137
}
138