gift-factory/secret-santa-picker

Pick a random player for each other player of a given group

1.1.0 2023-12-09 13:31 UTC

This package is auto-updated.

Last update: 2024-04-06 17:56:32 UTC


README

Pick a random player for each other player of a given group

Latest Stable Version PHP Version License GitHub Actions StyleCI codecov.io

Install

composer require gift-factory/secret-santa-picker

Use

$players = new PlayerList([
    new Player('Anna'),
    new Player('Bob'),
    // Bob and Dane won't be picked to send a gift to Chuck
    new Player('Chuck', exclusions: ['Bob', 'Dane']),
    new Player('Dane'),
    // Edith and Fiona will be mutually excluded
    [new Player('Edith'), new Player('Fiona')],
]);

$picker = new Picker();
$draw = $picker->pick($players);

foreach ($draw as $donor => $receiver) {
    mail(
        $donor->email,
        'Secret Santa',
        "
            Hello $donor->userName,

            This year, you'll be the santa of $receiver->userName,
            Here is the address where to send your gift:

            $receiver->realName
            $receiver->address
        ",
    );
}

Thanks

And a big thank-you to Jet Brains who provides such a great IDE:

687474703a2f2f6a65742d627261696e732e73656c666275696c642e66722f50687053746f726d2d746578742e737667