Completed
Push — master ( d81c19...f57266 )
by Kamil
20s
created

Sylius/Behat/Page/Admin/Customer/UpdatePage.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Customer;
15
16
use Sylius\Behat\Behaviour\Toggles;
17
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
18
19
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
20
{
21
    use Toggles;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getFullName()
27
    {
28
        $firstNameElement = $this->getElement('first_name')->getValue();
29
        $lastNameElement = $this->getElement('last_name')->getValue();
30
31
        return sprintf('%s %s', $firstNameElement, $lastNameElement);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function changeFirstName($firstName)
38
    {
39
        $this->getDocument()->fillField('First name', $firstName);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getFirstName()
46
    {
47
        return $this->getElement('first_name')->getValue();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function changeLastName($lastName)
54
    {
55
        $this->getDocument()->fillField('Last name', $lastName);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getLastName()
62
    {
63
        return $this->getElement('last_name')->getValue();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function changeEmail($email)
70
    {
71
        $this->getDocument()->fillField('Email', $email);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function changePassword($password)
78
    {
79
        $this->getDocument()->fillField('Password', $password);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getPassword()
86
    {
87
        return $this->getElement('password');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getElement('password'); (Behat\Mink\Element\NodeElement) is incompatible with the return type declared by the interface Sylius\Behat\Page\Admin\...eInterface::getPassword 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...
88
    }
89
90
    public function subscribeToTheNewsletter()
91
    {
92
        $this->getDocument()->checkField('Subscribe to the newsletter');
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function isSubscribedToTheNewsletter()
99
    {
100
        return $this->getDocument()->hasCheckedField('Subscribe to the newsletter');
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function getGroupName()
107
    {
108
        return $this->getElement('group')->getText();
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    protected function getToggleableElement()
115
    {
116
        return $this->getElement('enabled');
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122
    protected function getDefinedElements()
123
    {
124
        return array_merge(parent::getDefinedElements(), [
125
            'email' => '#sylius_customer_email',
126
            'enabled' => '#sylius_customer_user_enabled',
127
            'first_name' => '#sylius_customer_firstName',
128
            'group' => '#sylius_customer_group',
129
            'last_name' => '#sylius_customer_lastName',
130
            'password' => '#sylius_customer_user_password',
131
        ]);
132
    }
133
}
134