PHPackages                             pustato/topsort - 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. pustato/topsort

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

pustato/topsort
===============

Topological sorting implementation in PHP

v1.0.1(8y ago)145MITPHPPHP &gt;=7.0

Since Mar 7Pushed 8y ago1 watchersCompare

[ Source](https://github.com/pustato/topsort)[ Packagist](https://packagist.org/packages/pustato/topsort)[ RSS](/packages/pustato-topsort/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Topological Sort in PHP
=======================

[](#topological-sort-in-php)

Simple [Topological Sorting](https://en.wikipedia.org/wiki/Topological_sorting "Wikipedia Link") (aka Dependency Resolution) algorithm implementation in PHP.

Install
-------

[](#install)

```
composer require pustato/topsort

```

Example usage
-------------

[](#example-usage)

Implement interface `\Pustato\TopSort\Contracts\Sortable`:

```
// in SiteAsset.php
class SiteAsset implements Pustato\TopSort\Contracts\Sortable
{

    public function getId()
    {
        return static::class;
    }

    public function getDependencies()
    {
        return [
            JQueryAsset::class, BootstrapAsset::class
        ];
    }

    ...
    // Asset implementation
}
```

```
// in BootstrapAsset.php
class BootstrapAsset implements Pustato\TopSort\Contracts\Sortable
{

    public function getId()
    {
        return static::class;
    }

    public function getDependencies()
    {
        return [
            JQueryAsset::class
        ];
    }

    ...
    // Asset implementation
}
```

```
// in JQueryAsset.php
class JQueryAsset implements Pustato\TopSort\Contracts\Sortable
{

    public function getId()
    {
        return static::class;
    }

    public function getDependencies()
    {
        return [];
    }

    ...
    // Asset implementation
}
```

Add all sortable classes to `\Pustato\TopSort\Collection` and sort them:

```
$assetsCollection = new \Pustato\TopSort\Collection([
    new SiteAsset(), new JQueryAsset(), new BootstrapAsset()
]);
$result = $assetsCollection->getSorted();
var_dump($result);
```

And you will get:

```
array(3) {
  [0] => class JQueryAsset#1 (0) {}
  [1] => class BootstrapAsset#2 (0) {}
  [2] => class SiteAsset#3 (0) {}
}

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~185 days

Total

2

Last Release

3166d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9bbd00fc1215a56048a2c75ddd1495d9e143d9c1c2b49d01f710402504d3acf8?d=identicon)[pustato](/maintainers/pustato)

---

Top Contributors

[![pustato](https://avatars.githubusercontent.com/u/2969958?v=4)](https://github.com/pustato "pustato (3 commits)")

---

Tags

php7topological-sort

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pustato-topsort/health.svg)

```
[![Health](https://phpackages.com/badges/pustato-topsort/health.svg)](https://phpackages.com/packages/pustato-topsort)
```

PHPackages © 2026

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