PHPackages                             macmotp/codegen - 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. macmotp/codegen

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

macmotp/codegen
===============

Generate human friendly codes

v0.2.0(2y ago)41421MITPHPPHP &gt;=8.0

Since May 10Pushed 2y ago2 watchersCompare

[ Source](https://github.com/macmotp/codegen)[ Packagist](https://packagist.org/packages/macmotp/codegen)[ Docs](https://github.com/macmotp/codegen)[ RSS](/packages/macmotp-codegen/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (7)Dependencies (2)Versions (15)Used By (1)

Code Generator
==============

[](#code-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/86d964047569a54ec6320203ca0d25f1adf780ef14c802b39f95201eb0224576/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61636d6f74702f636f646567656e2e737667)](https://packagist.org/packages/macmotp/codegen)[![Total Downloads](https://camo.githubusercontent.com/335a2fe4b4acc78e6067bae93ee4048ed13c42c17a4eecb6b4fd183e48c399ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61636d6f74702f636f646567656e2e737667)](https://packagist.org/packages/macmotp/codegen)[![codecov](https://camo.githubusercontent.com/b60e0181c1036dac07d3aa511f6b79da27ce86e2f303bf55446fe0462c0dc6b0/68747470733a2f2f636f6465636f762e696f2f67682f6d61636d6f74702f636f646567656e2f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d4b35355251554c574c4a)](https://codecov.io/gh/macmotp/codegen/branch/main/graph/badge.svg?token=K55RQULWLJ)

**Generate human friendly codes**

Useful for referral codes, receipt codes, code references.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1

*for PHP 7.4, use branch v0.1.4*

*for PHP 8.0, use branch v0.1.5*

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

[](#installation)

Install the package via composer:

```
composer require macmotp/codegen
```

Usage
-----

[](#usage)

#### Create semantic and sanitized reference codes from any string

[](#create-semantic-and-sanitized-reference-codes-from-any-string)

```
use Macmotp\Codegen;

$generator = new Codegen();

echo $generator->generate('Bob McLovin');

// (string) 'BOMCLO'

echo $generator->generate('Company Name');

// (string) 'COMPNA'
```

#### Create collections of codes

[](#create-collections-of-codes)

```
use Macmotp\Codegen;

$generator = new Codegen();

for ($i = 0; $i < 4; $i++) {
   echo $generator->generate('Bob McLovin');
}
// (string) 'BOMCLO'
// (string) 'BOMCLV'
// (string) 'BOMCLI'
// (string) 'BOMCLN'

// Or you can simply retrieve the codes directly within a collection:
echo $generator->collection('Bob McLovin', 4);

// (array) [
//    "BOMCLO",
//    "BOMCLV",
//    "BOMCLI",
//    "BOMCLN",
// ];
```

*Once the possibilities are running low due to lack of letters from the source, it automatically applies random letters.**Please note that this package does not guarantee uniqueness on its results.*

Configuration
-------------

[](#configuration)

#### Set configuration parameters

[](#set-configuration-parameters)

```
use Macmotp\Codegen;

$generator = new Codegen();

echo $generator->setCodeLength(10)
        ->prepend('PR')
        ->append('AP')
        ->generate('Company Name');
// (string) 'PRCOMPNAAP'
```

#### List of methods for configuration

[](#list-of-methods-for-configuration)

- `setCodeLength(int $length)`: total length of the generated code;
- `prepend(string $prepend)`: prepend a string;
- `append(string $append)`: append a string;
- `setMaxAttempts(int $maxAttempts)`: set the maximum number of attempts;
- `sanitizeLevel(int $sanitizeLevel)`: read below;

Sanitize levels
---------------

[](#sanitize-levels)

Sometimes the purpose of human-readable codes is to avoid confusion while reading/spelling. Therefore, is possible to apply some filters to remove similar graphic letters/digits.

#### Choose between 3 different levels of sanitization

[](#choose-between-3-different-levels-of-sanitization)

- Level 1. Low/Default: will filter out anything is not a letter or a digit
- Level 2. Medium: will filter out (O - 0 - Q - I - 1) characters
- Level 3. High: will filter out (2 - Z - 4 - A - 5 - S - 8 - B - U - V - Y) characters

*Levels are inclusive, e.g. the highest level will apply also filters of level low and medium*

```
use Macmotp\Codegen;
use Macmotp\Codegen\Config\Config;

$generator = new Codegen();

echo $generator->sanitizeLevel(Config::SANITIZE_LEVEL_MEDIUM)
        ->generate('Bob McLovin');
// (string) 'BBMCLV'
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](changelog.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/contributing.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/security.md) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Marco Gava](https://github.com/macmotp)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](license.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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 ~61 days

Recently: every ~195 days

Total

14

Last Release

1045d ago

PHP version history (3 changes)v0.1.0.x-devPHP ^7.4

v0.1.5PHP ^8.0

v0.2.0.x-devPHP &gt;=8.0

### Community

Maintainers

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

---

Tags

codecode generatorcodegenmacmotphuman friendly codereference codesemantic codereceipt numbers

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/macmotp-codegen/health.svg)

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

###  Alternatives

[endroid/qr-code

Endroid QR Code

4.8k67.6M348](/packages/endroid-qr-code)[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[laminas/laminas-code

Extensions to the PHP Reflection API, static code scanning, and code generation

1.9k185.4M172](/packages/laminas-laminas-code)[nette/php-generator

🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.

2.2k64.2M576](/packages/nette-php-generator)[jetbrains/phpstorm-stubs

PHP runtime &amp; extensions header files for PhpStorm

1.4k27.7M68](/packages/jetbrains-phpstorm-stubs)[scrivo/highlight.php

Server side syntax highlighter that supports 185 languages. It's a PHP port of highlight.js

71040.3M82](/packages/scrivo-highlightphp)

PHPackages © 2026

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