PHPackages                             davidvarney/sortedlinkedlist - 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. davidvarney/sortedlinkedlist

ActiveLibrary

davidvarney/sortedlinkedlist
============================

A PHP library providing a sorted linked list for int or string values.

1.0.0(7mo ago)02MITPHPPHP &gt;=8.0CI passing

Since Oct 1Pushed 7mo agoCompare

[ Source](https://github.com/davidvarney/SortedLinkedList)[ Packagist](https://packagist.org/packages/davidvarney/sortedlinkedlist)[ Docs](https://github.com/davidvarney/SortedLinkedList)[ RSS](/packages/davidvarney-sortedlinkedlist/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (4)Used By (0)

SortedLinkedList
================

[](#sortedlinkedlist)

A tiny PHP library that provides a sorted singly-linked list which accepts either ints or strings (but not both). The list keeps values in sorted order as values are added.

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

[](#installation)

Install with Composer:

```
composer require davidvarney/sortedlinkedlist
```

For development (to run tests):

```
composer install
```

Basic usage
-----------

[](#basic-usage)

```
use DavidVarney\SortedLinkedList\SortedLinkedList;

$list = new SortedLinkedList();
$list->add(5);
$list->add(1);
$list->add(3);

// returns [1, 3, 5]
print_r($list->toArray());

// string join with default glue ", "
echo $list->toString(); // "1, 3, 5"

// type information
echo $list->getType(); // "int"

$list->clear();

$list->add('banana');
$list->add('apple');
echo $list->toString('|'); // "apple|banana"
```

Notes:

- The list enforces type consistency: once you add an int the list only accepts ints; same for strings.
- Attempting to add the other type throws an InvalidArgumentException.

API
---

[](#api)

- `add(int|string $value): void` — Insert a value in sorted order.
- `remove(int|string $value): bool` — Remove a value; returns true if removed.
- `toArray(): array` — Return the list as an array of values.
- `toString(string $glue = ', '): string` — Return a joined string of values.
- `contains(int|string $value): bool` — Check presence of a value.
- `isEmpty(): bool` — Check if the list is empty.
- `clear(): void` — Clear the list and reset the stored type.
- `getType(): ?string` — Returns `'int'`, `'string'`, or `null` for empty list.

Running tests
-------------

[](#running-tests)

This project uses PHPUnit (configured in `phpunit.xml`). Run the tests with the vendored PHPUnit binary:

```
./vendor/bin/phpunit
```

For a more readable output use testdox:

```
./vendor/bin/phpunit --testdox
```

Test coverage
-------------

[](#test-coverage)

This repository doesn't include a coverage tool by default, but you can generate coverage with Xdebug or PCOV installed and PHPUnit's `--coverage-html` option. Example (requires Xdebug enabled):

```
./vendor/bin/phpunit --coverage-html coverage

# open coverage/index.html in your browser
```

CI / PHPStan
------------

[](#ci--phpstan)

This repository runs PHPStan via GitHub Actions on `push` and `pull_request` to `main`.

To run PHPStan locally after installing dev dependencies:

```
./vendor/bin/phpstan analyse -c phpstan.neon
```

License
-------

[](#license)

MIT

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance62

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

229d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/95852ffb168c6e8833545839490f55c850c28db1bd4df88e482600f0288348b8?d=identicon)[daveNcbus](/maintainers/daveNcbus)

---

Top Contributors

[![davidvarney](https://avatars.githubusercontent.com/u/1133374?v=4)](https://github.com/davidvarney "davidvarney (26 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/davidvarney-sortedlinkedlist/health.svg)

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

PHPackages © 2026

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