Skip to content

GuilleGF/SecretSantaPHP

Repository files navigation

SecretSantaPHP

Build Status Code Coverage Scrutinizer Code Quality Dependency Status Latest Stable Version Total Downloads License

Description

Secret Santa game in PHP

Installation

Composer (Recommended)

Composer is a widely used dependency manager for PHP packages. Is available on Packagist as guillegf/secret-santa and can be installed either by running the composer require command or adding the library to your composer.json. To enable Composer for you project, refer to the project's Getting Started documentation.

To add this dependency using the command, run the following from within your project directory:

composer require guillegf/secret-santa "~1.3"

Alternatively, add the dependency directly to your composer.json file:

"require": {
    "guillegf/secret-santa": "~1.3"
}

Usage

In this example in total we add 10 players, 2 singles players, 2 couples (exclusive) and 4 exclusive players.

The couples and exclusive players never match together.

<?php
$secretSanta = new SecretSanta();
$secretSanta->addPlayer('Player1', '[email protected]')
  ->addPlayer('Player2', '[email protected]')
  ->addCouple('Player3', '[email protected]', 'Couple3', '[email protected]')
  ->addCouple('Player4', '[email protected]', 'Couple4', '[email protected]')
  ->addExclusivePlayers(
      ['Player5', '[email protected]'],
      ['Player6', '[email protected]'],
      ['Player7', '[email protected]'],
      ['Player8', '[email protected]']
  );
  
foreach ($secretSanta->play() as $player) {
     echo ("{$player->name()} ({$player->email()}): {$player->secretSanta()->name()}\n");
}

The above example will output:

Player1 ([email protected]): Player5
Player2 ([email protected]): Player7
Player3 ([email protected]): Player2
Couple3 ([email protected]): Player8
Player4 ([email protected]): Player3
Couple4 ([email protected]): Player6
Player5 ([email protected]): Player4
Player6 ([email protected]): Player1
Player7 ([email protected]): Couple3
Player8 ([email protected]): Couple4

License

The SecretSanta is open-sourced software licensed under the MIT license

About

Secret Santa game in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages