PHPackages                             mf/type-validator - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mf/type-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

mf/type-validator
=================

TypeValidator for asserting types of values

4.1.0(4y ago)035.3k↓100%MITPHPPHP ^8.0

Since Sep 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/MortalFlesh/TypeValidator)[ Packagist](https://packagist.org/packages/mf/type-validator)[ RSS](/packages/mf-type-validator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (5)Versions (11)Used By (0)

TypeValidator
=============

[](#typevalidator)

[![Latest Stable Version](https://camo.githubusercontent.com/b5f98f9aeef6157f23a38bb82fb0fc47bc2b19a488fa3c8dda52213fea1b467a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d662f747970652d76616c696461746f722e737667)](https://packagist.org/packages/mf/type-validator)[![Tests and linting](https://github.com/MortalFlesh/TypeValidator/actions/workflows/tests.yaml/badge.svg)](https://github.com/MortalFlesh/TypeValidator/actions/workflows/tests.yaml)[![Coverage Status](https://camo.githubusercontent.com/cbb7160c8a08db53a1a0b9361ed0e17fea60989fdff704fcf4141d90b2c6d547/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4d6f7274616c466c6573682f5479706556616c696461746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/MortalFlesh/TypeValidator?branch=master)[![Total Downloads](https://camo.githubusercontent.com/a5a436a19f3e438166a7f5498a09d90783d3a285d41c0db376fd69eff4da07f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d662f747970652d76616c696461746f722e737667)](https://packagist.org/packages/mf/type-validator)[![License](https://camo.githubusercontent.com/f2f0b47f059eb8f76c24079381b8ab1ff768c4c52670360c1324f562419423c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d662f747970652d76616c696461746f722e737667)](https://packagist.org/packages/mf/type-validator)

TypeValidator for asserting types of values

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

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

[](#requirements)

- PHP 8.0

Installation:
-----------------------------------------------------

[](#installation)

```
composer require mf/type-validator

```

Usage
--------------------------------------

[](#usage)

```
$validator = new TypeValidator(
    TypeValidator::TYPE_STRING,
    TypeValidator::TYPE_INT,
    [TypeValidator::TYPE_STRING],
    [TypeValidator::INT]
);

$validator->assertKeyType('string - value');
$validator->assertValueType(1);

$validator->assertValueType('invalid value type');  // throws InvalidArgumentException
```

### With Custom Exception

[](#with-custom-exception)

```
$validator = new TypeValidator(
    TypeValidator::TYPE_STRING,
    TypeValidator::TYPE_INT,
    [TypeValidator::TYPE_STRING],
    [TypeValidator::INT],
    App\MyCustomException::class
);

$validator->assertKeyType('string - value');
$validator->assertValueType(1);

$validator->assertValueType('invalid value type');  // throws App\MyCustomException
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity74

Established project with proven stability

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

Recently: every ~296 days

Total

9

Last Release

1582d ago

Major Versions

1.0.0 → 2.0.02017-06-16

2.4.0 → 3.0.02021-03-30

3.0.0 → 4.0.02021-03-31

PHP version history (5 changes)1.0.0PHP &gt;=5.5 || &gt;=7.0

2.0.0PHP &gt;=7.1

2.2.0PHP ^7.1

3.0.0PHP ^7.4

4.0.0PHP ^8.0

### Community

Maintainers

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

---

Top Contributors

[![MortalFlesh](https://avatars.githubusercontent.com/u/6317184?v=4)](https://github.com/MortalFlesh "MortalFlesh (41 commits)")

---

Tags

asserting-typesgeneric-typesgenericstypevalidator

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mf-type-validator/health.svg)

```
[![Health](https://phpackages.com/badges/mf-type-validator/health.svg)](https://phpackages.com/packages/mf-type-validator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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