Skip to content
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
29 changes: 17 additions & 12 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

dependencies:
- "highest"
Expand Down Expand Up @@ -57,10 +60,10 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

dependencies:
- "highest"
Expand Down Expand Up @@ -96,10 +99,10 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

dependencies:
- "highest"
Expand Down Expand Up @@ -131,10 +134,10 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

dependencies:
- "lowest"
Expand Down Expand Up @@ -167,8 +170,10 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

dependencies:
- "highest"
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.2",
"doctrine/collections": "^1.6 || ^2.0",
"doctrine/orm": "^2.8 || ^3.0",
"doctrine/persistence": "^1.3 || ^2.1 || ^3.0",
"symfony/property-access": "^5.4 || ^6.0",
"symfony/property-access": "^5.4 || ^6.4 || ^7.4 || ^8.0",
"webmozart/assert": "^1.10"
},
"require-dev": {
Expand All @@ -23,7 +23,8 @@
"phpunit/phpunit": "^9.5.10",
"psalm/plugin-phpunit": "^0.19.0",
"setono/code-quality-pack": "^2.1.3",
"symfony/cache": "^5.4 || ^6.0",
"symfony/cache": "^5.4 || ^6.4 || ^7.4 || ^8.0",
"symfony/var-exporter": "^5.4 || ^6.4 || ^7.4",
"weirdan/doctrine-psalm-plugin": "^2.0"
},
"autoload": {
Expand Down
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
</plugins>
<issueHandlers>
<PossiblyUnusedMethod>
<errorLevel type="suppress">
<file name="src/Exception/LowerBoundIsGreaterThanUpperBoundException.php"/>
<file name="src/Exception/NoManagerException.php"/>
<file name="src/Factory/BatcherFactoryInterface.php"/>
<file name="src/Query/QueryRebuilderInterface.php"/>
<file name="tests/Entity/Entity.php"/>
</errorLevel>
</PossiblyUnusedMethod>
<UnusedClass>
<errorLevel type="suppress">
<file name="src/Query/QueryRebuilder.php"/>
</errorLevel>
</UnusedClass>
</issueHandlers>
</psalm>
3 changes: 3 additions & 0 deletions src/Batch/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ public function __construct(QueryBuilder $qb)
$this->parameters = $qb->getParameters()->toArray();
}

#[\Override]
public function getClass(): string
{
return $this->class;
}

#[\Override]
public function getDql(): string
{
return $this->dql;
}

#[\Override]
public function getParameters(): array
{
return $this->parameters;
Expand Down
1 change: 1 addition & 0 deletions src/Batch/CollectionBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(array $collection, QueryBuilder $qb)
parent::__construct($qb);
}

#[\Override]
public function getCollection(): array
{
return $this->collection;
Expand Down
2 changes: 2 additions & 0 deletions src/Batch/RangeBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ public function __construct(int $lowerBound, int $upperBound, QueryBuilder $qb)
parent::__construct($qb);
}

#[\Override]
public function getLowerBound(): int
{
return $this->lowerBound;
}

#[\Override]
public function getUpperBound(): int
{
return $this->upperBound;
Expand Down
1 change: 1 addition & 0 deletions src/Batcher/Batcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function __construct(QueryBuilder $qb, string $identifier = 'id', bool $c
;
}

#[\Override]
public function getBatchCount(int $batchSize = 100): int
{
return (int) ceil($this->getCount() / $batchSize);
Expand Down
1 change: 1 addition & 0 deletions src/Batcher/Collection/CollectionBatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

abstract class CollectionBatcher extends Batcher implements CollectionBatcherInterface
{
#[\Override]
protected function getBatchableQueryBuilder(): QueryBuilder
{
$qb = $this->getQueryBuilder();
Expand Down
1 change: 1 addition & 0 deletions src/Batcher/Collection/CollectionBatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ interface CollectionBatcherInterface extends BatcherInterface
/**
* @return iterable<CollectionBatchInterface>
*/
#[\Override]
public function getBatches(int $batchSize = 100): iterable;
}
1 change: 1 addition & 0 deletions src/Batcher/Collection/IdCollectionBatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class IdCollectionBatcher extends CollectionBatcher
/**
* @return iterable<CollectionBatchInterface>
*/
#[\Override]
public function getBatches(int $batchSize = 100): iterable
{
$result = $this->getResult(sprintf('%s.%s', $this->alias, $this->identifier), $batchSize);
Expand Down
1 change: 1 addition & 0 deletions src/Batcher/Collection/ObjectCollectionBatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class ObjectCollectionBatcher extends CollectionBatcher
/**
* @return iterable<CollectionBatchInterface>
*/
#[\Override]
public function getBatches(int $batchSize = 100): iterable
{
$result = $this->getResult(null, $batchSize);
Expand Down
1 change: 1 addition & 0 deletions src/Batcher/Range/IdRangeBatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class IdRangeBatcher extends RangeBatcher
/**
* @return iterable<RangeBatchInterface>
*/
#[\Override]
public function getBatches(int $batchSize = 100): iterable
{
$result = $this->getResult(sprintf('%s.%s', $this->alias, $this->identifier), $batchSize);
Expand Down
8 changes: 4 additions & 4 deletions src/Batcher/Range/NaiveIdRangeBatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

final class NaiveIdRangeBatcher extends RangeBatcher implements NaiveIdRangeBatcherInterface
{
private int $count;

/**
* @return iterable<RangeBatchInterface>
*/
#[\Override]
public function getBatches(int $batchSize = 100): iterable
{
try {
Expand All @@ -40,14 +39,15 @@ public function getBatches(int $batchSize = 100): iterable
* If the lowest id is 30 and the highest id is 190 the maximum number of rows is (190 - 30) + 1 = 161
* If the number of rows is 145, then the sparseness is (161 - 145) / 161 * 100 = 9.94% and this method will return 10 in that case.
*/
#[\Override]
public function getSparseness(): int
{
try {
$bestPossibleCount = ($this->getMax() - $this->getMin()) + 1;
} catch (NoResultException $e) {
} catch (NoResultException) {
return 0;
}

return (int) round(($bestPossibleCount - $this->getCount()) / $bestPossibleCount * 100);
return (int) round((float) ($bestPossibleCount - $this->getCount()) / (float) $bestPossibleCount * 100.0);
}
}
1 change: 1 addition & 0 deletions src/Batcher/Range/RangeBatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

abstract class RangeBatcher extends Batcher implements RangeBatcherInterface
{
#[\Override]
protected function getBatchableQueryBuilder(): QueryBuilder
{
$qb = $this->getQueryBuilder();
Expand Down
1 change: 1 addition & 0 deletions src/Batcher/Range/RangeBatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ interface RangeBatcherInterface extends BatcherInterface
/**
* @return iterable<RangeBatchInterface>
*/
#[\Override]
public function getBatches(int $batchSize = 100): iterable;
}
11 changes: 7 additions & 4 deletions src/Factory/BatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,38 @@ public function __construct(
string $objectCollectionBatcherClass,
string $idCollectionBatcherClass,
string $naiveIdRangeBatcherClass,
string $idRangeBatcherClass
string $idRangeBatcherClass,
) {
$this->objectCollectionBatcherClass = $objectCollectionBatcherClass;
$this->idCollectionBatcherClass = $idCollectionBatcherClass;
$this->naiveIdRangeBatcherClass = $naiveIdRangeBatcherClass;
$this->idRangeBatcherClass = $idRangeBatcherClass;
}

#[\Override]
public function createObjectCollectionBatcher(
QueryBuilder $qb,
string $identifier = 'id',
bool $clearOnBatch = true
bool $clearOnBatch = true,
): CollectionBatcherInterface {
return new $this->objectCollectionBatcherClass($qb, $identifier, $clearOnBatch);
}

#[\Override]
public function createIdCollectionBatcher(
QueryBuilder $qb,
string $identifier = 'id',
bool $clearOnBatch = true
bool $clearOnBatch = true,
): CollectionBatcherInterface {
return new $this->idCollectionBatcherClass($qb, $identifier, $clearOnBatch);
}

#[\Override]
public function createIdRangeBatcher(
QueryBuilder $qb,
string $identifier = 'id',
bool $clearOnBatch = true,
int $sparsenessThreshold = 5
int $sparsenessThreshold = 5,
): RangeBatcherInterface {
/** @var NaiveIdRangeBatcherInterface $naiveIdBatcher */
$naiveIdBatcher = new $this->naiveIdRangeBatcherClass($qb, $identifier, $clearOnBatch);
Expand Down
1 change: 1 addition & 0 deletions src/Query/QueryRebuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(ManagerRegistry $managerRegistry)
$this->managerRegistry = $managerRegistry;
}

#[\Override]
public function rebuild(BatchInterface $batch): Query
{
$manager = $this->getManager($batch->getClass());
Expand Down
2 changes: 1 addition & 1 deletion tests/Batcher/Collection/IdCollectionBatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function it_works(): void

$batches = $batcher->getBatches(10);

foreach ($batches as $idx => $batch) {
foreach ($batches as $batch) {
foreach ($batch->getCollection() as $id) {
$this->assertArrayHasKey($id, $expectedIds);

Expand Down
2 changes: 1 addition & 1 deletion tests/Batcher/Collection/ObjectCollectionBatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function it_works(): void

$batches = $batcher->getBatches(10);

foreach ($batches as $idx => $batch) {
foreach ($batches as $batch) {
/** @var Entity $entity */
foreach ($batch->getCollection() as $entity) {
$this->assertArrayHasKey($entity->getId(), $expectedIds);
Expand Down
1 change: 1 addition & 0 deletions tests/EntityManagerAwareTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ abstract class EntityManagerAwareTestCase extends TestCase

protected ORMPurger $purger;

#[\Override]
public function setUp(): void
{
parent::setUp();
Expand Down
8 changes: 8 additions & 0 deletions tests/Factory/BatcherFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ public function will_use_naive_id_batcher(): void
$qb = $this->createQb();

$cls = new class() implements NaiveIdRangeBatcherInterface {
#[\Override]
public function getSparseness(): int
{
return 1;
}

#[\Override]
public function getBatches(int $batchSize = 100): iterable
{
return [];
}

#[\Override]
public function getBatchCount(int $batchSize = 100): int
{
return 0;
Expand All @@ -52,16 +55,19 @@ public function will_use_id_batcher(): void
$qb = $this->createQb();

$naiveIdBatcher = new class() implements NaiveIdRangeBatcherInterface {
#[\Override]
public function getSparseness(): int
{
return 6;
}

#[\Override]
public function getBatches(int $batchSize = 100): iterable
{
return [];
}

#[\Override]
public function getBatchCount(int $batchSize = 100): int
{
return 0;
Expand All @@ -74,11 +80,13 @@ public function getSparseness(): int
return 6;
}

#[\Override]
public function getBatches(int $batchSize = 100): iterable
{
return [];
}

#[\Override]
public function getBatchCount(int $batchSize = 100): int
{
return 0;
Expand Down