PHPackages                             matthiasmullie/types - 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. matthiasmullie/types

ActiveLibrary

matthiasmullie/types
====================

Some convenient classes to describe/cast types of values

1.0.2(1y ago)1118MITPHPPHP ^8.2

Since May 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/matthiasmullie/types)[ Packagist](https://packagist.org/packages/matthiasmullie/types)[ Docs](https://github.com/matthiasmullie/types)[ GitHub Sponsors](https://github.com/matthiasmullie)[ RSS](/packages/matthiasmullie-types/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Types
=====

[](#types)

[![Build status](https://camo.githubusercontent.com/06e76fe802056fcc62515ab8d83ea53710253904238a147cb2e004790c02e34e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d617474686961736d756c6c69652f74797065732f746573742e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/matthiasmullie/types/actions/workflows/test.yml)[![Code coverage](https://camo.githubusercontent.com/3096ec6ac5c1a705db58b8b2dbd6c5d98ea93ab89a647c6cb40af8433a2f636c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f6d617474686961736d756c6c69652f74797065733f7374796c653d666c61742d737175617265)](https://codecov.io/gh/matthiasmullie/types)[![Latest version](https://camo.githubusercontent.com/cf39bc9f21dcaf6606a507aac228de292ccec68b80976f3ad650ca9779beacac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617474686961736d756c6c69652f74797065733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/matthiasmullie/types)[![Downloads total](https://camo.githubusercontent.com/cfa0f84257f34cc5640eb31af40067b6c9743d0c8d8f513969c658d5fdee59c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617474686961736d756c6c69652f74797065733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/matthiasmullie/types)[![License](https://camo.githubusercontent.com/7d8980ace07d159bb9c8403e1db14789e6884b872cc9ef132e87bb14add94d51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d617474686961736d756c6c69652f74797065733f7374796c653d666c61742d737175617265)](https://github.com/matthiasmullie/types/blob/main/LICENSE)

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

[](#installation)

Simply add a dependency on `matthiasmullie/types` to your composer.json file if you use [Composer](https://getcomposer.org/) to manage the dependencies of your project:

```
composer require matthiasmullie/types
```

Usage
-----

[](#usage)

```
use MatthiasMullie\Types;

$type = new Types\Json(
    new Types\Map([
        'user_id' => new Types\Sha1(
            description: 'Unique user id',
        ),
        'email' => new Types\Email(
            description: 'Email address of the user',
        ),
        'gender' => new Types\Enum(
            ['m', 'f'],
            description: 'Biological sex',
        ),
        'birthdate' => new Types\Optional(
            new Types\Integer(),
            description: 'Birth date, UNIX timestamp',
        ),
    ]),
);
```

```
// this will succeed because the input is valid;
// `birthdate`, given as a string, will be cast to an integer
$safeInput = $type([
    'user_id' => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd4',
    'email' => 'jane.doe@example',
    'gender' => 'f',
    'birthdate' => '1715950172',
]);
```

```
// this will throw an exception because a required field (`gender`)
// is missing; note: `$type->test(...)` can also be used to simply
// check validity instead
$safeInput = $type([
    'user_id' => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd4',
    'email' => 'jane.doe@example',
    'birthdate' => '1715950172',
]);
```

```
// this will throw an exception because the input for `email` is not
// a valid email address
$safeInput = $type([
    'user_id' => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd4',
    'email' => 'not an email address',
    'gender' => 'f',
    'birthdate' => '1715950172',
]);
```

License
-------

[](#license)

types is [MIT](http://opensource.org/licenses/MIT) licensed.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Total

3

Last Release

719d ago

### Community

Maintainers

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

---

Top Contributors

[![matthiasmullie](https://avatars.githubusercontent.com/u/312776?v=4)](https://github.com/matthiasmullie "matthiasmullie (7 commits)")

---

Tags

types

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/matthiasmullie-types/health.svg)

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

###  Alternatives

[cekurte/environment

A library to get the values from environment variables and process to php data types

5884.0k7](/packages/cekurte-environment)[tomatophp/filament-types

Manage any type on your app in Database with easy to use Resource for FilamentPHP

5616.7k8](/packages/tomatophp-filament-types)[type-lang/mapper

Library for mapping variable types to other types

347.1k](/packages/type-lang-mapper)[ptlis/conneg

Tools for performing content negotiation.

364.9k1](/packages/ptlis-conneg)

PHPackages © 2026

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