Completed
Push — missing-product-variant-variab... ( 2e9a80...01bfdb )
by Kamil
22:39
created

AutocompleteHelper::waitForElementToBeVisible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
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\Service;
13
14
use Behat\Mink\Driver\Selenium2Driver;
15
use Behat\Mink\Element\NodeElement;
16
use Behat\Mink\Session;
17
use Webmozart\Assert\Assert;
18
19
/**
20
 * @author Kamil Kokot <[email protected]>
21
 */
22
abstract class AutocompleteHelper
0 ignored issues
show
Coding Style introduced by
AutocompleteHelper does not seem to conform to the naming convention (Utils?$).

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...
23
{
24
    /**
25
     * @param Session $session
26
     * @param NodeElement $element
27
     * @param string $value
28
     */
29
    public static function chooseValue(Session $session, NodeElement $element, $value)
30
    {
31
        Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class);
32
33
        static::waitForAsynchronousActionsToFinish($session);
0 ignored issues
show
Bug introduced by
Since waitForAsynchronousActionsToFinish() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of waitForAsynchronousActionsToFinish() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
34
35
        $element->click();
36
37
        static::waitForAsynchronousActionsToFinish($session);
0 ignored issues
show
Bug introduced by
Since waitForAsynchronousActionsToFinish() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of waitForAsynchronousActionsToFinish() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
38
        static::waitForElementToBeVisible($session, $element);
0 ignored issues
show
Bug introduced by
Since waitForElementToBeVisible() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of waitForElementToBeVisible() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
39
40
        $element->find('css', sprintf('div.item:contains("%s")', $value))->click();
41
42
        static::waitForElementToBeVisible($session, $element);
0 ignored issues
show
Bug introduced by
Since waitForElementToBeVisible() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of waitForElementToBeVisible() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
43
    }
44
45
    /**
46
     * @param Session $session
47
     */
48
    private static function waitForAsynchronousActionsToFinish(Session $session)
49
    {
50
        $session->wait(5000, '0 === jQuery.active');
51
    }
52
53
    /**
54
     * @param Session $session
55
     * @param NodeElement $element
56
     */
57
    private static function waitForElementToBeVisible(Session $session, NodeElement $element)
58
    {
59
        $session->wait(5000, sprintf(
60
            '$(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).dropdown("is visible")',
61
            $element->getXpath()
62
        ));
63
    }
64
}
65