PHPackages                             nice-yu/unique-code - 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. nice-yu/unique-code

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

nice-yu/unique-code
===================

Generate a unique invitation code within the current system

1.0(1y ago)012MITPHPPHP &gt;=7.4

Since Aug 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/nice-yu/unique-code)[ Packagist](https://packagist.org/packages/nice-yu/unique-code)[ Docs](https://github.com/nice-yu/unique-code)[ RSS](/packages/nice-yu-unique-code/feed)WikiDiscussions main Synced 1mo ago

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

Unique Code Library
===================

[](#unique-code-library)

[简体中文](README.zh-CN.md) | [English](README.md)

Unit Tests
----------

[](#unit-tests)

```
PHPUnit 9.6.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4
Configuration: /var/www/packages/unique-code/phpunit.xml

Functions (NiceYu\Tests\Functions)
 ✔ Unique encode [1.34 ms]
 ✔ Unique decode [17.30 ms]

Unique Code (NiceYu\Tests\UniqueCode)
 ✔ Getters [0.17 ms]
 ✔ Encode decode consistency [0.21 ms]
 ✔ Encode with max length [3.46 ms]
 ✔ Encode exceeding max [1.02 ms]
 ✔ Invalid decode [0.13 ms]
 ✔ Set seed number [0.15 ms]
 ✔ Set dictionaries [1.03 ms]
 ✔ Set complement [0.13 ms]
 ✔ Set max [0.12 ms]

Time: 00:00.040, Memory: 8.00 MB

OK (11 tests, 20 assertions)
```

Default 6 Digits
----------------

[](#default-6-digits)

1. In general, 6 digits are sufficient for large-scale projects.
2. If needed, you can modify it to 7 digits for cases like order calculations.

DigitsMaximum ValueCalculation524,300,00030^56729,000,00030^6721,870,000,00030^7Installation
------------

[](#installation)

### System Requirements

[](#system-requirements)

- PHP &gt;= 7.4

### Install Composer

[](#install-composer)

If you haven't installed Composer yet, install it first:

```
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
```

### Install Library

[](#install-library)

```
composer require nice-yu/unique-code
```

Parameter Description
---------------------

[](#parameter-description)

Parameter NameDefault ValueDescriptionseed\_numberMD5The seed number for shuffling the dictionary, default is to use system info hashed with MD5dictionaries0-9, A-ZDictionary info, default removed characters 0, O, 1, I, and Y, Z as separatorscomplementY-ZSeparator charactersmax6Number of digits to generateDefault Parameters
------------------

[](#default-parameters)

- You can set parameters in a fluent manner

```
use NiceYu\UniqueCode\UniqueCode;

UniqueCode::setSeedNumber(0)
    ->setDictionaries([
        '2', '3', '4', '5', '6', '7', '8', '9',
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X'
    ])
    ->setComplement(['Y', 'Z'])
    ->setMax(6);
```

Get Parameters
--------------

[](#get-parameters)

```
use NiceYu\UniqueCode\UniqueCode;

UniqueCode::getSeedNumber();
UniqueCode::getDictionaries();
UniqueCode::getComplement();
UniqueCode::getMax();
```

Generate Unique Code
--------------------

[](#generate-unique-code)

- Note the parameters set, if the maximum value is exceeded, it will return `null`
- If used across multiple servers, ensure the `seed_number` value is consistent to avoid duplicate unique codes

```
use NiceYu\UniqueCode\UniqueCode;

$id = 123456789;
$code = UniqueCode::encode($id); // Generate
$decodedId = UniqueCode::decode($code); // Reverse
```

Function Usage
--------------

[](#function-usage)

- If you prefer not to use the class, you can use the functions directly, but mind the parameters

```
$id = 12345;
$code = unique_encode($id); // Generate
$decodedId = unique_decode($code); // Reverse
```

Error Handling
--------------

[](#error-handling)

- If encoding fails (e.g., exceeding the maximum value), the `encode` method will return `null`. Ensure to check for this when using.
- In distributed systems, ensure all servers use the same `seed_number` to avoid encoding conflicts.

License
-------

[](#license)

This project is licensed under the [MIT License](LICENSE).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

652d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/22dd7a98b1d9b4221f6a7b3fab0b41dee3e6269ca8d672f6ebfebb9860c3d267?d=identicon)[nice-yu](/maintainers/nice-yu)

---

Top Contributors

[![nice-yu](https://avatars.githubusercontent.com/u/19602003?v=4)](https://github.com/nice-yu "nice-yu (1 commits)")

---

Tags

invitation codeunique code

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nice-yu-unique-code/health.svg)

```
[![Health](https://phpackages.com/badges/nice-yu-unique-code/health.svg)](https://phpackages.com/packages/nice-yu-unique-code)
```

###  Alternatives

[nystudio107/eagerbeaver

Allows you to eager load elements from auto-injected Entry elements on demand from your templates.

251.5k](/packages/nystudio107-eagerbeaver)

PHPackages © 2026

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