PHPackages                             smoren/graph-tools - 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. smoren/graph-tools

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

smoren/graph-tools
==================

Graph tools

v1.0.0(2y ago)9463MITPHPPHP &gt;=7.4.0

Since Dec 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Smoren/graph-tools-php)[ Packagist](https://packagist.org/packages/smoren/graph-tools)[ RSS](/packages/smoren-graph-tools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

graph-tools
===========

[](#graph-tools)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/7954349aa5df9cd11becbfee0ff05861fc7d861760beac13471beeb7d5acc80f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6f72656e2f67726170682d746f6f6c73)](https://camo.githubusercontent.com/7954349aa5df9cd11becbfee0ff05861fc7d861760beac13471beeb7d5acc80f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6f72656e2f67726170682d746f6f6c73)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7003f21e54413a9a4a2fbfca7f8a53955e8c541752cbc1473ff04818484b42b5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536d6f72656e2f67726170682d746f6f6c732d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Smoren/graph-tools-php/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/79ae9aee46e3f4cf973d4a6355e0539cc9ae89bd104a411b1db0954256c31cd9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f536d6f72656e2f67726170682d746f6f6c732d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Smoren/graph-tools-php?branch=master)[![Build and test](https://github.com/Smoren/graph-tools-php/actions/workflows/test_master.yml/badge.svg)](https://github.com/Smoren/graph-tools-php/actions/workflows/test_master.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Tools for working with graphs

### How to install to your project

[](#how-to-install-to-your-project)

```
composer require smoren/graph-tools

```

### Unit testing

[](#unit-testing)

```
composer install
composer test-init
composer test

```

### Usage

[](#usage)

#### Working with preloaded graph repository

[](#working-with-preloaded-graph-repository)

##### Basic graph

[](#basic-graph)

```
use Smoren\GraphTools\Models\Edge;
use Smoren\GraphTools\Models\Vertex;
use Smoren\GraphTools\Traverse\Traverse;
use Smoren\GraphTools\Traverse\TraverseDirect;
use Smoren\GraphTools\Traverse\TraverseReverse;
use Smoren\GraphTools\Filters\TransparentTraverseFilter;
use Smoren\GraphTools\Store\PreloadedGraphRepository;
use Smoren\GraphTools\Structs\FilterConfig;

$vertexes = [
    new Vertex(1, 1, null), // id, type, extra data
    new Vertex(2, 1, null),
    new Vertex(3, 1, null),
];
$connections = [
    new Edge(1, 1, 1, 2), // id, type, from id, to id
    new Edge(2, 1, 2, 3),
];

// Creating repository
$repo = new PreloadedGraphRepository($vertexes, $connections);

// Creating direct traverse model
$traverse = new TraverseDirect($repo);
$contexts = $traverse->generate(
    $repo->getVertexById(1),
    new TransparentTraverseFilter([FilterConfig::PREVENT_LOOP_PASS])
);

// Let's go traverse
$vertexIds = [];
foreach($contexts as $context) {
    $vertexIds[] = $context->getVertex()->getId();
}
print_r($vertexIds); // [1, 2, 3]

// Creating reverse traverse model
$traverse = new TraverseReverse($repo);
$contexts = $traverse->generate(
    $repo->getVertexById(3),
    new TransparentTraverseFilter([FilterConfig::PREVENT_LOOP_PASS])
);

// Let's go traverse
$vertexIds = [];
foreach($contexts as $context) {
    $vertexIds[] = $context->getVertex()->getId();
}
print_r($vertexIds); // [3, 2, 1]

$traverse = new Traverse($repo);

// Creating non-directed traverse model
$contexts = $traverse->generate(
    $repo->getVertexById(2),
    new TransparentTraverseFilter([FilterConfig::PREVENT_LOOP_PASS])
);

// Let's go traverse
$vertexIds = [];
$loopsCount = 0;
foreach($contexts as $context) {
    if($context->isLoop()) {
        $contexts->send(Traverse::STOP_BRANCH);
        ++$loopsCount;
    } else {
        $vertexIds[] = $context->getVertex()->getId();
    }
}
print_r($vertexIds); // [2, 3, 1]
var_dump($loopsCount); // 2

// Creating non-directed traverse model with loop prevent control
$contexts = $traverse->generate(
    $repo->getVertexById(2),
    new TransparentTraverseFilter([FilterConfig::PREVENT_LOOP_PASS, FilterConfig::PREVENT_LOOP_HANDLE])
);

// Let's go traverse
$vertexIds = [];
foreach($contexts as $context) {
    $vertexIds[] = $context->getVertex()->getId();
}
print_r($vertexIds); // [2, 3, 1]
```

Look for more examples in [tests](https://github.com/Smoren/graph-tools-php/tree/master/tests/unit).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.8% 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 ~81 days

Total

4

Last Release

996d ago

Major Versions

v0.2.0 → v1.0.02023-08-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdc9e8df44cbbc0fc88885a4f1daa2cad755266e73eb0bac15efaf0d47ecbae2?d=identicon)[smoren](/maintainers/smoren)

---

Top Contributors

[![Smoren](https://avatars.githubusercontent.com/u/7403235?v=4)](https://github.com/Smoren "Smoren (87 commits)")[![astrahov90](https://avatars.githubusercontent.com/u/86964207?v=4)](https://github.com/astrahov90 "astrahov90 (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

edgegraphgraph-algorithmsphptraversevertexmathgraph

###  Code Quality

TestsCodeception

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smoren-graph-tools/health.svg)

```
[![Health](https://phpackages.com/badges/smoren-graph-tools/health.svg)](https://phpackages.com/packages/smoren-graph-tools)
```

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[phpseclib/bcmath_compat

PHP 5.x-8.x polyfill for bcmath extension

16720.7M17](/packages/phpseclib-bcmath-compat)[graphp/graph

GraPHP is the mathematical graph/network library written in PHP.

711292.6k3](/packages/graphp-graph)[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2751.4M5](/packages/rubix-tensor)[amenadiel/jpgraph

Composer Friendly, full refactor of JpGraph, library to make graphs and charts

1492.2M7](/packages/amenadiel-jpgraph)

PHPackages © 2026

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