Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

III-3558 Increase PHPStan to level 8 #310

Merged
merged 9 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/Console/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace CultuurNet\UDB3\SearchService\Console;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;

abstract class AbstractCommand extends Command
LucWollants marked this conversation as resolved.
Show resolved Hide resolved
{
public function getApplication(): Application
{
$application = parent::getApplication();

if ($application === null) {
throw new \RuntimeException('The command is not attached to an application.');
}

return $application;
}
}
6 changes: 1 addition & 5 deletions app/Console/AbstractElasticSearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
namespace CultuurNet\UDB3\SearchService\Console;

use Elasticsearch\Client;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

abstract class AbstractElasticSearchCommand extends Command
abstract class AbstractElasticSearchCommand extends AbstractCommand
{
private Client $client;

Expand All @@ -19,14 +18,11 @@ public function __construct(Client $client)
$this->client = $client;
}



protected function getElasticSearchClient(): Client
{
return $this->client;
}


protected function getLogger(OutputInterface $output): ConsoleLogger
{
$output = clone $output;
Expand Down
3 changes: 1 addition & 2 deletions app/Console/MigrateElasticSearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace CultuurNet\UDB3\SearchService\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

final class MigrateElasticSearchCommand extends Command
final class MigrateElasticSearchCommand extends AbstractCommand
{
/**
* @inheritdoc
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 7
level: 8
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
Expand Down
2 changes: 1 addition & 1 deletion src/AMQP/EventBusForwardingConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
use Broadway\EventHandling\EventBus;
use CultuurNet\UDB3\Search\Deserializer\DeserializerLocatorInterface;
use CultuurNet\UDB3\Search\Deserializer\DeserializerNotFoundException;
use CultuurNet\UDB3\Search\LoggerAwareTrait;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use Ramsey\Uuid\Uuid;
use Throwable;
Expand Down
3 changes: 1 addition & 2 deletions src/ElasticSearch/ElasticSearchPagedResultSetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ final class ElasticSearchPagedResultSetFactory implements ElasticSearchPagedResu
{
private AggregationTransformerInterface $aggregationTransformer;

private ?ElasticSearchResponseValidatorInterface $responseValidator;

private ElasticSearchResponseValidatorInterface $responseValidator;

public function __construct(
AggregationTransformerInterface $aggregationTransformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function withDateRangeFilter(
return $this->withDateRangeQuery('dateRange', $from, $to);
}

public function withLocalTimeRangeFilter(int $localTimeFrom = null, int $localTimeTo = null): self
public function withLocalTimeRangeFilter(int $localTimeFrom, int $localTimeTo): self
{
$this->guardNaturalIntegerRange('localTime', new Time($localTimeFrom), new Time($localTimeTo));
return $this->withRangeQuery('localTimeRange', $localTimeFrom, $localTimeTo);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Authentication/Auth0/Auth0TokenGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use CultuurNet\UDB3\Search\Http\Authentication\Token\Token;
use CultuurNet\UDB3\Search\Http\Authentication\Token\TokenGenerator;
use CultuurNet\UDB3\Search\Json;
use CultuurNet\UDB3\Search\LoggerAwareTrait;
use DateTimeImmutable;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Psr7\Request;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;

final class Auth0TokenGenerator implements TokenGenerator, LoggerAwareInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Authentication/AuthenticateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use CultuurNet\UDB3\Search\Http\Authentication\ApiProblems\RemovedApiKey;
use CultuurNet\UDB3\Search\Http\Authentication\Token\ManagementTokenProvider;
use CultuurNet\UDB3\Search\Http\DefaultQuery\DefaultQueryRepository;
use CultuurNet\UDB3\Search\LoggerAwareTrait;
use Exception;
use GuzzleHttp\Exception\ConnectException;
use ICultureFeed;
Expand All @@ -25,7 +26,6 @@
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;

final class AuthenticateRequest implements MiddlewareInterface, LoggerAwareInterface
Expand Down
8 changes: 5 additions & 3 deletions src/Http/OrganizerSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ public function __construct(

public function __invoke(ApiRequestInterface $request): ResponseInterface
{
$this->organizerParameterWhiteList->guardAgainstUnsupportedParameters(
$request->getQueryParamsKeys()
);
$keys = $request->getQueryParamsKeys();

if ($keys !== null) {
$this->organizerParameterWhiteList->guardAgainstUnsupportedParameters($keys);
}

$start = new Start((int) $request->getQueryParam('start', 0));
$limit = new Limit((int) $request->getQueryParam('limit', 30));
Expand Down
4 changes: 2 additions & 2 deletions src/JsonDocument/TransformingJsonDocumentIndexService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace CultuurNet\UDB3\Search\JsonDocument;

use Exception;
use CultuurNet\UDB3\Search\LoggerAwareTrait;
use CultuurNet\UDB3\Search\ReadModel\DocumentRepository;
use Exception;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;

final class TransformingJsonDocumentIndexService implements
Expand Down
17 changes: 17 additions & 0 deletions src/LoggerAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace CultuurNet\UDB3\Search;

use Psr\Log\LoggerInterface;

trait LoggerAwareTrait
{
private LoggerInterface $logger;

public function setLogger(LoggerInterface $logger): void
{
$this->logger = $logger;
}
}
4 changes: 2 additions & 2 deletions src/Offer/OfferQueryBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function withDateRangeFilter(
): OfferQueryBuilderInterface;

public function withLocalTimeRangeFilter(
int $localTimeFrom = null,
int $localTimeTo = null
int $localTimeFrom,
int $localTimeTo
): OfferQueryBuilderInterface;

public function withStatusFilter(Status ...$statuses): OfferQueryBuilderInterface;
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/MockOfferQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function withDateRangeFilter(DateTimeImmutable $from = null, DateTimeImmu
return $c;
}

public function withLocalTimeRangeFilter(int $localTimeFrom = null, int $localTimeTo = null): self
public function withLocalTimeRangeFilter(int $localTimeFrom, int $localTimeTo): self
{
$c = clone $this;
$c->mockQuery['localTimeRange']['from'] = $localTimeFrom;
Expand Down
4 changes: 3 additions & 1 deletion tests/Http/Parameters/ArrayParameterBagAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,10 @@ private function assertArrayContentsAreEqual(array $expected, array $actual): vo
}


private function assertDateTimeEquals(DateTimeImmutable $expected, DateTimeImmutable $actual): void
private function assertDateTimeEquals(DateTimeImmutable $expected, ?DateTimeImmutable $actual): void
{
$this->assertNotNull($actual);

$this->assertEquals(
$expected->format(DateTime::ATOM),
$actual->format(DateTime::ATOM)
Expand Down
Loading