Skip to content

Commit

Permalink
Fix implicitly nullable parameters (#660)
Browse files Browse the repository at this point in the history
Add ? to all method arguments that are implicitly nullable, because this
is deprecated in PHP 8.4:
https://www.php.net/manual/en/migration84.deprecated.php
  • Loading branch information
otsch authored Nov 6, 2024
1 parent 9dfbc4a commit 5849ef8
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getConnection(): Connection
*
* @param string|null $script
*/
public function setPagePreScript(string $script = null): void
public function setPagePreScript(?string $script = null): void
{
$this->pagePreScript = $script;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Browser/BrowserProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BrowserProcess implements LoggerAwareInterface
*
* @param LoggerInterface|null $logger
*/
public function __construct(LoggerInterface $logger = null)
public function __construct(?LoggerInterface $logger = null)
{
// set or create logger
$this->setLogger($logger ?? new NullLogger());
Expand Down
2 changes: 1 addition & 1 deletion src/BrowserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BrowserFactory
*/
protected $options = [];

public function __construct(string $chromeBinary = null)
public function __construct(?string $chromeBinary = null)
{
$this->chromeBinary = $chromeBinary ?? (new AutoDiscover())->guessChromeBinaryPath();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Communication/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Connection extends EventEmitter implements LoggerAwareInterface
* @param SocketInterface|string $socketClient
* @param int|null $sendSyncDefaultTimeout
*/
public function __construct($socketClient, LoggerInterface $logger = null, int $sendSyncDefaultTimeout = null)
public function __construct($socketClient, ?LoggerInterface $logger = null, ?int $sendSyncDefaultTimeout = null)
{
// set or create logger
$this->setLogger($logger ?? new NullLogger());
Expand Down Expand Up @@ -264,7 +264,7 @@ public function sendMessage(Message $message): ResponseReader
*
* @return Response
*/
public function sendMessageSync(Message $message, int $timeout = null): Response
public function sendMessageSync(Message $message, ?int $timeout = null): Response
{
$responseReader = $this->sendMessage($message);
$response = $responseReader->waitForResponse($timeout);
Expand Down Expand Up @@ -355,7 +355,7 @@ public function readLine()
*
* @internal
*/
private function dispatchMessage(string $message, Session $session = null)
private function dispatchMessage(string $message, ?Session $session = null)
{
// responses come as json string
$response = \json_decode($message, true);
Expand Down
2 changes: 1 addition & 1 deletion src/Communication/ResponseReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getResponse(): Response
*
* @return Response
*/
public function waitForResponse(int $timeout = null): Response
public function waitForResponse(?int $timeout = null): Response
{
if ($this->hasResponse()) {
return $this->getResponse();
Expand Down
2 changes: 1 addition & 1 deletion src/Communication/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function sendMessage(Message $message): ResponseReader
*
* @return Response
*/
public function sendMessageSync(Message $message, int $timeout = null): Response
public function sendMessageSync(Message $message, ?int $timeout = null): Response
{
$responseReader = $this->sendMessage($message);

Expand Down
2 changes: 1 addition & 1 deletion src/Communication/Socket/Wrench.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Wrench implements SocketInterface, LoggerAwareInterface
/**
* @param WrenchClient $client
*/
public function __construct(WrenchClient $client, LoggerInterface $logger = null)
public function __construct(WrenchClient $client, ?LoggerInterface $logger = null)
{
$this->client = $client;

Expand Down
2 changes: 1 addition & 1 deletion src/Cookies/CookiesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CookiesCollection implements \IteratorAggregate, \Countable
/**
* CookiesCollection constructor.
*/
public function __construct(array $cookies = null)
public function __construct(?array $cookies = null)
{
if ($cookies) {
foreach ($cookies as $cookie) {
Expand Down
2 changes: 1 addition & 1 deletion src/Input/Keyboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function press(string $key): self
*
* @return $this
*/
public function release(string $key = null): self
public function release(?string $key = null): self
{
$this->page->assertNotClosed();

Expand Down
8 changes: 4 additions & 4 deletions src/Input/Mouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(Page $page)
*
* @return $this
*/
public function move(int $x, int $y, array $options = null)
public function move(int $x, int $y, ?array $options = null)
{
$this->page->assertNotClosed();

Expand Down Expand Up @@ -88,7 +88,7 @@ public function move(int $x, int $y, array $options = null)
* @throws \HeadlessChromium\Exception\CommunicationException
* @throws \HeadlessChromium\Exception\NoResponseAvailable
*/
public function press(array $options = null)
public function press(?array $options = null)
{
$this->page->assertNotClosed();
$this->page->getSession()->sendMessageSync(new Message('Input.dispatchMouseEvent', [
Expand All @@ -106,7 +106,7 @@ public function press(array $options = null)
* @throws \HeadlessChromium\Exception\CommunicationException
* @throws \HeadlessChromium\Exception\NoResponseAvailable
*/
public function release(array $options = null)
public function release(?array $options = null)
{
$this->page->assertNotClosed();
$this->page->getSession()->sendMessageSync(new Message('Input.dispatchMouseEvent', [
Expand All @@ -126,7 +126,7 @@ public function release(array $options = null)
* @throws \HeadlessChromium\Exception\CommunicationException
* @throws \HeadlessChromium\Exception\NoResponseAvailable
*/
public function click(array $options = null)
public function click(?array $options = null)
{
$this->press($options);
$this->release($options);
Expand Down
6 changes: 3 additions & 3 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public function waitForElement($selectors, int $position = 1)
*
* @return Clip
*/
public function getFullPageClip(int $timeout = null): Clip
public function getFullPageClip(?int $timeout = null): Clip
{
$contentSize = $this->getLayoutMetrics()->await($timeout)->getCssContentSize();

Expand Down Expand Up @@ -1021,7 +1021,7 @@ public function readAllCookies()
*
* @return CookiesCollection
*/
public function getCookies(int $timeout = null)
public function getCookies(?int $timeout = null)
{
return $this->readCookies()->await($timeout)->getCookies();
}
Expand All @@ -1041,7 +1041,7 @@ public function getCookies(int $timeout = null)
*
* @return CookiesCollection
*/
public function getAllCookies(int $timeout = null)
public function getAllCookies(?int $timeout = null)
{
return $this->readAllCookies()->await($timeout)->getCookies();
}
Expand Down
6 changes: 3 additions & 3 deletions src/PageUtils/PageEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function waitForPageReload($eventName = Page::LOAD, $timeout = 30000): vo
*
* @param int|null $timeout
*/
public function waitForResponse(int $timeout = null)
public function waitForResponse(?int $timeout = null)
{
$this->response = $this->responseReader->waitForResponse($timeout);

Expand Down Expand Up @@ -102,7 +102,7 @@ public function waitForResponse(int $timeout = null)
*
* @return mixed
*/
public function getReturnValue(int $timeout = null)
public function getReturnValue(?int $timeout = null)
{
if (!$this->response) {
$this->waitForResponse($timeout);
Expand All @@ -120,7 +120,7 @@ public function getReturnValue(int $timeout = null)
*
* @return mixed
*/
public function getReturnType(int $timeout = null)
public function getReturnType(?int $timeout = null)
{
if (!$this->response) {
$this->waitForResponse($timeout);
Expand Down
2 changes: 1 addition & 1 deletion src/PageUtils/PageNavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function __construct(Page $page, string $url, bool $strict = false)
*
* @return mixed
*/
public function waitForNavigation($eventName = Page::LOAD, int $timeout = null)
public function waitForNavigation($eventName = Page::LOAD, ?int $timeout = null)
{
if (null === $timeout) {
$timeout = 30000;
Expand Down
4 changes: 2 additions & 2 deletions src/PageUtils/ResponseWaiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(ResponseReader $responseReader)
*
* @return $this
*/
public function await(int $time = null)
public function await(?int $time = null)
{
$this->response = $this->responseReader->waitForResponse($time);

Expand All @@ -68,7 +68,7 @@ public function await(int $time = null)
*
* @return Response
*/
protected function awaitResponse(int $time = null): Response
protected function awaitResponse(?int $time = null): Response
{
if (!$this->response) {
$this->await($time);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Utils
*
* @return mixed
*/
public static function tryWithTimeout(int $timeoutMicroSec, \Generator $generator, callable $onTimeout = null)
public static function tryWithTimeout(int $timeoutMicroSec, \Generator $generator, ?callable $onTimeout = null)
{
$waitUntilMicroSec = \hrtime(true) / 1000 + $timeoutMicroSec;

Expand Down

0 comments on commit 5849ef8

Please sign in to comment.