TableTrait::checkTable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ByTIC\Codeception\Page\AbstractTraits;
4
5
/**
6
 * Class TableTrait
7
 * @package ByTIC\Codeception\Page\AbstractTraits
8
 */
9
trait TableTrait
10
{
11
    protected $tableLinks = null;
12
13
    public function checkTable()
14
    {
15
        $this->getTester()->seeElement(['css' => $this->getTablePath()]);
16
17
        $links = $this->getTableLinks();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $links is correct as $this->getTableLinks() (which targets ByTIC\Codeception\Page\A...eTrait::getTableLinks()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
18
        $this->getTester()->assertGreaterThanOrEqual(1, count($links), "Check at least 1 table item defined");
19
    }
20
21
    /**
22
     * @return \ByTIC\Common\Tests\AcceptanceTester;
0 ignored issues
show
Documentation introduced by
The doc-type \ByTIC\Common\Tests\AcceptanceTester; could not be parsed: Expected "|" or "end of type", but got ";" at position 36. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
23
     */
24
    abstract protected function getTester();
25
26
    /**
27
     * @return null
28
     */
29
    public function getTablePath()
30
    {
31
        if (!$this->tablePath) {
0 ignored issues
show
Bug introduced by
The property tablePath does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
            $this->getTester()->fail('table path must be set for ['.get_class($this).']');
33
        }
34
35
        return $this->tablePath;
36
    }
37
38
    /**
39
     * @return null
40
     */
41
    public function getTableLinks()
42
    {
43
        if ($this->tableLinks === null) {
44
            $this->initTableLinks();
45
        }
46
47
        return $this->tableLinks;
48
    }
49
50
    public function initTableLinks()
51
    {
52
        $this->tableLinks = $this->getTester()->grabMultiple($this->getFullLinkPath(), 'href');
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getFullLinkPath()
59
    {
60
        return $this->getTablePath().' '.$this->getLinkPath();
61
    }
62
63
    /**
64
     * @return null
65
     */
66
    public function getLinkPath()
67
    {
68
        if (!$this->linkPath) {
0 ignored issues
show
Bug introduced by
The property linkPath does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
69
            $this->getTester()->fail('links path must be set for ['.get_class($this).']');
70
        }
71
72
        return $this->linkPath;
73
    }
74
75
    public function clickTableFirstLink()
76
    {
77
        $links = $this->getTableLinks();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $links is correct as $this->getTableLinks() (which targets ByTIC\Codeception\Page\A...eTrait::getTableLinks()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
78
        $link = reset($links);
79
        $this->getTester()->amOnUrl($link);
80
    }
81
}
82