Skip to content

An API that lets you sort this kind of list and present back a description of how to complete your journey.

Notifications You must be signed in to change notification settings

mbouazzaa/TripSorter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TripSorter

Installation

To install the project you must have Composer installed and run the command below in the root directory of the project.

composer install

Project Dependencies

Note: The project uses the the composer autoload to load classes.

Development Dependencies

Usage

Run the project

To test the project with some predefined values you can run the following command in the public directory

php public/index.php

Code samples

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.

About

An API that lets you sort this kind of list and present back a description of how to complete your journey.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages