Skip to content

Commit

Permalink
xdebug and phpunit upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
k-samuel committed Nov 21, 2024
1 parent 6b53cef commit 01fe626
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 36 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
}
},
"require-dev": {
"phpunit/phpunit": "^9",
"phpstan/phpstan": "^1",
"phpunit/phpunit": "^11",
"phpstan/phpstan": "^2",
"codacy/coverage": "dev-master",
"phpbench/phpbench": "^1.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/ExcludeFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface ExcludeFilterInterface extends FilterInterface
/**
* Add records into exclude list
* @param array<int|string,array<int>|\SplFixedArray<int>> $facetedData
* @param array<int,bool|int> & $excludeRecords - RecordId passed into keys of an array (performance issue)
* @param array<int,bool|int> &$excludeRecords - RecordId passed into keys of an array (performance issue)
* @return void
*/
public function addExcluded(array $facetedData, array &$excludeRecords): void;
Expand Down
5 changes: 4 additions & 1 deletion src/Filter/ExcludeRangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class ExcludeRangeFilter extends RangeFilter implements ExcludeFilterInterface
{
/**
* @inheritDoc
* @inheritdoc
*/
public function addExcluded(array $facetedData, array &$excludeRecords): void
{
Expand All @@ -61,6 +61,9 @@ public function addExcluded(array $facetedData, array &$excludeRecords): void
continue;
}
foreach ($records as $item) {
/**
* @var int $item
*/
$excludeRecords[$item] = true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/ExcludeValueFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function addExcluded(array $facetedData, array &$excludeRecords): void
}

foreach ($facetedData[$item] as $recId) {
/**
* @var int $recId
*/
$excludeRecords[$recId] = true;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Filter/RangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public function filterInput(array $facetedData, array &$inputIdKeys, array $exc

if (empty($inputIdKeys)) {
foreach ($limit as $v) {
/**
* @var int $v
*/
$inputIdKeys[$v] = true;
}
return;
Expand All @@ -113,6 +116,9 @@ public function filterInput(array $facetedData, array &$inputIdKeys, array $exc
// Reuse of input data. Set mark "2" for the data that needs to be in result.
foreach ($limit as $index) {
if (isset($inputIdKeys[$index])) {
/**
* @var int $index
*/
$inputIdKeys[$index] = 2;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/ValueFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class ValueFilter extends AbstractFilter
{
/**
* @var array<int,mixed>
* @var array<int|mixed,mixed>
*/
protected $value;

Expand Down
3 changes: 0 additions & 3 deletions src/Index/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ final class Factory

public function create(string $storage): IndexInterface
{
/**
* @var StorageInterface $store
*/
$store = new $storage;

if (!$store instanceof StorageInterface) {
Expand Down
20 changes: 13 additions & 7 deletions src/Index/Storage/ArrayStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ class ArrayStorage implements StorageInterface
{
/**
* Index data
* @var array<int|string,array<int|string,array<int>>>
* @var array<int|string,array<int|string,array<int,int>>>
*/
protected array $data = [];
/**
* @var array<int|string,IndexerInterface>
* @var array<int|string, IndexerInterface>
*/
protected array $indexers = [];

/**
* Add record to index
* @param int $recordId
* @param array<int|string,array<int,mixed>> $recordValues - ['fieldName'=>'fieldValue','fieldName2'=>['val1','val2']]
* @param array<int|string,mixed|array<int,mixed>> $recordValues - ['fieldName'=>'fieldValue','fieldName2'=>['val1','val2']]
* @return bool
*/
public function addRecord(int $recordId, array $recordValues): bool
Expand All @@ -68,6 +68,10 @@ public function addRecord(int $recordId, array $recordValues): bool
if (!isset($this->data[$fieldName])) {
$this->data[$fieldName] = [];
}

/**
* @phpstan-ignore-next-line
*/
if (!$this->indexers[$fieldName]->add($this->data[$fieldName], $recordId, $values)) {
return false;
}
Expand All @@ -88,20 +92,21 @@ public function addRecord(int $recordId, array $recordValues): bool

/**
* Get facet data.
* @return array<int|string,array<int|string,array<int>|\SplFixedArray<int>>>
* @return array<int|string,array<int|string,array<int,int>|\SplFixedArray<int>>>
*/
public function getData(): array
{
return $this->data;
}

/**
* Get facet data.
* @return array<int|string,array<int|string,array<int>>>
* Get facet data.
* @return array<int|string,array<int|string,array<int,int>>>
*/
public function export(): array
{
foreach ($this->indexers as $fieldName => $item) {
// @phpstan-ignore-next-line
$item->optimize($this->data[$fieldName]);
}

Expand All @@ -110,7 +115,7 @@ public function export(): array

/**
* Set index data. Can be used for restoring from DB
* @param array<int|string,array<int|string,array<int>>> $data
* @param array<int|string,array<int|string,array<int,int>>> $data
*/
public function setData(array $data): void
{
Expand Down Expand Up @@ -190,6 +195,7 @@ protected function getValuesCount(): array
public function optimize(): void
{
foreach ($this->indexers as $fieldName => $item) {
// @phpstan-ignore-next-line
$item->optimize($this->data[$fieldName]);
}

Expand Down
9 changes: 5 additions & 4 deletions src/Index/Storage/FixedArrayStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FixedArrayStorage extends ArrayStorage

/**
* Get index data. Can be used for storing it to DB
* @return array<int|string,array<int|string,array<int>>>
* @return array<int|string,array<int|string,array<int,int>>>
*/
public function export(): array
{
Expand All @@ -54,10 +54,11 @@ public function export(): array
}

foreach ($this->indexers as $fieldName => $item) {
// @phpstan-ignore-next-line
$item->optimize($this->data[$fieldName]);
}
/**
* @var array<int|string,array<int|string,array<int>>>
* @var array<int|string,array<int|string,array<int,int>>>
*/
return $this->data;
}
Expand All @@ -69,7 +70,7 @@ public function writeMode(): void
{
foreach ($this->data as &$value) {
/**
* @var \SplFixedArray<int> $recordList
* @var array<int,int>|\SplFixedArray<int> $recordList
*/
foreach ($value as &$recordList) {
if ($recordList instanceof \SplFixedArray) {
Expand All @@ -89,7 +90,7 @@ public function convert(): void
{
foreach ($this->data as &$value) {
/**
* @var array<int>|\SplFixedArray<int> $recordList
* @var array<int,int>|\SplFixedArray<int> $recordList
*/
foreach ($value as &$recordList) {
if (is_array($recordList)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Index/Storage/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function findRecordsMap(StorageInterface $storage, array $filters, array
return [];
}
}

// @phpstan-ignore return.type
return $inputRecords;
}

Expand All @@ -87,6 +87,7 @@ public function findExcludeRecordsMap(StorageInterface $storage, array $filters,
foreach ($filters as $filter) {
$fieldName = $filter->getFieldName();
if (isset($data[$fieldName])) {
// @phpstan-ignore-next-line
$filter->addExcluded($data[$fieldName], $excludeRecords);
}
}
Expand Down Expand Up @@ -139,6 +140,9 @@ private function findInput(StorageInterface $storage, array $inputRecords, array
*/
public function getAllRecordIdMap(StorageInterface $storage): array
{
/**
* @var array<int,bool> $result
*/
$result = [];
/**
* @var array<int|string,array<int>>$values
Expand All @@ -150,10 +154,6 @@ public function getAllRecordIdMap(StorageInterface $storage): array
}
}
}
/**
* @var array<int,bool> $result
*/

return $result;
}
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Indexer/IndexerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function add(array &$indexContainer, int $recordId, array $values): bool;

/**
* Optimize data structures
* @param array<int|string,array<int|string,array<int>>> &$indexContainer
* @param array<int|string,array<int|string,array<int,int>>> &$indexContainer
* @return void
*/
public function optimize(array &$indexContainer): void;
Expand Down
14 changes: 7 additions & 7 deletions src/Indexer/Number/RangeIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@

class RangeIndexer implements IndexerInterface
{
/**
* @var int
*/

protected int $step;

protected bool $hasUnsorted = false;
/**
* New values for sorting
* @var array<int|string,array<int|string,array<int>>>
* @var array<int|string,array<int|string,array<int,int>>>
*/
protected array $unsortedBuf = [];

Expand All @@ -55,7 +53,7 @@ public function __construct(int $step)
}

/**
* @param array<int|string,array<int>> $indexContainer
* @param array<int|string,array<int,int>> $indexContainer
* @param int $recordId
* @param array<int,int|float> $values
* @return bool
Expand All @@ -78,7 +76,7 @@ public function add(&$indexContainer, int $recordId, array $values): bool
/**
* Prepare values for export
*
* @param array<int|string,array<int|string,array<int>>> &$indexContainer
* @param array<int|string,array<int|string,array<int,int>>> &$indexContainer
* @return void
*/
public function optimize(array &$indexContainer): void
Expand All @@ -89,10 +87,12 @@ public function optimize(array &$indexContainer): void

foreach ($this->unsortedBuf as $position => &$values) {
ksort($values);
foreach ($values as $value => $ids) {
foreach ($values as $ids) {
foreach ($ids as $id) {
// @phpstan-ignore-next-line
$this->addSorterId($indexContainer[$position], $id);
}
// @phpstan-ignore parameterByRef.type
$indexContainer[$position] = array_values($indexContainer[$position]);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Indexer/Number/RangeListIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function detectRangeKey($value): int
/**
* Prepare values for export
*
* @param array<int|string,array<int|string,array<int>>> &$indexContainer
* @param array<int|string,array<int|string,array<int,int>>> &$indexContainer
* @return void
*/
public function optimize(array &$indexContainer): void
Expand All @@ -107,10 +107,12 @@ public function optimize(array &$indexContainer): void

foreach ($this->unsortedBuf as $position => &$values) {
ksort($values);
foreach ($values as $value => $ids) {
foreach ($values as $ids) {
foreach ($ids as $id) {
// @phpstan-ignore-next-line
$this->addSorterId($indexContainer[$position], $id);
}
// @phpstan-ignore-next-line
$indexContainer[$position] = array_values($indexContainer[$position]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Index/Storage/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class StorageTest extends TestCase
{
public function storeProvider(): array
static public function storeProvider(): array
{
return [
[(new Factory)->create(Factory::ARRAY_STORAGE)],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testAggregate(): void
);
}

public function storeProvider(): array
static public function storeProvider(): array
{
return [
[(new Factory)->create(Factory::ARRAY_STORAGE)],
Expand Down

0 comments on commit 01fe626

Please sign in to comment.