Skip to content

Commit

Permalink
phpstan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PeeHaa committed Jun 25, 2019
1 parent 954e494 commit 3f11a7c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
21 changes: 21 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ parameters:
paths:
- %currentWorkingDirectory%/src/Validator/Json/Schema/LogInRequest.php*
- %currentWorkingDirectory%/src/Validator/Json/Schema/RegisterRequest.php*
- %currentWorkingDirectory%/src/Validator/Json/Schema/GetArticlesRequest.php*
- %currentWorkingDirectory%/src/Validator/Json/Schema/GetCategoriesRequest.php*
- %currentWorkingDirectory%/src/Validator/Json/Schema/SubscribeToAllRequest.php*
-
message: '~Parameter #2 \$error of class PeeHaa\\FeedMe\\Request\\Error constructor expects HarmonyIO\\Validation\\Result\\Error, HarmonyIO\\Validation\\Result\\Error\|null given\.~'
paths:
Expand Down Expand Up @@ -35,3 +38,21 @@ parameters:
message: '~Call to an undefined method PeeHaa\\FeedMe\\Request\\Request::getPassword\(\)\.~'
paths:
- %currentWorkingDirectory%/src/Controller/Register.php*
-
message: '~Call to an undefined method PeeHaa\\FeedMe\\Request\\Request::getUser\(\)\.~'
paths:
- %currentWorkingDirectory%/src/Controller/GetArticles.php*
- %currentWorkingDirectory%/src/Controller/GetCategories.php*
- %currentWorkingDirectory%/src/Controller/SubscribeToAll.php*
-
message: '~Cannot call method getUrl\(\) on PeeHaa\\FeedMe\\Entity\\Article\|null\.~'
paths:
- %currentWorkingDirectory%/src/Controller/ReadArticle.php*
-
message: '~Parameter #1 \$article of method PeeHaa\\FeedMe\\Http\\WebSocket::markArticleAsReadForUser\(\) expects PeeHaa\\FeedMe\\Entity\\Article, PeeHaa\\FeedMe\\Entity\\Article\|null given\.~'
paths:
- %currentWorkingDirectory%/src/Controller/ReadArticle.php*
-
message: '~Parameter #1 \$article of method PeeHaa\\FeedMe\\Storage\\Article\\Repository::markAsRead\(\) expects PeeHaa\\FeedMe\\Entity\\Article, PeeHaa\\FeedMe\\Entity\\Article\|null given\.~'
paths:
- %currentWorkingDirectory%/src/Controller/ReadArticle.php*
8 changes: 4 additions & 4 deletions src/Controller/ReadArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function handleRequest(Request $request): Promise
if (!$userSession->has('userId')) {
return new Response(Status::FOUND, [
'location' => $article->getUrl(),
'content-length' => 0,
'content-length' => '0',
], new InMemoryStream());
}

Expand All @@ -72,10 +72,10 @@ public function handleRequest(Request $request): Promise
/** @var User|null $user */
$user = yield $this->userRepository->getById($userId);

if (!$user) {
if ($user === null) {
return new Response(Status::FOUND, [
'location' => $article->getUrl(),
'content-length' => 0,
'content-length' => '0',
], new InMemoryStream());
}

Expand All @@ -84,7 +84,7 @@ public function handleRequest(Request $request): Promise

return new Response(Status::FOUND, [
'location' => $article->getUrl(),
'content-length' => 0,
'content-length' => '0',
], new InMemoryStream());
});
}
Expand Down
10 changes: 9 additions & 1 deletion src/Http/WebSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,15 @@ public function onOpen(int $clientId, Request $request): void
public function onData(int $clientId, Message $message): Promise
{
return call(function () use ($clientId, $message) {
if ($this->clients->getById($clientId) === null) {
return;
}

/** @var SocketResponse $response */
$response = yield $this->frontController->handleRequest(
yield $message->read(),
$this->clients->getById($clientId),
$this->clients->getById($clientId) ? $this->clients->getById($clientId)->getUser() : null,
$this->clients->getById($clientId)->getUser(),
);

if ($response instanceof LogInValid || $response instanceof RegisterValid) {
Expand All @@ -140,6 +144,10 @@ public function onData(int $clientId, Message $message): Promise
// phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
public function onClose(int $clientId, int $code, string $reason): void
{
if ($this->clients->getById($clientId) === null) {
return;
}

$this->subscriptions->removeByClient($this->clients->getById($clientId));

$this->clients->removeById($clientId);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/WebSocket/Clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getClientIdsByUserId(string $userId): array
$clientIds = [];

foreach ($this->clients as $client) {
if (!$client->getUser() || $client->getUser()->getId() !== $userId) {
if ($client->getUser() === null || $client->getUser()->getId() !== $userId) {
continue;
}

Expand Down

0 comments on commit 3f11a7c

Please sign in to comment.