Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Nov 15, 2023
1 parent bdcbd3f commit 599d1f7
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 79 deletions.
70 changes: 0 additions & 70 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$value of function ini_set expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
path: src/IniOptionsHandler.php

-
message: "#^Access to an undefined property React\\\\Socket\\\\ConnectionInterface\\:\\:\\$stream\\.$#"
count: 1
Expand All @@ -15,11 +10,6 @@ parameters:
count: 1
path: src/ReactPhpServer.php

-
message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\<0, max\\>\\|false given\\.$#"
count: 1
path: src/Session/Middleware/InitializeSession.php

-
message: "#^Method BabDev\\\\WebSocket\\\\Server\\\\Session\\\\Reader\\\\PhpSerializeReader\\:\\:read\\(\\) should return array but returns mixed\\.$#"
count: 1
Expand Down Expand Up @@ -80,67 +70,7 @@ parameters:
count: 1
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php

-
message: "#^Parameter \\#2 \\$haystack of function in_array expects array, mixed given\\.$#"
count: 2
path: tests/Http/Middleware/RejectBlockedIpAddressTest.php

-
message: "#^Parameter \\#2 \\$haystack of function in_array expects array, mixed given\\.$#"
count: 2
path: tests/Http/Middleware/RestrictToAllowedOriginsTest.php

-
message: "#^Parameter \\#1 \\$haystack of function str_contains expects string, string\\|null given\\.$#"
count: 1
path: tests/ReactPhpServerTest.php

-
message: "#^Parameter \\#1 \\$socket of function socket_close expects Socket, Socket\\|false given\\.$#"
count: 3
path: tests/ReactPhpServerTest.php

-
message: "#^Parameter \\#1 \\$socket of function socket_connect expects Socket, Socket\\|false given\\.$#"
count: 3
path: tests/ReactPhpServerTest.php

-
message: "#^Parameter \\#1 \\$socket of function socket_set_block expects Socket, Socket\\|false given\\.$#"
count: 3
path: tests/ReactPhpServerTest.php

-
message: "#^Parameter \\#1 \\$socket of function socket_set_option expects Socket, Socket\\|false given\\.$#"
count: 6
path: tests/ReactPhpServerTest.php

-
message: "#^Parameter \\#1 \\$socket of function socket_shutdown expects Socket, Socket\\|false given\\.$#"
count: 6
path: tests/ReactPhpServerTest.php

-
message: "#^Parameter \\#1 \\$socket of function socket_write expects Socket, Socket\\|false given\\.$#"
count: 2
path: tests/ReactPhpServerTest.php

-
message: "#^Property BabDev\\\\WebSocket\\\\Server\\\\Tests\\\\ReactPhpServerTest\\:\\:\\$port \\(int\\) does not accept int\\<0, 65535\\>\\|false\\|null\\.$#"
count: 1
path: tests/ReactPhpServerTest.php

-
message: "#^Property BabDev\\\\WebSocket\\\\Server\\\\Tests\\\\ReactPhpServerTest\\:\\:\\$server is never read, only written\\.$#"
count: 1
path: tests/ReactPhpServerTest.php

-
message: "#^Class UnknownClass not found\\.$#"
count: 1
path: tests/WAMP/MessageHandler/DefaultMessageHandlerResolverTest.php

-
message: "#^Class UnknownClass not found\\.$#"
count: 1
path: tests/WAMP/MessageHandler/PsrContainerMessageHandlerResolverTest.php
6 changes: 6 additions & 0 deletions src/IniOptionsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

final class IniOptionsHandler implements OptionsHandler
{
/**
* @phpstan-return string|false
*/
public function get(string $option): mixed
{
return \ini_get($option);
}

/**
* @phpstan-param string|int|float|bool|null $value
*/
public function set(string $option, mixed $value): void
{
ini_set($option, $value);
Expand Down
1 change: 1 addition & 0 deletions src/Session/Middleware/InitializeSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private function parseCookieHeader(string $cookieHeader): array
throw new \RuntimeException('Invalid Cookie header.');
}

/** @var int $separatorPosition */
$separatorPosition = strpos($cookie, '=');

$key = ltrim(substr($cookie, 0, $separatorPosition));
Expand Down
13 changes: 10 additions & 3 deletions tests/Http/Middleware/RejectBlockedIpAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,18 @@ public function testManagesBlockedAddressList(): void
$this->middleware->blockAddress('192.168.1.1');
$this->middleware->blockAddress('192.168.0.0/24');

$this->assertTrue(\in_array('192.168.1.1', $blockedAddresses->getValue($this->middleware), true));
$this->assertTrue(\in_array('192.168.0.0/24', $blockedAddresses->getValue($this->middleware), true));
/** @var list<non-empty-string> $addresses */
$addresses = $blockedAddresses->getValue($this->middleware);

$this->assertContains('192.168.1.1', $addresses);
$this->assertContains('192.168.0.0/24', $addresses);

$this->middleware->allowAddress('192.168.1.1');

$this->assertFalse(\in_array('192.168.1.1', $blockedAddresses->getValue($this->middleware), true));
/** @var list<non-empty-string> $addresses */
$addresses = $blockedAddresses->getValue($this->middleware);

$this->assertNotContains('192.168.1.1', $addresses);
$this->assertContains('192.168.0.0/24', $addresses);
}
}
13 changes: 10 additions & 3 deletions tests/Http/Middleware/RestrictToAllowedOriginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,18 @@ public function testManagesAllowedOriginList(): void
$this->middleware->allowOrigin('192.168.1.1');
$this->middleware->allowOrigin('localhost');

$this->assertTrue(\in_array('192.168.1.1', $allowedOrigins->getValue($this->middleware), true));
$this->assertTrue(\in_array('localhost', $allowedOrigins->getValue($this->middleware), true));
/** @var list<non-empty-string> $origins */
$origins = $allowedOrigins->getValue($this->middleware);

$this->assertContains('192.168.1.1', $origins);
$this->assertContains('localhost', $origins);

$this->middleware->removeAllowedOrigin('192.168.1.1');

$this->assertFalse(\in_array('192.168.1.1', $allowedOrigins->getValue($this->middleware), true));
/** @var list<non-empty-string> $origins */
$origins = $allowedOrigins->getValue($this->middleware);

$this->assertNotContains('192.168.1.1', $origins);
$this->assertContains('localhost', $origins);
}
}
27 changes: 26 additions & 1 deletion tests/ReactPhpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ protected function setUp(): void

$uri = $this->socket->getAddress();

$this->port = parse_url((str_contains($uri, '://') ? '' : 'tcp://').$uri, \PHP_URL_PORT);
if (!\is_string($uri)) {
self::fail('Could not get socket server address');
}

$port = parse_url((str_contains($uri, '://') ? '' : 'tcp://').$uri, \PHP_URL_PORT);

if (!\is_int($port)) {
self::fail('Could not extract port from socket server address');
}

$this->port = $port;

$this->server = new ReactPhpServer($this->middleware, $this->socket, Loop::get());
}
Expand Down Expand Up @@ -77,6 +87,11 @@ public function testOnData(): void
->with($this->isInstanceOf(Connection::class), $message);

$client = socket_create(\AF_INET, \SOCK_STREAM, \SOL_TCP);

if (false === $client) {
self::fail(sprintf('Could not create the socket for testing: %s', socket_strerror(socket_last_error())));
}

socket_set_option($client, \SOL_SOCKET, \SO_REUSEADDR, 1);
socket_set_option($client, \SOL_SOCKET, \SO_SNDBUF, 4096);
socket_set_block($client);
Expand All @@ -103,6 +118,11 @@ public function testOnEnd(): void
->with($this->isInstanceOf(Connection::class));

$client = socket_create(\AF_INET, \SOCK_STREAM, \SOL_TCP);

if (false === $client) {
self::fail(sprintf('Could not create the socket for testing: %s', socket_strerror(socket_last_error())));
}

socket_set_option($client, \SOL_SOCKET, \SO_REUSEADDR, 1);
socket_set_option($client, \SOL_SOCKET, \SO_SNDBUF, 4096);
socket_set_block($client);
Expand Down Expand Up @@ -134,6 +154,11 @@ public function testOnError(): void
->with($this->isInstanceOf(Connection::class), $exception);

$client = socket_create(\AF_INET, \SOCK_STREAM, \SOL_TCP);

if (false === $client) {
self::fail(sprintf('Could not create the socket for testing: %s', socket_strerror(socket_last_error())));
}

socket_set_option($client, \SOL_SOCKET, \SO_REUSEADDR, 1);
socket_set_option($client, \SOL_SOCKET, \SO_SNDBUF, 4096);
socket_set_block($client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testCannotResolveAMessageHandlerWhenTheControllerRequestAttribut
$this->expectException(UnknownMessageHandler::class);

$attributes = new ParameterBag();
$attributes->set('_controller', \UnknownClass::class);
$attributes->set('_controller', \UnknownClass::class); // @phpstan-ignore-line

(new DefaultMessageHandlerResolver())->findMessageHandler(new WAMPMessageRequest($attributes));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testCannotResolveAMessageHandlerWhenTheControllerRequestAttribut
$this->expectException(UnknownMessageHandler::class);

$attributes = new ParameterBag();
$attributes->set('_controller', \UnknownClass::class);
$attributes->set('_controller', \UnknownClass::class); // @phpstan-ignore-line

(new PsrContainerMessageHandlerResolver(new Container()))->findMessageHandler(new WAMPMessageRequest($attributes));
}
Expand Down

0 comments on commit 599d1f7

Please sign in to comment.