PHPackages                             rumd3x/php-countable - 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. rumd3x/php-countable

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

rumd3x/php-countable
====================

Library providing several Object Oriented Counters and utilities for counting stuff

1.0.0(6y ago)04MITPHPPHP &gt;=7.1CI failing

Since Oct 1Pushed 6y agoCompare

[ Source](https://github.com/rumd3x/php-countable)[ Packagist](https://packagist.org/packages/rumd3x/php-countable)[ RSS](/packages/rumd3x-php-countable/feed)WikiDiscussions master Synced 2w ago

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

php-countable
=============

[](#php-countable)

Library providing several Object Oriented utilities for Counting stuff.

[![Build Status](https://camo.githubusercontent.com/74d80c55989bd813ac565b1f6d6e40ea91ec042408edbc9ddcb512b8e01ab082/68747470733a2f2f7472617669732d63692e6f72672f72756d6433782f7068702d636f756e7461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rumd3x/php-countable)[![Codecov](https://camo.githubusercontent.com/cd27a7fbade6fd570e9cae377d708550fe68c47105c1c04f39f9b36682d31a9f/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f72756d6433782f7068702d636f756e7461626c652e737667)](https://camo.githubusercontent.com/cd27a7fbade6fd570e9cae377d708550fe68c47105c1c04f39f9b36682d31a9f/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f72756d6433782f7068702d636f756e7461626c652e737667)[![PHP Version](https://camo.githubusercontent.com/4b7b9d85759f78dd2f90bade5b97c24a6051bb371edee9b70fce25dc69417cb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72756d6433782f7068702d636f756e7461626c652e737667)](https://camo.githubusercontent.com/4b7b9d85759f78dd2f90bade5b97c24a6051bb371edee9b70fce25dc69417cb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72756d6433782f7068702d636f756e7461626c652e737667)

Install
-------

[](#install)

```
composer require rumd3x/php-countable
```

Usage Examples
--------------

[](#usage-examples)

- As a while loop exit condition:

```
use use Rumd3x\Countable\Counters\BasicCounter;

$counter = new BasicCounter(10);

while (!$counter->isZero()) {
    // Do stuff...
    $counter->decrement();
}
```

- As an iterator counter:

```
use use Rumd3x\Countable\Counters\BasicCounter;

$counter = new BasicCounter();

foreach($myArrayOfStuff as $value) {
    // Do stuff...

    $counter->incrementBy($value->quantity);
}

echo "Found {$counter->getCounter()} stuff";
```

API Description
---------------

[](#api-description)

This Library provides:

- 2 counter interfaces `Decrementable` and `Incrementable`.
- A basic `AbstractCounter` that can be extended upon.
- 4 counter implementations, all of them implementing both interfaces, and using `AbstractCounter` as a base.

The `Incrementable` and `Decrementable` interfaces provides the following methods:

```
    /** Incrementable **/
    public function increment(): int; // Increment the counter by one and returns the previous value
    public function incrementBy(int $incrementQuantity): int; //Increments the counter by incrementQuantity and returns the previous value

    /** Decrementable **/
    public function decrement(): int; // Decrements the counter by one and returns the previous value
    public function decrementBy(int $decrementQuantity): int; // Decrements the counter by decrementQuantity and returns the previous value
```

*Each Counter implementation handles incrementing and decrementing the counter differently:*

### BasicCounter

[](#basiccounter)

`Rumd3x\Countable\Counters\BasicCounter`

It is the most basic implementation of both Incrementable and Decrementable interfaces, it does not do any transformation with your inputs, and does not raise any Exceptions.

### StandardCounter

[](#standardcounter)

`Rumd3x\Countable\Counters\StandardCounter`

StandardCounter holds a counter, and can increment or decrement its value by implementing both Incrementable and Decrementable interfaces. It can also count to negatives.

### SmartCounter

[](#smartcounter)

`Rumd3x\Countable\Counters\SmartCounter`

SmartCounter is the same as StandardCounter, but it does not throw `Rumd3x\Countable\Exceptions\NegativeQuantityException` when trying to increment or decrement by negatives, instead it swiftly converts the value to a positive one.

### AbsoluteCounter

[](#absolutecounter)

`Rumd3x\Countable\Counters\AbsoluteCounter`

The AbsoluteCounter is just like a StandardCounter but throws `Rumd3x\Countable\Exceptions\NegativeCounterExpcetion` if tries the program tries to decrement past 0. It ensures the counter is always positive.

### AbstractCounter

[](#abstractcounter)

The `AbstractCounter` implements the following methods below: (Which makes it also available for all 4 Counter implementations provided by the library)

```
    /**
     * Retrieve the current counter value
     * @return integer
     */
    public function getCounter(): int;

    /**
     * Returns true if the counter is zero, false otherwise
     * @return boolean
     */
    public function isZero(): bool;

    /**
     * Returns true if the counter is less than zero, false otherwise
     * @return boolean
     */
    public function isNegative(): bool;

    /**
     * Returns true if the counter is greater than zero, false otherwise
     * @return boolean
     */
    public function isPositive(): bool;
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community6

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

2465d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/35540165?v=4)[edmur](/maintainers/edmur)[@Edmur](https://github.com/Edmur)

---

Top Contributors

[![rumd3x](https://avatars.githubusercontent.com/u/12579932?v=4)](https://github.com/rumd3x "rumd3x (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rumd3x-php-countable/health.svg)

```
[![Health](https://phpackages.com/badges/rumd3x-php-countable/health.svg)](https://phpackages.com/packages/rumd3x-php-countable)
```

###  Alternatives

[functional-php/trampoline

Trampoline implementation for PHP.

3517.7k1](/packages/functional-php-trampoline)

PHPackages © 2026

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