Dropdown   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSearchSelector() 0 4 1
A getFilterSelector() 0 4 1
A setValue() 0 4 1
A withItems() 0 6 1
A isVisible() 0 9 3
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\tests\_support\Page\Widget\Input;
12
13
/**
14
 * Class Dropdown.
15
 *
16
 * Represents dropdown input element
17
 */
18
class Dropdown extends TestableInput
19
{
20
    /**
21
     * @property string[]|null
22
     */
23
    private $items;
24
25
    /**
26
     * @return string
27
     */
28
    protected function getSearchSelector(): string
29
    {
30
        return self::AS_BASE . "div[data-title='{$this->title}']>select";
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    protected function getFilterSelector(): string
37
    {
38
        return self::TF_BASE . "select[name*={$this->auxName}]";
39
    }
40
41
    /**
42
     * @param string $value
43
     */
44
    public function setValue(string $value): void
45
    {
46
        $this->tester->selectOption($this->selector, $value);
47
    }
48
49
    /**
50
     * @param string[] $items array of items names
51
     * @return self
52
     */
53
    public function withItems(array $items): Dropdown
54
    {
55
        $this->items = $items;
56
57
        return $this;
58
    }
59
60
    public function isVisible(): void
61
    {
62
        parent::isVisible();
63
        if ($this->items) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->items of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
64
            foreach ($this->items as $item) {
65
                $this->tester->see($item, $this->selector . ' option');
66
            }
67
        }
68
    }
69
}
70