GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 080777...9cdac9 )
by Stuart
07:21
created

TargettedBrowserExpects::isChecked()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 7

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 16
loc 16
rs 9.4286
c 1
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
/**
4
 * Copyright (c) 2011-present Mediasift Ltd
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 *   * Redistributions of source code must retain the above copyright
12
 *     notice, this list of conditions and the following disclaimer.
13
 *
14
 *   * Redistributions in binary form must reproduce the above copyright
15
 *     notice, this list of conditions and the following disclaimer in
16
 *     the documentation and/or other materials provided with the
17
 *     distribution.
18
 *
19
 *   * Neither the names of the copyright holders nor the names of his
20
 *     contributors may be used to endorse or promote products derived
21
 *     from this software without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 *
36
 * @category  Libraries
37
 * @package   Storyplayer/Modules/Browser
38
 * @author    Stuart Herbert <[email protected]>
39
 * @copyright 2011-present Mediasift Ltd www.datasift.com
40
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
41
 * @link      http://datasift.github.io/storyplayer
42
 */
43
44
namespace Storyplayer\SPv2\Modules\Browser;
45
46
use Exception;
47
use DataSift\Storyplayer\PlayerLib\StoryTeller;
48
49
/**
50
 * Helper class for testing elements using convenient, human-like names
51
 * and terms for elements (such as 'buttonLabelled')
52
 *
53
 * @category  Libraries
54
 * @package   Storyplayer/Modules/Browser
55
 * @author    Stuart Herbert <[email protected]>
56
 * @copyright 2011-present Mediasift Ltd www.datasift.com
57
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
58
 * @link      http://datasift.github.io/storyplayer
59
 */
60
class TargettedBrowserExpects
61
{
62
    protected $st;
63
    protected $searchFunction;
64
    protected $searchTerm;
65
    protected $element;
66
    protected $elementType;
67
    protected $elementDesc;
68
69
    /**
70
     * @param string $elementDesc
71
     */
72
    public function __construct(StoryTeller $st, callable $searchFunction, $searchTerm, $elementDesc)
73
    {
74
        $this->st             = $st;
75
        $this->searchFunction = $searchFunction;
76
        $this->searchTerm     = $searchTerm;
77
        $this->elementDesc    = $elementDesc;
78
    }
79
80 View Code Duplication
    public function isBlank()
81
    {
82
        // what are we doing?
83
        $log = usingLog()->startAction("{$this->elementDesc} '{$this->searchTerm}' must be blank");
84
85
        // get the element
86
        $element = $this->getElement();
87
88
        // test it
89
        if (strlen($element->attribute("value")) > 0) {
90
            throw new E5xx_ExpectFailed(__METHOD__, $this->searchTerm . ' is blank', $this->searchTerm . ' is not blank');
91
        }
92
93
        // all done
94
        $log->endAction();
95
        return true;
96
    }
97
98 View Code Duplication
    public function isNotBlank()
99
    {
100
        // what are we doing?
101
        $log = usingLog()->startAction("{$this->elementDesc} '{$this->searchTerm}' must not be blank");
102
103
        // get the element
104
        $element = $this->getElement();
105
106
        // test it
107
        if (strlen($element->attribute("value")) > 0) {
108
            $log->endAction();
109
            return true;
110
        }
111
112
        throw new E5xx_ExpectFailed(__METHOD__, $this->searchTerm . ' is not blank', $this->searchTerm . ' is blank');
113
    }
114
115 View Code Duplication
    public function isChecked()
116
    {
117
        // what are we doing?
118
        $log = usingLog()->startAction("{$this->elementDesc} '{$this->searchTerm}' must be checked");
119
120
        // get the element
121
        $element = $this->getElement();
122
123
        // test it
124
        if ($element->attribute("checked")) {
125
            $log->endAction();
126
            return true;
127
        }
128
129
        throw new E5xx_ExpectFailed(__METHOD__, $this->searchTerm . ' checked', $this->searchTerm . ' not checked');
130
    }
131
132 View Code Duplication
    public function isNotChecked()
133
    {
134
        // what are we doing?
135
        $log = usingLog()->startAction("{$this->elementDesc} '{$this->searchTerm}' must not be checked");
136
137
        // get the element
138
        $element = $this->getElement();
139
140
        // test it
141
        if ($element->attribute("checked")) {
142
            throw new E5xx_ExpectFailed(__METHOD__, $this->searchTerm . ' not checked', $this->searchTerm . ' checked');
143
        }
144
145
        // all done
146
        $log->endAction();
147
        return true;
148
    }
149
150
    protected function getElement()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
151
    {
152
        $callable = $this->searchFunction;
153
154
        $log = usingLog()->startAction("Find element on page with label, id or name '{$this->searchTerm}'");
155
        try {
156
            $element = $callable();
157
            $log->endAction();
158
159
            return $element;
160
        }
161
        catch (Exception $e) {
162
            throw new E5xx_ExpectFailed(__METHOD__, $this->searchTerm . ' exists', 'does not exist');
163
        }
164
    }
165
}
166