Skip to content

Commit 577483d

Browse files
committed
Add type for all method parameters that can have them
The only untyped arguments are the ones using union types.
1 parent 6816350 commit 577483d

21 files changed

+248
-260
lines changed

src/Driver/CoreDriver.php

Lines changed: 48 additions & 54 deletions
Large diffs are not rendered by default.

src/Driver/DriverInterface.php

Lines changed: 47 additions & 53 deletions
Large diffs are not rendered by default.

src/Element/DocumentElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getContent()
4444
*
4545
* @return bool
4646
*/
47-
public function hasContent($content)
47+
public function hasContent(string $content)
4848
{
4949
return $this->has('named', array('content', $content));
5050
}

src/Element/Element.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function getSelectorsHandler()
9393
/**
9494
* {@inheritdoc}
9595
*/
96-
public function has($selector, $locator)
96+
public function has(string $selector, $locator)
9797
{
9898
return null !== $this->find($selector, $locator);
9999
}
@@ -106,12 +106,8 @@ public function isValid()
106106
return 1 === count($this->getDriver()->find($this->getXpath()));
107107
}
108108

109-
public function waitFor($timeout, $callback)
109+
public function waitFor($timeout, callable $callback)
110110
{
111-
if (!is_callable($callback)) {
112-
throw new \InvalidArgumentException('Given callback is not a valid callable');
113-
}
114-
115111
$start = microtime(true);
116112
$end = $start + $timeout;
117113

@@ -131,7 +127,7 @@ public function waitFor($timeout, $callback)
131127
/**
132128
* {@inheritdoc}
133129
*/
134-
public function find($selector, $locator)
130+
public function find(string $selector, $locator)
135131
{
136132
$items = $this->findAll($selector, $locator);
137133

@@ -141,7 +137,7 @@ public function find($selector, $locator)
141137
/**
142138
* {@inheritdoc}
143139
*/
144-
public function findAll($selector, $locator)
140+
public function findAll(string $selector, $locator)
145141
{
146142
return $this->elementFinder->findAll($selector, $locator, $this->getXpath());
147143
}
@@ -183,7 +179,7 @@ public function getOuterHtml()
183179
*
184180
* @deprecated as of 1.7, to be removed in 2.0
185181
*/
186-
protected function elementNotFound($type, $selector = null, $locator = null)
182+
protected function elementNotFound(string $type, ?string $selector = null, ?string $locator = null)
187183
{
188184
@trigger_error(sprintf('The method %s is deprecated as of 1.7 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED);
189185

src/Element/ElementInterface.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getSession();
4545
*
4646
* @see ElementInterface::findAll for the supported selectors
4747
*/
48-
public function has($selector, $locator);
48+
public function has(string $selector, $locator);
4949

5050
/**
5151
* Checks if an element still exists in the DOM.
@@ -71,10 +71,8 @@ public function isValid();
7171
* @return mixed
7272
*
7373
* @phpstan-return T
74-
*
75-
* @throws \InvalidArgumentException When invalid callback given.
7674
*/
77-
public function waitFor($timeout, $callback);
75+
public function waitFor($timeout, callable $callback);
7876

7977
/**
8078
* Finds first element with specified selector inside the current element.
@@ -86,7 +84,7 @@ public function waitFor($timeout, $callback);
8684
*
8785
* @see ElementInterface::findAll for the supported selectors
8886
*/
89-
public function find($selector, $locator);
87+
public function find(string $selector, $locator);
9088

9189
/**
9290
* Finds all elements with specified selector inside the current element.
@@ -106,7 +104,7 @@ public function find($selector, $locator);
106104
*
107105
* @see NamedSelector for the locators supported by the named selectors
108106
*/
109-
public function findAll($selector, $locator);
107+
public function findAll(string $selector, $locator);
110108

111109
/**
112110
* Returns element text (inside tag).

src/Element/NodeElement.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class NodeElement extends TraversableElement
3333
* @param string $xpath element xpath
3434
* @param Session $session session instance
3535
*/
36-
public function __construct($xpath, Session $session)
36+
public function __construct(string $xpath, Session $session)
3737
{
3838
$this->xpath = $xpath;
3939

@@ -125,7 +125,7 @@ public function setValue($value)
125125
*
126126
* @return bool
127127
*/
128-
public function hasAttribute($name)
128+
public function hasAttribute(string $name)
129129
{
130130
return null !== $this->getDriver()->getAttribute($this->getXpath(), $name);
131131
}
@@ -137,7 +137,7 @@ public function hasAttribute($name)
137137
*
138138
* @return string|null
139139
*/
140-
public function getAttribute($name)
140+
public function getAttribute(string $name)
141141
{
142142
return $this->getDriver()->getAttribute($this->getXpath(), $name);
143143
}
@@ -149,7 +149,7 @@ public function getAttribute($name)
149149
*
150150
* @return bool
151151
*/
152-
public function hasClass($className)
152+
public function hasClass(string $className)
153153
{
154154
$class = $this->getAttribute('class');
155155

@@ -255,7 +255,7 @@ public function isChecked()
255255
*
256256
* @throws ElementNotFoundException when the option is not found in the select box
257257
*/
258-
public function selectOption($option, $multiple = false)
258+
public function selectOption(string $option, bool $multiple = false)
259259
{
260260
if ('select' !== $this->getTagName()) {
261261
$this->getDriver()->selectOption($this->getXpath(), $option, $multiple);
@@ -297,7 +297,7 @@ public function isSelected()
297297
*
298298
* @return void
299299
*/
300-
public function attachFile($path)
300+
public function attachFile(string $path)
301301
{
302302
$this->getDriver()->attachFile($this->getXpath(), $path);
303303
}
@@ -357,44 +357,38 @@ public function blur()
357357
/**
358358
* Presses specific keyboard key.
359359
*
360-
* @param string|int $char could be either char ('b') or char-code (98)
361-
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
362-
*
363-
* @phpstan-param KeyModifier::*|null $modifier
360+
* @param string|int $char could be either char ('b') or char-code (98)
361+
* @param KeyModifier::*|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
364362
*
365363
* @return void
366364
*/
367-
public function keyPress($char, $modifier = null)
365+
public function keyPress($char, ?string $modifier = null)
368366
{
369367
$this->getDriver()->keyPress($this->getXpath(), $char, $modifier);
370368
}
371369

372370
/**
373371
* Pressed down specific keyboard key.
374372
*
375-
* @param string|int $char could be either char ('b') or char-code (98)
376-
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
377-
*
378-
* @phpstan-param KeyModifier::*|null $modifier
373+
* @param string|int $char could be either char ('b') or char-code (98)
374+
* @param KeyModifier::*|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
379375
*
380376
* @return void
381377
*/
382-
public function keyDown($char, $modifier = null)
378+
public function keyDown($char, ?string $modifier = null)
383379
{
384380
$this->getDriver()->keyDown($this->getXpath(), $char, $modifier);
385381
}
386382

387383
/**
388384
* Pressed up specific keyboard key.
389385
*
390-
* @param string|int $char could be either char ('b') or char-code (98)
391-
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
392-
*
393-
* @phpstan-param KeyModifier::*|null $modifier
386+
* @param string|int $char could be either char ('b') or char-code (98)
387+
* @param KeyModifier::*|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
394388
*
395389
* @return void
396390
*/
397-
public function keyUp($char, $modifier = null)
391+
public function keyUp($char, ?string $modifier = null)
398392
{
399393
$this->getDriver()->keyUp($this->getXpath(), $char, $modifier);
400394
}

src/Element/TraversableElement.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class TraversableElement extends Element
2626
*
2727
* @return NodeElement|null
2828
*/
29-
public function findById($id)
29+
public function findById(string $id)
3030
{
3131
return $this->find('named', array('id', $id));
3232
}
@@ -38,7 +38,7 @@ public function findById($id)
3838
*
3939
* @return bool
4040
*/
41-
public function hasLink($locator)
41+
public function hasLink(string $locator)
4242
{
4343
return null !== $this->findLink($locator);
4444
}
@@ -50,7 +50,7 @@ public function hasLink($locator)
5050
*
5151
* @return NodeElement|null
5252
*/
53-
public function findLink($locator)
53+
public function findLink(string $locator)
5454
{
5555
return $this->find('named', array('link', $locator));
5656
}
@@ -64,7 +64,7 @@ public function findLink($locator)
6464
*
6565
* @throws ElementNotFoundException
6666
*/
67-
public function clickLink($locator)
67+
public function clickLink(string $locator)
6868
{
6969
$link = $this->findLink($locator);
7070

@@ -82,7 +82,7 @@ public function clickLink($locator)
8282
*
8383
* @return bool
8484
*/
85-
public function hasButton($locator)
85+
public function hasButton(string $locator)
8686
{
8787
return null !== $this->findButton($locator);
8888
}
@@ -94,7 +94,7 @@ public function hasButton($locator)
9494
*
9595
* @return NodeElement|null
9696
*/
97-
public function findButton($locator)
97+
public function findButton(string $locator)
9898
{
9999
return $this->find('named', array('button', $locator));
100100
}
@@ -108,7 +108,7 @@ public function findButton($locator)
108108
*
109109
* @throws ElementNotFoundException
110110
*/
111-
public function pressButton($locator)
111+
public function pressButton(string $locator)
112112
{
113113
$button = $this->findButton($locator);
114114

@@ -126,7 +126,7 @@ public function pressButton($locator)
126126
*
127127
* @return bool
128128
*/
129-
public function hasField($locator)
129+
public function hasField(string $locator)
130130
{
131131
return null !== $this->findField($locator);
132132
}
@@ -138,24 +138,24 @@ public function hasField($locator)
138138
*
139139
* @return NodeElement|null
140140
*/
141-
public function findField($locator)
141+
public function findField(string $locator)
142142
{
143143
return $this->find('named', array('field', $locator));
144144
}
145145

146146
/**
147147
* Fills in field (input, textarea, select) with specified locator.
148148
*
149-
* @param string $locator input id, name or label
150-
* @param string $value value
149+
* @param string $locator input id, name or label
150+
* @param string|bool|array $value value
151151
*
152152
* @return void
153153
*
154154
* @throws ElementNotFoundException
155155
*
156156
* @see NodeElement::setValue
157157
*/
158-
public function fillField($locator, $value)
158+
public function fillField(string $locator, $value)
159159
{
160160
$field = $this->findField($locator);
161161

@@ -175,7 +175,7 @@ public function fillField($locator, $value)
175175
*
176176
* @see NodeElement::isChecked
177177
*/
178-
public function hasCheckedField($locator)
178+
public function hasCheckedField(string $locator)
179179
{
180180
$field = $this->findField($locator);
181181

@@ -191,7 +191,7 @@ public function hasCheckedField($locator)
191191
*
192192
* @see NodeElement::isChecked
193193
*/
194-
public function hasUncheckedField($locator)
194+
public function hasUncheckedField(string $locator)
195195
{
196196
$field = $this->findField($locator);
197197

@@ -207,7 +207,7 @@ public function hasUncheckedField($locator)
207207
*
208208
* @throws ElementNotFoundException
209209
*/
210-
public function checkField($locator)
210+
public function checkField(string $locator)
211211
{
212212
$field = $this->findField($locator);
213213

@@ -227,7 +227,7 @@ public function checkField($locator)
227227
*
228228
* @throws ElementNotFoundException
229229
*/
230-
public function uncheckField($locator)
230+
public function uncheckField(string $locator)
231231
{
232232
$field = $this->findField($locator);
233233

@@ -245,7 +245,7 @@ public function uncheckField($locator)
245245
*
246246
* @return bool
247247
*/
248-
public function hasSelect($locator)
248+
public function hasSelect(string $locator)
249249
{
250250
return $this->has('named', array('select', $locator));
251251
}
@@ -263,7 +263,7 @@ public function hasSelect($locator)
263263
*
264264
* @see NodeElement::selectOption
265265
*/
266-
public function selectFieldOption($locator, $value, $multiple = false)
266+
public function selectFieldOption(string $locator, string $value, bool $multiple = false)
267267
{
268268
$field = $this->findField($locator);
269269

@@ -281,7 +281,7 @@ public function selectFieldOption($locator, $value, $multiple = false)
281281
*
282282
* @return bool
283283
*/
284-
public function hasTable($locator)
284+
public function hasTable(string $locator)
285285
{
286286
return $this->has('named', array('table', $locator));
287287
}
@@ -298,7 +298,7 @@ public function hasTable($locator)
298298
*
299299
* @see NodeElement::attachFile
300300
*/
301-
public function attachFileToField($locator, $path)
301+
public function attachFileToField(string $locator, string $path)
302302
{
303303
$field = $this->findField($locator);
304304

src/Exception/DriverException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DriverException extends Exception
2424
* @param int $code
2525
* @param \Throwable|null $previous
2626
*/
27-
public function __construct($message, $code = 0, \Throwable $previous = null)
27+
public function __construct(string $message, int $code = 0, \Throwable $previous = null)
2828
{
2929
parent::__construct($message, $code, $previous);
3030
}

src/Exception/ElementHtmlException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ElementHtmlException extends ExpectationException
3636
* @param Element $element element
3737
* @param \Throwable|null $exception expectation exception
3838
*/
39-
public function __construct($message, $driver, Element $element, \Throwable $exception = null)
39+
public function __construct(string $message, $driver, Element $element, \Throwable $exception = null)
4040
{
4141
$this->element = $element;
4242

0 commit comments

Comments
 (0)