PHPackages                             juststeveking/masking-engine - 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. juststeveking/masking-engine

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

juststeveking/masking-engine
============================

A data masking engine for PHP.

0.0.1(1y ago)263MITPHPPHP ^8.3

Since Oct 23Pushed 1y ago2 watchersCompare

[ Source](https://github.com/JustSteveKing/masking-engine)[ Packagist](https://packagist.org/packages/juststeveking/masking-engine)[ Docs](https://github.com/juststeveking/masking-engine)[ GitHub Sponsors](https://github.com/sponsors/juststeveking)[ RSS](/packages/juststeveking-masking-engine/feed)WikiDiscussions main Synced 1mo ago

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

Masking Engine
==============

[](#masking-engine)

[![Latest Version](https://camo.githubusercontent.com/baf3b9520d7948ccbc98db40723b5576d34dea590c270564f8a6ce80f45a4f51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a75737473746576656b696e672f6d61736b696e672d656e67696e652e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/juststeveking/masking-engine)[![PHP Version](https://camo.githubusercontent.com/501f069aad004571c24b32f06e6ef65c3d52721f940d6748eac2333e3f971cbe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a75737473746576656b696e672f6d61736b696e672d656e67696e652e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![run-tests](https://github.com/JustSteveKing/masking-engine/actions/workflows/ci.yml/badge.svg)](https://github.com/JustSteveKing/masking-engine/actions/workflows/ci.yml)[![Total Downloads](https://camo.githubusercontent.com/7e2efd1a6f145cde3126786ac527e197e4337774e21303a52694b44a2cf3f5ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a75737473746576656b696e672f6d61736b696e672d656e67696e652e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/juststeveking/masking-engine)

A PHP masking engine, that allows you to quickly and easily mask data based on configured formats.

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

[](#installation)

You can install this package using composer

```
composer require juststeveking/masking-engine
```

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

[](#configuration)

You can publish the configuration for this package using the `php artisan vendor:publish --tag=masking-config`

This will publish the default config to `config/masking.php`, and will look like the following by default:

```
use JustSteveKing\Masking\Matchers\StringMatcher;

return [
    'values' => [
        'password' => StringMatcher::class,
    ],
];
```

Usage
-----

[](#usage)

Let's walk through the usage. We have a values array, that hold how we want to mask data in our application.

You will see that we are using a `StringMatcher` here, what this can do is obfuscate any string to a series of `*`.

For example `test` will turn into `****`. By default, this package comes with a selection of maskers/matchers that you can use - but you are also free to create your own.

- `StringMatcher` - will match or mask a standard string.
- `CreditCard` - will match or mask a credit card number from `1234-1234-1234-1234` to `****-****-****-1234`.
- `Date` - will match or mask a date from `09/09/1988` to `09/09/****`.
- `Email` - will match or mask an email address from `juststevemcd@gmail.com` to `************@gmail.com`.
- `PostalCode` - will match or mask a UK postal code from `B33 8TH` to `B33 ***`.
- `SocialSecurity` - will match or mask a Social Security Number from `123-45-6789` to `***-**-6789`.

Please note, these classes will not validate that the data is correct - for example it will not validate it is a correct credit card number or social security number.

The Masking Engine uses Regex to define a pattern both mask or match the input passed in. All Matching classes needs to either implement the `MasksInput` interface, or extend the `StringMatcher` class itself.

Let's look at the `Email` matcher as an example:

```
final class Email extends StringMatcher
{
    protected string $pattern = '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';

    public function mask(): string
    {
        return (string) preg_replace_callback(
            pattern: '/([^@]+)/',
            callback: static fn(array $matches): string => str_repeat(
                string: '*',
                times: mb_strlen($matches[0]),
            ),
            subject: $this->input,
            limit: 1,
        );
    }
}
```

We define a pattern as a property for the class, which is a simple Regex to make sure that the input is formatted correctly. The masking method, will do a preg replace callback to take certain parts from the input and mask a specific part of the input.

In theory, you don't have to use Regex at all. You could implement something really simple such as:

```
use JustSteveKing\Masking\Matchers\StringMatcher;

final class Dummy extends StringMatcher
{
    public function mask(): string
    {
        return '';
    }
}
```

The only important part of the class, is that the `mask` method will return a string.

Testing
-------

[](#testing)

This package comes will a full test suite, as well as static analysis checks:

```
composer test
```

or

```
composer stan
```

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

[](#contributing)

Feel free to use this package as suits your needs, if you would like to contribute please make sure that you are following the coding standards in place for this library, and test coverage is kept to a high standard.

Security
--------

[](#security)

If you find any security related issues with this package, please feel free to reach out to me directly.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

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

563d ago

### Community

Maintainers

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

---

Top Contributors

[![JustSteveKing](https://avatars.githubusercontent.com/u/6368379?v=4)](https://github.com/JustSteveKing "JustSteveKing (2 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juststeveking-masking-engine/health.svg)

```
[![Health](https://phpackages.com/badges/juststeveking-masking-engine/health.svg)](https://phpackages.com/packages/juststeveking-masking-engine)
```

###  Alternatives

[letournel/path-finder

Path finder algorithm

142.0k](/packages/letournel-path-finder)

PHPackages © 2026

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