Skip to content

Commit

Permalink
Merge pull request #595 from elifesciences/phpstan-level-4
Browse files Browse the repository at this point in the history
phpstan level 4
  • Loading branch information
scottaubrey authored Dec 20, 2024
2 parents cc76e45 + 67761de commit 8aa7ff5
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 211 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 3
level: 4
paths:
- src
- tests
Expand Down
6 changes: 0 additions & 6 deletions src/Search/Api/Elasticsearch/ElasticQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ private function postFilter($filter)
$this->query['body']['post_filter']['bool']['filter'][] = $filter;
}

private function query($key, array $body)
{
$this->query['body']['query'] = $this->query['body']['query'] ?? [];
$this->query['body']['query'][$key] = $body;
}

private function setBoostings(array $query = [])
{
/* Boost results based on 'type' */
Expand Down
16 changes: 7 additions & 9 deletions src/Search/Api/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
final class SearchController
{
private $serializer;
private $apiUrl;
private $client;
private $context;
private $elasticIndex;
Expand All @@ -38,26 +37,25 @@ public function __construct(
LoggerInterface $logger,
SerializationContext $context,
MappedElasticsearchClient $client,
string $apiUrl,
string $elasticIndex
) {
$this->serializer = $serializer;
$this->logger = $logger;
$this->context = $context;
$this->client = $client;
$this->apiUrl = $apiUrl;
$this->elasticIndex = $elasticIndex;
}

private function validateDateRange(DateTimeImmutable $startDateTime = null, DateTimeImmutable $endDateTime = null)
private function validateDateRange(DateTimeImmutable|false $startDateTime = null, DateTimeImmutable|false $endDateTime = null)
{
if (false === $endDateTime || false === $startDateTime) {
if ($endDateTime === null && $startDateTime === null) {
return;
}

if ($endDateTime === false || $startDateTime === false) {
throw new BadRequestHttpException('Invalid date provided');
}
if (
($endDateTime && $startDateTime) &&
(1 === $startDateTime->diff($endDateTime)->invert)
) {
if (($endDateTime && $startDateTime) && 1 === $startDateTime->diff($endDateTime)->invert) {
throw new BadRequestHttpException('start-date must be the same or before end-date');
}
}
Expand Down
18 changes: 0 additions & 18 deletions src/Search/Indexer/ModelIndexer/Helper/JsonSerializerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,17 @@

trait JsonSerializerHelper
{
private static $cache = [];

abstract protected function getSdkClass() : string;
abstract protected function getSerializer() : Serializer;

protected function deserialize(string $json)
{
return $this->getSerializer()->deserialize($json, $this->getSdkClass(), 'json');

//todo: the following code causes a conflict when reading from $cache
$key = sha1($json);
if (!isset(self::$cache[$key])) {
self::$cache[$key] = $this->getSerializer()->deserialize($json, $this->getSdkClass(), 'json');
}

return self::$cache[$key];
}

protected function serialize($item) : string
{
return $this->getSerializer()->serialize($item, 'json');

//todo: the following code causes a conflict when reading from $cache
$key = spl_object_hash($item);
if (!isset(self::$cache[$key])) {
self::$cache[$key] = $this->getSerializer()->serialize($item, 'json');
}

return self::$cache[$key];
}

protected function snippet($item) : array
Expand Down
16 changes: 0 additions & 16 deletions src/Search/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function __construct($config = [])
'process_memory_limit' => 256,
'aws' => array_merge([
'credential_file' => false,
'mock_queue' => true,
'queue_name' => 'search--dev',
'key' => '-----------------------',
'secret' => '-------------------------------',
Expand Down Expand Up @@ -284,7 +283,6 @@ public function dependencies(Container $container)
$container['logger'],
$container['serializer.context'],
$container['elastic.client.read'],
$container['config']['api_url'],
$this->indexMetadata()->read()
);
};
Expand Down Expand Up @@ -427,24 +425,10 @@ public function dependencies(Container $container)
};

$container['console.queue.watch'] = function (Container $container) {
$mock_queue = $container['config']['aws']['mock_queue'] ?? false;
if ($mock_queue) {
return new QueueWatchCommand(
$container['mocks.queue'],
$container['mocks.queue_transformer'],
$container['indexer'],
true,
$container['logger'],
$container['monitoring'],
$container['limit.long_running']
);
}

return new QueueWatchCommand(
$container['aws.queue'],
$container['aws.queue_transformer'],
$container['indexer'],
false,
$container['logger'],
$container['monitoring'],
$container['limit.long_running']
Expand Down
3 changes: 0 additions & 3 deletions src/Search/Queue/Command/QueueWatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@

class QueueWatchCommand extends QueueCommand
{
private $isMock;
private $indexer;

public function __construct(
WatchableQueue $queue,
QueueItemTransformer $transformer,
Indexer $indexer,
bool $isMock,
LoggerInterface $logger,
Monitoring $monitoring,
callable $limit
) {
parent::__construct($logger, $queue, $transformer, $monitoring, $limit, false);
$this->isMock = $isMock;
$this->indexer = $indexer;
}

Expand Down
140 changes: 0 additions & 140 deletions tests/src/Search/AsyncAssert.php

This file was deleted.

8 changes: 4 additions & 4 deletions tests/src/Search/Indexer/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testSkipInsert()
$this->indexer->index($entity);

// added to remove risky flag from this test, as all the assertions are done at `tearDown()`
$this->assertTrue(true);
$this->expectNotToPerformAssertions();
}

#[Test]
Expand Down Expand Up @@ -102,7 +102,7 @@ public function testIndexSuccess()
$this->indexer->index($entity);

// added to remove risky flag from this test, as all the assertions are done at `tearDown()`
$this->assertTrue(true);
$this->expectNotToPerformAssertions();
}


Expand Down Expand Up @@ -137,7 +137,7 @@ public function testPostValidateFailure()
$this->indexer->index($entity);

// added to remove risky flag from this test, as all the assertions are done at `tearDown()`
$this->assertTrue(true);
$this->expectNotToPerformAssertions();
}

#[Test]
Expand Down Expand Up @@ -171,6 +171,6 @@ public function testIndexAndDeleteSuccess()
$this->indexer->index($entity);

// added to remove risky flag from this test, as all the assertions are done at `tearDown()`
$this->assertTrue(true);
$this->expectNotToPerformAssertions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ final class ResearchArticleIndexerTest extends TestCase
use CallSerializer;
use ModelProvider;

private MockInterface|MappedElasticsearchClient $elastic;

private ResearchArticleIndexer $indexer;

protected function setUp(): void
{
$this->elastic = Mockery::mock(MappedElasticsearchClient::class);
$this->indexer = new ResearchArticleIndexer($this->getSerializer(), []);
}

Expand Down
5 changes: 1 addition & 4 deletions tests/src/Search/RamlRequirement.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public static function getFixture(string $name) : string
$file = ComposerLocator::getPath('elife/api').'/dist/samples/'.$name;
if (file_exists($file)) {
return file_get_contents($file);
} else {
throw new LogicException("Fixture {$name} does not exist");
}

return null;
throw new LogicException("Fixture {$name} does not exist");
}
}
4 changes: 2 additions & 2 deletions tests/src/Search/Web/BoostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function testBoostByType()
$response = $this->getJsonResponse();

$this->markTestIncomplete('This needs more investigation to eliminate factors other that type affecting relevance scores.');
$this->assertEquals($response->items[0]->id, '15278');
$this->assertEquals($response->items[1]->id, '15276');
// $this->assertEquals($response->items[0]->id, '15278');
// $this->assertEquals($response->items[1]->id, '15276');
}

public function testBoostByField()
Expand Down
Loading

0 comments on commit 8aa7ff5

Please sign in to comment.