Completed
Push — develop ( 723ec8...69e22a )
by Peter
08:18
created

ClickTrait::clickLink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 8
rs 9.4285
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDev/ for the canonical source repository
6
 * @copyright   Copyright (c) 2018 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDev\Test\Selenium;
11
12
/**
13
 * Trait ClickTrait
14
 */
15
trait ClickTrait
16
{
17
    /**
18
     * Clicks on a link
19
     *
20
     * @param string $linkText
21
     * @param callable $callback
22
     * @param float $sleep
23
     * @return $this
24
     */
25
    protected function clickLink($linkText, callable $callback = null, $sleep = 2.0)
26
    {
27
        $elm = $this->elementByLinkText($linkText);
0 ignored issues
show
Bug introduced by
It seems like elementByLinkText() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
28
        $elm->click();
29
        $callback and call_user_func($callback, $elm);
30
        $this->sleep($sleep);
0 ignored issues
show
Bug introduced by
It seems like sleep() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
31
        return $this;
32
    }
33
34
    /**
35
     * Clicks on ajax-link
36
     *
37
     * @param string $linkText
38
     * @param callable $callback
39
     * @return $this
40
     */
41
    protected function clickAjaxLink($linkText, callable $callback = null)
42
    {
43
        $this->clickLink($linkText, $callback, 0);
44
        $this->waitForAjax();
0 ignored issues
show
Bug introduced by
It seems like waitForAjax() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
45
        return $this;
46
    }
47
48
    /**
49
     * @param string $class
50
     * @return $this
51
     */
52
    protected function clickByClass($class)
53
    {
54
        $this->elementByClassName($class)->click();
0 ignored issues
show
Bug introduced by
It seems like elementByClassName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
55
        return $this;
56
    }
57
58
    /**
59
     * @param string $name
60
     * @param string $value
61
     * @return $this
62
     * @deprecated use getSelect()
63
     */
64
    protected function clickSelect($name, $value)
65
    {
66
        $selector = sprintf('select[name="%s"] option[value="%s"]', $name, $value);
67
        $this->elementByCssSelector($selector)->click();
0 ignored issues
show
Bug introduced by
It seems like elementByCssSelector() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
68
        return $this;
69
    }
70
}
71