Completed
Push — master ( 968507...279808 )
by Paweł
10:20
created

UpdatePage::isShippingRequired()   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 0
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\ProductVariant;
13
14
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
15
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
16
use Sylius\Component\Core\Model\ChannelInterface;
17
use Sylius\Component\Currency\Model\CurrencyInterface;
18
19
/**
20
 * @author Łukasz Chruściel <[email protected]>
21
 */
22
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
23
{
24
    use ChecksCodeImmutability;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function getCodeElement()
30
    {
31
        return $this->getElement('code');
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function specifyPrice($price)
38
    {
39
        $this->getDocument()->fillField('Price', $price);
40
    }
41
42
    public function disableTracking()
43
    {
44
        $this->getElement('tracked')->uncheck();
45
    }
46
47
    public function enableTracking()
48
    {
49
        $this->getElement('tracked')->check();
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function isTracked()
56
    {
57
        return $this->getElement('tracked')->isChecked();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getPricingConfigurationForChannelAndCurrencyCalculator(ChannelInterface $channel, CurrencyInterface $currency)
64
    {
65
        $priceElement = $this->getElement('pricing_configuration')->find('css', sprintf('label:contains("%s %s")', $channel->getCode(), $currency->getCode()))->getParent();
66
67
        return $priceElement->find('css', 'input')->getValue();
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getPriceForChannel($channelName)
74
    {
75
        return $this->getElement('price', ['%channelName%' => $channelName])->getValue();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getElement...nnelName))->getValue(); (string|boolean|array) is incompatible with the return type declared by the interface Sylius\Behat\Page\Admin\...ace::getPriceForChannel of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getOriginalPriceForChannel($channelName)
82
    {
83
        return $this->getElement('original_price', ['%channelName%' => $channelName])->getValue();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getElement...nnelName))->getValue(); (string|boolean|array) is incompatible with the return type declared by the interface Sylius\Behat\Page\Admin\...OriginalPriceForChannel of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function getNameInLanguage($language)
90
    {
91
        return $this->getElement('name', ['%language%' => $language])->getValue();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getElement...language))->getValue(); (string|boolean|array) is incompatible with the return type declared by the interface Sylius\Behat\Page\Admin\...face::getNameInLanguage of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function specifyCurrentStock($amount)
98
    {
99
        $this->getElement('on_hand')->setValue($amount);
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function isShippingRequired()
106
    {
107
        return $this->getElement('shipping_required')->isChecked();
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    protected function getDefinedElements()
114
    {
115
        return array_merge(parent::getDefinedElements(), [
116
            'code' => '#sylius_product_variant_code',
117
            'name' => '#sylius_product_variant_translations_%language%_name',
118
            'on_hand' => '#sylius_product_variant_onHand',
119
            'original_price' => '#sylius_product_variant_channelPricings > .field:contains("%channelName%") input[name$="[originalPrice]"]',
120
            'price' => '#sylius_product_variant_channelPricings > .field:contains("%channelName%") input[name$="[price]"]',
121
            'pricing_configuration' => '#sylius_calculator_container',
122
            'shipping_required' => '#sylius_product_variant_shippingRequired',
123
            'tracked' => '#sylius_product_variant_tracked',
124
        ]);
125
    }
126
}
127