From 9c20a931c94b1172a57ecbab6d5503fd9efa655c Mon Sep 17 00:00:00 2001 From: Seriyyy95 Date: Thu, 25 Apr 2024 21:12:49 +0300 Subject: [PATCH] fix: code style --- .gitignore | 1 - composer.json | 2 -- src/Communication/Connection.php | 6 ++++++ src/Communication/Socket/MockSocket.php | 7 ------- src/Communication/Socket/SocketInterface.php | 2 -- src/Communication/Socket/WaitForDataInterface.php | 8 ++++++++ src/Communication/Socket/Wrench.php | 2 +- .../CommunicationException/CantSyncEventsException.php | 10 ++++++++++ 8 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 src/Communication/Socket/WaitForDataInterface.php create mode 100644 src/Exception/CommunicationException/CantSyncEventsException.php diff --git a/.gitignore b/.gitignore index 8be5d942..f207df2e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ composer.lock phpstan.neon phpunit.xml vendor -.idea diff --git a/composer.json b/composer.json index 587c81bd..206d0a40 100644 --- a/composer.json +++ b/composer.json @@ -46,8 +46,6 @@ }, "preferred-install": "dist" }, - "minimum-stability": "dev", - "prefer-stable": true, "extra": { "bamarni-bin": { "bin-links": true, diff --git a/src/Communication/Connection.php b/src/Communication/Connection.php index c60467f4..14b1be08 100644 --- a/src/Communication/Connection.php +++ b/src/Communication/Connection.php @@ -12,9 +12,11 @@ namespace HeadlessChromium\Communication; use Evenement\EventEmitter; +use HeadlessChromium\Communication\Socket\WaitForDataInterface; use HeadlessChromium\Communication\Socket\SocketInterface; use HeadlessChromium\Communication\Socket\Wrench; use HeadlessChromium\Exception\CommunicationException; +use HeadlessChromium\Exception\CommunicationException\CantSyncEventsException; use HeadlessChromium\Exception\CommunicationException\CannotReadResponse; use HeadlessChromium\Exception\CommunicationException\InvalidResponse; use HeadlessChromium\Exception\OperationTimedOut; @@ -348,6 +350,10 @@ public function readLine() public function processAllEvents(): void { + if($this->wsClient instanceof WaitForDataInterface === false){ + throw new CantSyncEventsException(); + } + $hasData = $this->wsClient->waitForData(0); if ($hasData) { diff --git a/src/Communication/Socket/MockSocket.php b/src/Communication/Socket/MockSocket.php index 0c9da21b..66a450b5 100644 --- a/src/Communication/Socket/MockSocket.php +++ b/src/Communication/Socket/MockSocket.php @@ -124,11 +124,4 @@ public function disconnect($reason = 1000) return true; } - - public function waitForData(float $maxSeconds): bool - { - // TODO: Implement wait if needed. - - return !empty($this->receivedData); - } } diff --git a/src/Communication/Socket/SocketInterface.php b/src/Communication/Socket/SocketInterface.php index 8900aeb2..d151617c 100644 --- a/src/Communication/Socket/SocketInterface.php +++ b/src/Communication/Socket/SocketInterface.php @@ -52,6 +52,4 @@ public function isConnected(); * @return bool */ public function disconnect($reason = 1000); - - public function waitForData(float $maxSeconds): bool; } diff --git a/src/Communication/Socket/WaitForDataInterface.php b/src/Communication/Socket/WaitForDataInterface.php new file mode 100644 index 00000000..a7793439 --- /dev/null +++ b/src/Communication/Socket/WaitForDataInterface.php @@ -0,0 +1,8 @@ +