PHPackages                             mll-lab/php-utils - 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. mll-lab/php-utils

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

mll-lab/php-utils
=================

Shared PHP utility functions of MLL

v6.9.0(2mo ago)253.7k↓44.8%[3 issues](https://github.com/mll-lab/php-utils/issues)[5 PRs](https://github.com/mll-lab/php-utils/pulls)2MITPHPPHP ^7.4 || ^8CI passing

Since Nov 26Pushed 2mo agoCompare

[ Source](https://github.com/mll-lab/php-utils)[ Packagist](https://packagist.org/packages/mll-lab/php-utils)[ Docs](https://github.com/mll-lab/php-utils)[ RSS](/packages/mll-lab-php-utils/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (42)Versions (82)Used By (2)

php-utils
=========

[](#php-utils)

[![.github/workflows/format.yml](https://github.com/mll-lab/php-utils/actions/workflows/format.yml/badge.svg)](https://github.com/mll-lab/php-utils/actions/workflows/format.yml)[![.github/workflows/release.yml](https://github.com/mll-lab/php-utils/actions/workflows/release.yml/badge.svg)](https://github.com/mll-lab/php-utils/actions/workflows/release.yml)[![.github/workflows/validate.yml](https://github.com/mll-lab/php-utils/actions/workflows/validate.yml/badge.svg)](https://github.com/mll-lab/php-utils/actions/workflows/validate.yml)[![Code Coverage](https://camo.githubusercontent.com/66b795d779d98a691dd1263a9d682024db7b6f09a14a6e028fc5b0b2a6c2d21f/68747470733a2f2f636f6465636f762e696f2f67682f6d6c6c2d6c61622f7068702d7574696c732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/mll-lab/php-utils)

[![Latest Stable Version](https://camo.githubusercontent.com/f09a1a1c26531649f8b69e7e417445fdacd9582d9f05965b88fcba7649548c04/68747470733a2f2f706f7365722e707567782e6f72672f6d6c6c2d6c61622f7068702d7574696c732f762f737461626c65)](https://packagist.org/packages/mll-lab/php-utils)[![Total Downloads](https://camo.githubusercontent.com/b5215e5f98758c8ce642169d30cae81168b753145fc71243991ebc4787aca093/68747470733a2f2f706f7365722e707567782e6f72672f6d6c6c2d6c61622f7068702d7574696c732f646f776e6c6f616473)](https://packagist.org/packages/mll-lab/php-utils)

Shared PHP utility functions of MLL

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

[](#installation)

Install through composer

```
composer require mll-lab/php-utils
```

Usage
-----

[](#usage)

See [tests](tests).

### SafeCast

[](#safecast)

PHP's native type casts like `(int)` and `(float)` can produce unexpected results, especially when casting from strings. The `SafeCast` utility provides safe alternatives that validate input before casting:

Each type has two variants:

- `toX()`: returns the cast value or throws `\InvalidArgumentException`
- `tryX()`: returns the cast value or `null` (like `Enum::tryFrom()`)

```
use MLL\Utils\SafeCast;

// Safe integer casting
SafeCast::toInt(42);           // 42
SafeCast::toInt('42');         // 42
SafeCast::toInt('hello');      // throws InvalidArgumentException
SafeCast::tryInt('hello');     // null

// Safe float casting
SafeCast::toFloat(3.14);       // 3.14
SafeCast::toFloat('3.14');     // 3.14
SafeCast::toFloat('abc');      // throws InvalidArgumentException
SafeCast::tryFloat('abc');     // null

// Safe string casting
SafeCast::toString(42);        // '42'
SafeCast::toString(null);      // ''
SafeCast::tryString([1, 2]);   // null

// Safe boolean casting
SafeCast::toBool(true);        // true
SafeCast::toBool(1);           // true
SafeCast::toBool('0');         // false
SafeCast::toBool('true');      // throws InvalidArgumentException
SafeCast::tryBool('true');     // null
```

See [tests](tests/SafeCastTest.php) for more examples.

### Holidays

[](#holidays)

You can add custom holidays by registering a method that returns a map of holidays for a given year. Set this up in a central place that always runs before your application, e.g. a bootstrap method.

```
use MLL\Holidays\BavarianHolidays;

BavarianHolidays::$loadUserDefinedHolidays = static function (int $year): array {
    switch ($year) {
        case 2019:
            return ['22.03' => 'Day of the Tentacle'];
        default:
            return [];
    }
};
```

Custom holidays have precedence over the holidays inherent to this library.

### PHPStan extension

[](#phpstan-extension)

This library provides a PHPStan extension that is either registered through [PHPStan Extension Installer](https://github.com/phpstan/extension-installer)or registered manually by adding the following to your `phpstan.neon`:

```
includes:
+- vendor/mll-lab/php-utils/extension.neon
+- vendor/mll-lab/php-utils/rules.neon
```

Requires `spaze/phpstan-disallowed-calls`.

Changelog
---------

[](#changelog)

See [`CHANGELOG.md`](CHANGELOG.md).

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

[](#contributing)

See [`CONTRIBUTING.md`](.github/CONTRIBUTING.md).

License
-------

[](#license)

This package is licensed using the MIT License.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance68

Regular maintenance activity

Popularity31

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~1 days

Total

69

Last Release

61d ago

Major Versions

v1.14.0 → v2.0.02024-05-22

v2.2.0 → v3.0.02024-06-20

v3.2.0 → v4.0.02024-08-06

v4.1.0 → v5.0.02024-09-11

v5.25.0 → v6.0.02026-02-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ff5d1af2c0f601f7ed7e75e15be0aa4c062149b57fd5aace4e44cc37b8b7a40?d=identicon)[spawnia](/maintainers/spawnia)

![](https://www.gravatar.com/avatar/8bc431e479f402ddb0f2a7d1a35a2e812ab5565b8f5eb78d5c43263984e1cf3c?d=identicon)[SimBig](/maintainers/SimBig)

---

Top Contributors

[![spawnia](https://avatars.githubusercontent.com/u/12158000?v=4)](https://github.com/spawnia "spawnia (58 commits)")[![simbig](https://avatars.githubusercontent.com/u/26680884?v=4)](https://github.com/simbig "simbig (32 commits)")[![semantic-release-bot](https://avatars.githubusercontent.com/u/32174276?v=4)](https://github.com/semantic-release-bot "semantic-release-bot (20 commits)")[![KingKong1213](https://avatars.githubusercontent.com/u/168984406?v=4)](https://github.com/KingKong1213 "KingKong1213 (5 commits)")[![fischerl](https://avatars.githubusercontent.com/u/12935231?v=4)](https://github.com/fischerl "fischerl (5 commits)")[![sp3259](https://avatars.githubusercontent.com/u/41192240?v=4)](https://github.com/sp3259 "sp3259 (2 commits)")[![nebojsa10](https://avatars.githubusercontent.com/u/90136311?v=4)](https://github.com/nebojsa10 "nebojsa10 (1 commits)")[![indy2kro](https://avatars.githubusercontent.com/u/1812715?v=4)](https://github.com/indy2kro "indy2kro (1 commits)")[![dhaupt88](https://avatars.githubusercontent.com/u/133017448?v=4)](https://github.com/dhaupt88 "dhaupt88 (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mll-lab-php-utils/health.svg)

```
[![Health](https://phpackages.com/badges/mll-lab-php-utils/health.svg)](https://phpackages.com/packages/mll-lab-php-utils)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.1k84.2M225](/packages/laravel-horizon)[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

7545.8k](/packages/firefly-iii-data-importer)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[specialtactics/l5-api

Dependencies for the Laravel API Boilerplate package

3672.8k2](/packages/specialtactics-l5-api)

PHPackages © 2026

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