konekod/evenly-distribute

Universal service for even distribution of anything

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/konekod/evenly-distribute

1.0.0 2024-06-13 09:22 UTC

This package is auto-updated.

Last update: 2025-12-13 20:43:58 UTC


README

Universal service for even distribution of anything

Features

  • Sort by distinct by field nonUniqueEntityId

  • Distribute evenly by the values defined in pool Id.

    • (strips each element of pool id and builds an array with unique local pool id)

Usage

// See EvenlyDistributeServiceTest::testExampleWorksFine

$input = [
        ['poolId' => 'A', 'uniqueEntityId' => '123', 'nonUniqueEntityId' => 1, 'entity' => ['id' => 123]],
        ['poolId' => 'B', 'uniqueEntityId' => '456', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 456]],
        ['poolId' => 'B', 'uniqueEntityId' => '678', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 678]],
];

$output = EvenlyDistributeService::distributeByPools($input);

$excepted = [
    'A' => [
        ['poolId' => 'A', 'uniqueEntityId' => '123', 'nonUniqueEntityId' => 1, 'entity' => ['id' => 123]]
    ],
    'B' => [
        ['poolId' => 'B', 'uniqueEntityId' => '456', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 456]]
    ],
];

echo $excepted === $output;

Testing

# Run phpunit
vendor/bin/phpunit tests

# PhpStan
composer run phpstan