To install the project you must have Composer installed and run the command below in the root directory of the project.
composer install
- PHP: ^7.2
Note: The project uses the the composer autoload to load classes.
- PHPUnit: ^7
To test the project with some predefined values you can run the following command in the public directory
php public/index.php
use App\{
Exceptions\GenericException, SortingAlgorithms\Sorter, Trip
};
use App\BoardingPasses\{
BoardingPassCollection, Factories\BoardingPassFactory
};
$boardingPassFactory = new BoardingPassFactory();
$trainPassFromFactory = $boardingPassFactory->buildTrainPass(
"Madrid",
"Barcelona",
"78A",
"45B"
);
$busPassFromFactory = $boardingPassFactory->buildBusPass(
"Barcelona",
"Gernoa Airport",
"airport",
null
);
$planePassFromFactory = $boardingPassFactory->buildPlanePass(
"Gernoa Airport",
"Stockholm",
"SK455",
"3A",
"45B",
"Baggage drop at ticket counter 344"
);
$planePass1FromFactory1 = $boardingPassFactory->buildTrainPass(
"Stockholm",
"New York JFK",
"SK22",
"7B",
"22",
"Baggage will we automatically transferred from your last leg"
);
$boardingPassCollection = new BoardingPassCollection();
$boardingPassCollection->add($trainPassFromFactory, 0);
$boardingPassCollection->add($busPassFromFactory);
$boardingPassCollection->add($planePass1FromFactory1);
$boardingPassCollection->add($planePassFromFactory);
$sorter = new Sorter();
$tripSorter = new Trip($sorter, $boardingPassCollection);
try {
$sortedBoardingPassCollection = $tripSorter->sortBoardingPasses();
} catch (GenericException $e) {
// treat exception
}
echo PHP_EOL;
// or
$boardingPassCollection = new BoardingPassCollection();
$boardingPassCollection->add($trainPassFromFactory, 0);
$boardingPassCollection->add($busPassFromFactory);
$boardingPassCollection->add($planePass1FromFactory1);
$boardingPassCollection->add($planePassFromFactory);
$sorter = new Sorter();
$tripSorter = new Trip($sorter);
$tripSorter->setBoardingPasses($boardingPassCollection);
try {
$sortedBoardingPassCollection = $tripSorter->sortBoardingPasses();
} catch (GenericException $e) {
// treat exception
}
echo PHP_EOL;
```
##### Sample Output
The final string output will be a BoardingPassCollection that implements the magic method
__toString(), the output will be:
```
1. Take train 78A from Madrid to Barcelona. Sit in seat 45B.
2. Take the airport bus from Barcelona to Gernoa Airport. No seat assignment.
3. From Gernoa Airport, take flight SK455 to Stockholm. Gate 45B, seat 3A.
Baggage drop at ticket counter 344.
4. Take train SK22 from Stockholm to New York JFK. Sit in seat 7B.
5. You have arrived at your final destination.