PHPackages                             samdark/sack - 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. samdark/sack

ActiveLibrary

samdark/sack
============

1.0.0(3y ago)92[1 PRs](https://github.com/samdark/sack/pulls)MITPHPPHP ^8.0CI failing

Since Sep 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/samdark/sack)[ Packagist](https://packagist.org/packages/samdark/sack)[ Patreon](https://www.patreon.com/samdark)[ RSS](/packages/samdark-sack/feed)WikiDiscussions master Synced 1w ago

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

Sack
====

[](#sack)

[![Latest Stable Version](https://camo.githubusercontent.com/0f209e9b04fd432ff0affb2bf1f20933e21be7f863c733e7b68f18a7e0e029a1/68747470733a2f2f706f7365722e707567782e6f72672f73616d6461726b2f7361636b2f76)](https://packagist.org/packages/samdark/sack)[![Total Downloads](https://camo.githubusercontent.com/e1489cec0cef83c31e66c393f5ef459f26741d28e361f67b56dee9ed750e085e/68747470733a2f2f706f7365722e707567782e6f72672f73616d6461726b2f7361636b2f646f776e6c6f616473)](https://packagist.org/packages/samdark/sack)[![Build status](https://github.com/samdark/sack/workflows/build/badge.svg)](https://github.com/samdark/sack/actions?query=workflow%3Abuild)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d811c0357f56a51d5d8d37fcf0d1a8539ad048e06ab7da136e04140e7b251f16/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d6461726b2f7361636b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samdark/sack/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/fb3fad0690da7b9cf9f077d3205e1078660f8fe09d48be66068db4754bc2b156/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d6461726b2f7361636b2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samdark/sack/?branch=master)[![Mutation testing badge](https://camo.githubusercontent.com/080d7729eacda876dde97f3bd125215b0afebb08ec3ea6bf7e068ce491e28b21/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246796969736f6674253246726261632532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/samdark/sack/master)[![static analysis](https://github.com/samdark/sack/workflows/static%20analysis/badge.svg)](https://github.com/samdark/sack/actions?query=workflow%3A%22static+analysis%22)[![type-coverage](https://camo.githubusercontent.com/d99a3525270613e2e7c0f73a6e998b1d3b5954fe0282ea37ac8ce446df965f6c/68747470733a2f2f73686570686572642e6465762f6769746875622f73616d6461726b2f7361636b2f636f7665726167652e737667)](https://shepherd.dev/github/samdark/sack)

This package implements "0-1 Knapsack Problem" algorithm i.e. allows to find the best way to fill a knapsack of a specified volume with items of a certain volume and value.

It could be applied to:

- Filling a box with most valued items.
- Selecting best tasks for a week knowing each task value and effort in days.
- Selecting attractions to visit in a limited time knowing how much one wants to visit an attraction and time required for a visit.
- etc.

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

[](#installation)

The package could be installed with composer:

```
composer require samdark/sack --prefer-dist
```

General usage
-------------

[](#general-usage)

```
declare(strict_types=1);

use Samdark\Sack\Item;
use Samdark\Sack\SackFiller;

require __DIR__ . '/vendor/autoload.php';

// Items to select from
$items = [
    new Item('Guitar', 1, 1500),
    new Item('Player', 4, 3000),
    new Item('Laptop', 3, 2000),
];

$sackVolume = 7;
$filler = new SackFiller($sackVolume);
$result = $filler->fill($items);

echo "Possible items:\n\n";
echo "Name\tVolume\tValue\n";
foreach ($items as $item) {
    echo "{$item->getName()}\t{$item->getVolume()}\t{$item->getValue()}\n";
}

echo "\n\nMaximum value for sack of $sackVolume is {$result->getValue()}:\n\n";
echo "Name\tVolume\tValue\n";
foreach ($result->getItems() as $item) {
    echo "{$item->getName()}\t{$item->getVolume()}\t{$item->getValue()}\n";
}
```

Testing
-------

[](#testing)

### Unit testing

[](#unit-testing)

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

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

### Mutation testing

[](#mutation-testing)

The package tests are checked with [Infection](https://infection.github.io/) mutation framework with [Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:

```
./vendor/bin/roave-infection-static-analysis-plugin
```

### Static analysis

[](#static-analysis)

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

```
./vendor/bin/psalm
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

1350d ago

### Community

Maintainers

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

---

Top Contributors

[![samdark](https://avatars.githubusercontent.com/u/47294?v=4)](https://github.com/samdark "samdark (6 commits)")

---

Tags

knapsack-problem

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/samdark-sack/health.svg)

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

PHPackages © 2026

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