PHPackages                             kuaukutsu/ds-collection - 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. kuaukutsu/ds-collection

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

kuaukutsu/ds-collection
=======================

Is the abstract layer which covers functionality the data structure Collection.

2.2.2(2mo ago)143.0k2MITPHPPHP ^8.2CI passing

Since Nov 10Pushed 2mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (31)Used By (2)

Data structure Collection
=========================

[](#data-structure-collection)

Коллекция объектов.

[![PHP Version Require](https://camo.githubusercontent.com/dc04050461209c535463a8a44207644830c37222b8627a30e3a0a4b6d86d30fe/687474703a2f2f706f7365722e707567782e6f72672f6b7561756b757473752f64732d636f6c6c656374696f6e2f726571756972652f706870)](https://packagist.org/packages/kuaukutsu/ds-collection)[![Latest Stable Version](https://camo.githubusercontent.com/1498ce41dab03cb51504e210b5d5b75b4cabe76c7949adead72eea7726125645/68747470733a2f2f706f7365722e707567782e6f72672f6b7561756b757473752f64732d636f6c6c656374696f6e2f762f737461626c65)](https://packagist.org/packages/kuaukutsu/ds-collection)[![License](https://camo.githubusercontent.com/303916fcb7694994c7cd0ae7a589df4c590f1bd31e4221363a25fe6893c37e34/687474703a2f2f706f7365722e707567782e6f72672f6b7561756b757473752f64732d636f6c6c656374696f6e2f6c6963656e7365)](https://packagist.org/packages/kuaukutsu/ds-collection)[![Psalm Level](https://camo.githubusercontent.com/318fc1de4a36f4a58da4d7c86eda19d28f94171bba90f9f4fe672951ccbc774b/68747470733a2f2f73686570686572642e6465762f6769746875622f6b7561756b757473752f64732d636f6c6c656374696f6e2f6c6576656c2e737667)](https://shepherd.dev/github/kuaukutsu/ds-collection)[![Psalm Type Coverage](https://camo.githubusercontent.com/785c57cbc9b2ec21e7e6c074de50f1769556185ef618f8b8bf082dcf25caa7ce/68747470733a2f2f73686570686572642e6465762f6769746875622f6b7561756b757473752f64732d636f6c6c656374696f6e2f636f7665726167652e737667)](https://shepherd.dev/github/kuaukutsu/ds-collection)

Tech Stack
----------

[](#tech-stack)

kuaukutsu/ds-collection is built on the following main stack:

- [PHP](http://www.php.net/) – Languages
- [PHPUnit](https://phpunit.de/) – Testing Frameworks
- [GitHub Actions](https://github.com/features/actions) – Continuous Integration

Примеры
-------

[](#примеры)

```
$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));

$collectionOther = new DtoCollection();
$collectionOther->attach(new Dto(3, 'third'));
$collectionOther->attach(new Dto(4, 'fourth'));

$collection->merge($collectionOther);
```

### Фильтрация

[](#фильтрация)

```
$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));
$collection->attach(new Dto(3, 'first'));
$collection->attach(new Dto(4, 'second'));

$collectionByFiltered = $collection->filter(
    static fn(Dto $dto): bool => $dto->name === 'first'
);
```

### Сортировка

[](#сортировка)

```
$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));
$collection->attach(new Dto(3, 'first'));
$collection->attach(new Dto(4, 'second'));

$sortCollection = $collection->sort(
    static fn(Dto $a, Dto $b): int => strcmp($a->name, $b->name)
);
```

### Индексация

[](#индексация)

В классе коллекции необходимо указать на основании какого свойства объекта индексировать коллекцию. Это делается при помощи метода `indexBy`, например:

```
/**
 * @param Dto $item
 * @return int
 */
protected function indexBy($item): int
{
    return $item->id;
}
```

```
/**
 * @param Dto $item
 * @return string
 */
protected function indexBy($item): string
{
    return $item->name;
}
```

Это позволяет получить быстрый доступ к объекту по ключу индекса, например для indexBy по ключу name:

```
$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));

$dto = $collection->get('second');
```

#### Составные ключи

[](#составные-ключи)

Ключ индексирования может быть составным, например:

```
/**
 * @param Dto $item
 * @return array
 */
protected function indexBy($item): array
{
    return [$item->id, $item->name];
}
```

```
$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));
$collection->attach(new Dto(22, 'second'));

$dto = $collection->get(2, 'second');
```

Testing
-------

[](#testing)

### Unit testing

[](#unit-testing)

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

```
make phpunit
```

```
PHP_VERSION=8.1 make phpunit
```

### Static analysis

[](#static-analysis)

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:

```
make psalm
```

```
PHP_VERSION=8.1 make psalm
```

```
make phpstan
```

```
PHP_VERSION=8.4 make phpstan
```

### Code Sniffer

[](#code-sniffer)

```
make phpcs
```

### Rector

[](#rector)

```
make rector
```

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 96% 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 ~69 days

Recently: every ~51 days

Total

29

Last Release

70d ago

Major Versions

1.4.4 → 2.0.12022-11-05

1.4.7 → 2.0.22023-10-14

PHP version history (5 changes)1.0.0PHP &gt;=7.4

2.0.1PHP ^7.4|^8.0

2.0.2PHP ^8.1

2.1.1PHP ^8.1.31

2.2.1PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![kuaukutsu](https://avatars.githubusercontent.com/u/647093?v=4)](https://github.com/kuaukutsu "kuaukutsu (48 commits)")[![stack-file[bot]](https://avatars.githubusercontent.com/in/408123?v=4)](https://github.com/stack-file[bot] "stack-file[bot] (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kuaukutsu-ds-collection/health.svg)

```
[![Health](https://phpackages.com/badges/kuaukutsu-ds-collection/health.svg)](https://phpackages.com/packages/kuaukutsu-ds-collection)
```

###  Alternatives

[malios/php-to-ascii-table

A PHP library to generate plain text tables.

30118.8k1](/packages/malios-php-to-ascii-table)[samsara/fermat

A library providing math and statistics operations for numbers of arbitrary size.

653.1k3](/packages/samsara-fermat)[shrink0r/workflux

Finite state machine for php.

375.6k1](/packages/shrink0r-workflux)

PHPackages © 2026

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