Skip to content

Commit

Permalink
Merge pull request #856 from stof/add_parameter_types
Browse files Browse the repository at this point in the history
Add type for all method parameters that can have them
  • Loading branch information
stof authored Jun 15, 2023
2 parents 6816350 + 577483d commit 9ea43c2
Show file tree
Hide file tree
Showing 21 changed files with 248 additions and 260 deletions.
102 changes: 48 additions & 54 deletions src/Driver/CoreDriver.php

Large diffs are not rendered by default.

100 changes: 47 additions & 53 deletions src/Driver/DriverInterface.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Element/DocumentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getContent()
*
* @return bool
*/
public function hasContent($content)
public function hasContent(string $content)
{
return $this->has('named', array('content', $content));
}
Expand Down
14 changes: 5 additions & 9 deletions src/Element/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function getSelectorsHandler()
/**
* {@inheritdoc}
*/
public function has($selector, $locator)
public function has(string $selector, $locator)
{
return null !== $this->find($selector, $locator);
}
Expand All @@ -106,12 +106,8 @@ public function isValid()
return 1 === count($this->getDriver()->find($this->getXpath()));
}

public function waitFor($timeout, $callback)
public function waitFor($timeout, callable $callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Given callback is not a valid callable');
}

$start = microtime(true);
$end = $start + $timeout;

Expand All @@ -131,7 +127,7 @@ public function waitFor($timeout, $callback)
/**
* {@inheritdoc}
*/
public function find($selector, $locator)
public function find(string $selector, $locator)
{
$items = $this->findAll($selector, $locator);

Expand All @@ -141,7 +137,7 @@ public function find($selector, $locator)
/**
* {@inheritdoc}
*/
public function findAll($selector, $locator)
public function findAll(string $selector, $locator)
{
return $this->elementFinder->findAll($selector, $locator, $this->getXpath());
}
Expand Down Expand Up @@ -183,7 +179,7 @@ public function getOuterHtml()
*
* @deprecated as of 1.7, to be removed in 2.0
*/
protected function elementNotFound($type, $selector = null, $locator = null)
protected function elementNotFound(string $type, ?string $selector = null, ?string $locator = null)
{
@trigger_error(sprintf('The method %s is deprecated as of 1.7 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED);

Expand Down
10 changes: 4 additions & 6 deletions src/Element/ElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getSession();
*
* @see ElementInterface::findAll for the supported selectors
*/
public function has($selector, $locator);
public function has(string $selector, $locator);

/**
* Checks if an element still exists in the DOM.
Expand All @@ -71,10 +71,8 @@ public function isValid();
* @return mixed
*
* @phpstan-return T
*
* @throws \InvalidArgumentException When invalid callback given.
*/
public function waitFor($timeout, $callback);
public function waitFor($timeout, callable $callback);

/**
* Finds first element with specified selector inside the current element.
Expand All @@ -86,7 +84,7 @@ public function waitFor($timeout, $callback);
*
* @see ElementInterface::findAll for the supported selectors
*/
public function find($selector, $locator);
public function find(string $selector, $locator);

/**
* Finds all elements with specified selector inside the current element.
Expand All @@ -106,7 +104,7 @@ public function find($selector, $locator);
*
* @see NamedSelector for the locators supported by the named selectors
*/
public function findAll($selector, $locator);
public function findAll(string $selector, $locator);

/**
* Returns element text (inside tag).
Expand Down
36 changes: 15 additions & 21 deletions src/Element/NodeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class NodeElement extends TraversableElement
* @param string $xpath element xpath
* @param Session $session session instance
*/
public function __construct($xpath, Session $session)
public function __construct(string $xpath, Session $session)
{
$this->xpath = $xpath;

Expand Down Expand Up @@ -125,7 +125,7 @@ public function setValue($value)
*
* @return bool
*/
public function hasAttribute($name)
public function hasAttribute(string $name)
{
return null !== $this->getDriver()->getAttribute($this->getXpath(), $name);
}
Expand All @@ -137,7 +137,7 @@ public function hasAttribute($name)
*
* @return string|null
*/
public function getAttribute($name)
public function getAttribute(string $name)
{
return $this->getDriver()->getAttribute($this->getXpath(), $name);
}
Expand All @@ -149,7 +149,7 @@ public function getAttribute($name)
*
* @return bool
*/
public function hasClass($className)
public function hasClass(string $className)
{
$class = $this->getAttribute('class');

Expand Down Expand Up @@ -255,7 +255,7 @@ public function isChecked()
*
* @throws ElementNotFoundException when the option is not found in the select box
*/
public function selectOption($option, $multiple = false)
public function selectOption(string $option, bool $multiple = false)
{
if ('select' !== $this->getTagName()) {
$this->getDriver()->selectOption($this->getXpath(), $option, $multiple);
Expand Down Expand Up @@ -297,7 +297,7 @@ public function isSelected()
*
* @return void
*/
public function attachFile($path)
public function attachFile(string $path)
{
$this->getDriver()->attachFile($this->getXpath(), $path);
}
Expand Down Expand Up @@ -357,44 +357,38 @@ public function blur()
/**
* Presses specific keyboard key.
*
* @param string|int $char could be either char ('b') or char-code (98)
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*
* @phpstan-param KeyModifier::*|null $modifier
* @param string|int $char could be either char ('b') or char-code (98)
* @param KeyModifier::*|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*
* @return void
*/
public function keyPress($char, $modifier = null)
public function keyPress($char, ?string $modifier = null)
{
$this->getDriver()->keyPress($this->getXpath(), $char, $modifier);
}

/**
* Pressed down specific keyboard key.
*
* @param string|int $char could be either char ('b') or char-code (98)
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*
* @phpstan-param KeyModifier::*|null $modifier
* @param string|int $char could be either char ('b') or char-code (98)
* @param KeyModifier::*|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*
* @return void
*/
public function keyDown($char, $modifier = null)
public function keyDown($char, ?string $modifier = null)
{
$this->getDriver()->keyDown($this->getXpath(), $char, $modifier);
}

/**
* Pressed up specific keyboard key.
*
* @param string|int $char could be either char ('b') or char-code (98)
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*
* @phpstan-param KeyModifier::*|null $modifier
* @param string|int $char could be either char ('b') or char-code (98)
* @param KeyModifier::*|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*
* @return void
*/
public function keyUp($char, $modifier = null)
public function keyUp($char, ?string $modifier = null)
{
$this->getDriver()->keyUp($this->getXpath(), $char, $modifier);
}
Expand Down
40 changes: 20 additions & 20 deletions src/Element/TraversableElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class TraversableElement extends Element
*
* @return NodeElement|null
*/
public function findById($id)
public function findById(string $id)
{
return $this->find('named', array('id', $id));
}
Expand All @@ -38,7 +38,7 @@ public function findById($id)
*
* @return bool
*/
public function hasLink($locator)
public function hasLink(string $locator)
{
return null !== $this->findLink($locator);
}
Expand All @@ -50,7 +50,7 @@ public function hasLink($locator)
*
* @return NodeElement|null
*/
public function findLink($locator)
public function findLink(string $locator)
{
return $this->find('named', array('link', $locator));
}
Expand All @@ -64,7 +64,7 @@ public function findLink($locator)
*
* @throws ElementNotFoundException
*/
public function clickLink($locator)
public function clickLink(string $locator)
{
$link = $this->findLink($locator);

Expand All @@ -82,7 +82,7 @@ public function clickLink($locator)
*
* @return bool
*/
public function hasButton($locator)
public function hasButton(string $locator)
{
return null !== $this->findButton($locator);
}
Expand All @@ -94,7 +94,7 @@ public function hasButton($locator)
*
* @return NodeElement|null
*/
public function findButton($locator)
public function findButton(string $locator)
{
return $this->find('named', array('button', $locator));
}
Expand All @@ -108,7 +108,7 @@ public function findButton($locator)
*
* @throws ElementNotFoundException
*/
public function pressButton($locator)
public function pressButton(string $locator)
{
$button = $this->findButton($locator);

Expand All @@ -126,7 +126,7 @@ public function pressButton($locator)
*
* @return bool
*/
public function hasField($locator)
public function hasField(string $locator)
{
return null !== $this->findField($locator);
}
Expand All @@ -138,24 +138,24 @@ public function hasField($locator)
*
* @return NodeElement|null
*/
public function findField($locator)
public function findField(string $locator)
{
return $this->find('named', array('field', $locator));
}

/**
* Fills in field (input, textarea, select) with specified locator.
*
* @param string $locator input id, name or label
* @param string $value value
* @param string $locator input id, name or label
* @param string|bool|array $value value
*
* @return void
*
* @throws ElementNotFoundException
*
* @see NodeElement::setValue
*/
public function fillField($locator, $value)
public function fillField(string $locator, $value)
{
$field = $this->findField($locator);

Expand All @@ -175,7 +175,7 @@ public function fillField($locator, $value)
*
* @see NodeElement::isChecked
*/
public function hasCheckedField($locator)
public function hasCheckedField(string $locator)
{
$field = $this->findField($locator);

Expand All @@ -191,7 +191,7 @@ public function hasCheckedField($locator)
*
* @see NodeElement::isChecked
*/
public function hasUncheckedField($locator)
public function hasUncheckedField(string $locator)
{
$field = $this->findField($locator);

Expand All @@ -207,7 +207,7 @@ public function hasUncheckedField($locator)
*
* @throws ElementNotFoundException
*/
public function checkField($locator)
public function checkField(string $locator)
{
$field = $this->findField($locator);

Expand All @@ -227,7 +227,7 @@ public function checkField($locator)
*
* @throws ElementNotFoundException
*/
public function uncheckField($locator)
public function uncheckField(string $locator)
{
$field = $this->findField($locator);

Expand All @@ -245,7 +245,7 @@ public function uncheckField($locator)
*
* @return bool
*/
public function hasSelect($locator)
public function hasSelect(string $locator)
{
return $this->has('named', array('select', $locator));
}
Expand All @@ -263,7 +263,7 @@ public function hasSelect($locator)
*
* @see NodeElement::selectOption
*/
public function selectFieldOption($locator, $value, $multiple = false)
public function selectFieldOption(string $locator, string $value, bool $multiple = false)
{
$field = $this->findField($locator);

Expand All @@ -281,7 +281,7 @@ public function selectFieldOption($locator, $value, $multiple = false)
*
* @return bool
*/
public function hasTable($locator)
public function hasTable(string $locator)
{
return $this->has('named', array('table', $locator));
}
Expand All @@ -298,7 +298,7 @@ public function hasTable($locator)
*
* @see NodeElement::attachFile
*/
public function attachFileToField($locator, $path)
public function attachFileToField(string $locator, string $path)
{
$field = $this->findField($locator);

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/DriverException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DriverException extends Exception
* @param int $code
* @param \Throwable|null $previous
*/
public function __construct($message, $code = 0, \Throwable $previous = null)
public function __construct(string $message, int $code = 0, \Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ElementHtmlException.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ElementHtmlException extends ExpectationException
* @param Element $element element
* @param \Throwable|null $exception expectation exception
*/
public function __construct($message, $driver, Element $element, \Throwable $exception = null)
public function __construct(string $message, $driver, Element $element, \Throwable $exception = null)
{
$this->element = $element;

Expand Down
Loading

0 comments on commit 9ea43c2

Please sign in to comment.