Completed
Push — upgrade ( c4e463 )
by Kamil
22:47
created

SlugGenerationHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 82
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A waitForSlugGeneration() 0 8 1
A enableSlugModification() 0 11 1
A isSlugReadonly() 0 10 2
A waitForElementToBeClickable() 0 7 1
A isElementReadonly() 0 7 1
A waitForAsynchronousActionsToFinish() 0 4 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\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 Jan Góralski <[email protected]>
21
 */
22
abstract class SlugGenerationHelper
0 ignored issues
show
Coding Style introduced by
SlugGenerationHelper 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
     */
28
    public static function waitForSlugGeneration(Session $session, NodeElement $element)
29
    {
30
        Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class);
31
32
        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...
33
        static::isElementReadonly($session, $element);
0 ignored issues
show
Bug introduced by
Since isElementReadonly() 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 isElementReadonly() 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
        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...
35
    }
36
37
    /**
38
     * @param Session $session
39
     * @param NodeElement $element
40
     */
41
    public static function enableSlugModification(Session $session, NodeElement $element)
42
    {
43
        Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class);
44
45
        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...
46
        static::waitForElementToBeClickable($session, $element);
0 ignored issues
show
Bug introduced by
Since waitForElementToBeClickable() 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 waitForElementToBeClickable() 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...
47
48
        $element->click();
49
50
        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...
51
    }
52
53
    /**
54
     * @param Session $session
55
     * @param NodeElement $element
56
     *
57
     * @return bool
58
     */
59
    public static function isSlugReadonly(Session $session, NodeElement $element)
60
    {
61
        if (!$session->getDriver() instanceof Selenium2Driver) {
62
            return $element->hasAttribute('readonly');
63
        }
64
65
        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...
66
67
        return static::isElementReadonly($session, $element);
0 ignored issues
show
Bug introduced by
Since isElementReadonly() 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 isElementReadonly() 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...
68
    }
69
70
    /**
71
     * @param Session $session
72
     * @param NodeElement $element
73
     */
74
    private static function waitForElementToBeClickable(Session $session, NodeElement $element)
75
    {
76
        $session->wait(5000, sprintf(
77
            'false === $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).hasClass("loading")',
78
            $element->getParent()->getParent()->getXpath()
79
        ));
80
    }
81
82
    /**
83
     * @param Session $session
84
     * @param NodeElement $element
85
     *
86
     * @return bool
87
     */
88
    private static function isElementReadonly(Session $session, NodeElement $element)
89
    {
90
        return $session->wait(5000, sprintf(
91
            'undefined != $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).attr("readonly")',
92
            $element->getXpath()
93
        ));
94
    }
95
96
    /**
97
     * @param Session $session
98
     */
99
    private static function waitForAsynchronousActionsToFinish(Session $session)
100
    {
101
        $session->wait(5000, '0 === jQuery.active');
102
    }
103
}
104