PHPackages                             kwaadpepper/serial-int-caster - 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. kwaadpepper/serial-int-caster

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

kwaadpepper/serial-int-caster
=============================

Convert int To as serial number and reverse

2.0.0(9mo ago)02.1k↑6300%MITPHPPHP &gt;=7.3.0CI passing

Since May 14Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/Kwaadpepper/serial-int-caster)[ Packagist](https://packagist.org/packages/kwaadpepper/serial-int-caster)[ RSS](/packages/kwaadpepper-serial-int-caster/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (7)Used By (0)

Serial Int Caster PHP
=====================

[](#serial-int-caster-php)

This Library allows encoding an integer to a serial number and the other way around decode it to retrieve the integer.

This library is compatible with **BCMath** and **GMP** extensions to handle large numbers.

Unit tests
----------

[](#unit-tests)

Unit tests are available:

```
composer install
```

```
composer test
```

Usage
-----

[](#usage)

```
composer require kwaadpepper/serial-int-caster
```

### For large numbers (BCMath or GMP)

[](#for-large-numbers-bcmath-or-gmp)

Use the `BCMathBaseConverter` or `GmpBaseConverter` to handle numbers that exceed PHP's integer capacity. One of these extensions must be installed.

```
use Kwaadpepper\\Serial\\SerialCaster;
use Kwaadpepper\\Serial\\SerialCasterBuilder;
use Kwaadpepper\\Serial\\Converters\\BCMathBaseConverter;
use Kwaadpepper\\Serial\\Converters\\GmpBaseConverter;
use Kwaadpepper\\Serial\\Shufflers\\FisherYatesShuffler;

// Using BCMathBaseConverter
$int_to_encode = 9223372036854775807; // PHP_INT_MAX
$seed          = 1492;
$length        = 12;
$chars         = 'ABCDEFabcdef0123456789';

$caster_bcmath = (new SerialCasterBuilder(new BCMathBaseConverter()))
    ->withShuffler(new FisherYatesShuffler())
    ->withChars($chars)
    ->withLength($length)
    ->withSeed($seed)
    ->build();

$encoded_number_bcmath = $caster_bcmath->encode($int_to_encode);

// Prints TRUE
print_r($int_to_encode === $caster_bcmath->decode($encoded_number_bcmath));

// Using GmpBaseConverter
$int_to_encode = 9223372036854775807; // PHP_INT_MAX
$seed          = 1492;
$length        = 12;

$caster_gmp = (new SerialCasterBuilder(new GmpBaseConverter()))
    ->withShuffler(new FisherYatesShuffler())
    ->withChars($chars)
    ->withLength($length)
    ->withSeed($seed)
    ->build();

$encoded_number_gmp = $caster_gmp->encode($int_to_encode);

// Prints TRUE
print_r($int_to_encode === $caster_gmp->decode($encoded_number_gmp));
```

### For small numbers (without BCMath/GMP)

[](#for-small-numbers-without-bcmathgmp)

If you are working with numbers that do not exceed PHP's maximum integer value (`PHP_INT_MAX`), you can use the `NativeBaseConverter`. This is a faster solution because it does not rely on external extensions, but it is limited to initial base conversions of 10 or less.

```
use Kwaadpepper\\Serial\\SerialCaster;
use Kwaadpepper\\Serial\\SerialCasterBuilder;
use Kwaadpepper\\Serial\\Converters\\NativeBaseConverter;
use Kwaadpepper\\Serial\\Shufflers\\FisherYatesShuffler;

$int_to_encode_native = 15;
$seed                 = 1492;
$length               = 6;
$chars                = '01234ABCDE';

$caster_native = (new SerialCasterBuilder(new NativeBaseConverter()))
    ->withShuffler(new FisherYatesShuffler())
    ->withChars($chars)
    ->withLength($length)
    ->withSeed($seed)
    ->build();

$encoded_number_native = $caster_native->encode($int_to_encode_native);

// Prints TRUE
print_r($int_to_encode_native === $caster_native->decode($encoded_number_native));
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance56

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Every ~385 days

Total

5

Last Release

289d ago

Major Versions

1.2.0 → 2.0.02025-08-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d6fe69e010efceae2bd9a92eb6463139fff339c94c545b6b7b1210a00d963e4?d=identicon)[Kwaadpepper](/maintainers/Kwaadpepper)

---

Top Contributors

[![Kwaadpepper](https://avatars.githubusercontent.com/u/6019313?v=4)](https://github.com/Kwaadpepper "Kwaadpepper (63 commits)")

---

Tags

decoderencoderintegerphpserial

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/kwaadpepper-serial-int-caster/health.svg)

```
[![Health](https://phpackages.com/badges/kwaadpepper-serial-int-caster/health.svg)](https://phpackages.com/packages/kwaadpepper-serial-int-caster)
```

###  Alternatives

[tooltipster/tooltipster

Tooltipster is a flexible and extensible jQuery plugin for modern tooltips.

2.7k9.4k2](/packages/tooltipster-tooltipster)[neveldo/text-generator

TextGenerator is a tool that aims to automate the generation of text from data by using a template.

9258.7k](/packages/neveldo-text-generator)[litepie/task

Task package for Lavalite

1210.0k](/packages/litepie-task)

PHPackages © 2026

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