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-07-06 18:28:36 UTC


README

Secret Santa Picker

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: