PHPackages                             sasakocic/trip-sorter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sasakocic/trip-sorter

ActiveProject[Utility &amp; Helpers](/categories/utility)

sasakocic/trip-sorter
=====================

Trip Sorter

2.0.1(5y ago)07[1 PRs](https://github.com/sasakocic/trip-sorter/pulls)MITPHPPHP ^7.4CI passing

Since Aug 28Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/sasakocic/trip-sorter)[ Packagist](https://packagist.org/packages/sasakocic/trip-sorter)[ RSS](/packages/sasakocic-trip-sorter/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (6)Versions (8)Used By (0)

Trip Sorter
===========

[](#trip-sorter)

[![Build Status](https://camo.githubusercontent.com/1b7939051c9e4a2db22eae809159aff7f7efb32297d6251b2e4c38b100d884b9/68747470733a2f2f7472617669732d63692e6f72672f736173616b6f6369632f747269702d736f727465722e737667)](https://travis-ci.org/sasakocic/trip-sorter)[![Code Style Status](https://camo.githubusercontent.com/1e7e2898f8052ca73186a06fb089a9260ed62eac573c99ec0f3585269cd30ec3/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3130313534323537302f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/101542570)[![CodeCov](https://camo.githubusercontent.com/fa292cd27bd172307582efac91378acba17ef3f087638be8a32367d9b480eb33/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f736173616b6f6369632f747269702d736f727465722e737667)](https://codecov.io/gh/sasakocic/trip-sorter)[![CodeClimate](https://camo.githubusercontent.com/961eb202f8a60a10c5a5f5f1d7e96eeedc06ba0160b5fd299e412c29d3f35cb8/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f30323463613633636333343561323362663731642f6d61696e7461696e6162696c6974792e737667)](https://codeclimate.com/github/sasakocic/trip-sorter)[![Issue Count](https://camo.githubusercontent.com/6b5b1f421d55e99ae2ef14a446ef3d3355b39ba846352a7054893d22a85c4273/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f736173616b6f6369632f747269702d736f727465722f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/sasakocic/trip-sorter)[![Issue Count](https://camo.githubusercontent.com/16b5cbe4d54b419aef39d1e8c4c430232916b9b856b63d9070606e7064413da8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736173616b6f6369632f747269702d736f727465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sasakocic/trip-sorter/?branch=master)

Task
----

[](#task)

You are given a stack of boarding cards for various transportations that will take you from a point A to point B via several stops on the way. All of the boarding cards are out of order, and you don't know where your journey starts, nor where it ends. Each boarding card contains information about seat assignment, and means of transportation (such as flight number, bus number etc). Write an API that lets you sort this kind of list and present back a description of how to complete your journey. For instance the API should be able to take an unordered set of boarding cards, provided in a format defined by you, and produce this list:

1. Take the train 78A from Madrid to Barcelona. Sit in the seat 45B.
2. Take the airport bus from Barcelona to Gerona Airport. No seat assignment.
3. From Gerona Airport, take flight SK455 to Stockholm. Gate 45B, seat 3A. Baggage drop at ticket counter 344.
4. From Stockholm, take flight SK22 to New York JFK. Gate 22, seat 7B. Baggage will we automatically transferred from your last leg.
5. You have arrived at your final destination.

The list should be defined in a format that's compatible with the input format. The API is to be an internal PHP API so it will only communicate with other parts of a PHP application, not server to server, nor server to client. Use PHP-doc to document the input and output your API accepts/returns.

Assumptions
-----------

[](#assumptions)

- Since the result is only one list, I assume that input receives boarding cards for just one particular trip, and we just need to sort them.
- To cover all variations of output without introducing artificial intelligence, I will assume that cards have `Sit in seat 45B.` or `No seat assignment.` written on them. Having a field seat would be considered otherwise.

Installation
------------

[](#installation)

Install with [Composer](https://getcomposer.org/)

```
composer install

```

Tests
-----

[](#tests)

Tests can be executed by running the following command from the root directory

```
composer run tests

```

Usage
-----

[](#usage)

Input is an array in the following format

```
$cards = [
  ['from' => 'Madrid', 'to' => 'Barcelona', 'type' => 'train', 'number' => '78A', 'info' => 'Sit in the seat 45B.'],
  ['from' => 'Barcelona', 'to' => 'Gerona Airport', 'type' => 'airport bus', 'number' => '', 'info' => 'No seat assignment.'],
  ['from' => 'Gerona Airport', 'to' => 'Stockholm', 'type' => 'flight', 'number' => 'SK455', 'seat' => '3A', 'info' => 'Gate 45B, seat 3A. Baggage drop at ticket counter 344.'],
  ['from' => 'Stockholm', 'to' => 'New York JFK', 'type' => 'flight', 'number' => 'SK455', 'seat' => '7B', 'info' => 'Gate 22. Baggage will we automatically transferred from your last leg.'],
];
$result = TripSorter::sort($cards);
```

Result is an array of strings:

1. Take train 78A from Madrid to Barcelona. Sit in seat 45B.
2. Take the airport bus from Barcelona to Gerona Airport. No seat assignment.
3. From Gerona Airport, take flight SK455 to Stockholm. Gate 45B, seat 3A. Baggage drop at ticket counter 344.
4. From Stockholm, take flight SK22 to New York JFK. Gate 22, seat 7B. Baggage will we automatically transferred from your last leg.
5. You have arrived at your final destination.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

Please see the [license file](LICENSE) for more information.

###  Health Score

38

↑

LowBetter than 85% of packages

Maintenance59

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~332 days

Total

5

Last Release

1850d ago

Major Versions

1.2.0 → 2.0.02021-04-20

PHP version history (2 changes)1.1PHP ^7.1

1.2.0PHP ^7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/881312?v=4)[Saša Kocić](/maintainers/sasakocic)[@sasakocic](https://github.com/sasakocic)

---

Top Contributors

[![sasakocic](https://avatars.githubusercontent.com/u/881312?v=4)](https://github.com/sasakocic "sasakocic (28 commits)")[![developeratexample](https://avatars.githubusercontent.com/u/14004359?v=4)](https://github.com/developeratexample "developeratexample (7 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/sasakocic-trip-sorter/health.svg)

```
[![Health](https://phpackages.com/badges/sasakocic-trip-sorter/health.svg)](https://phpackages.com/packages/sasakocic-trip-sorter)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
