PHPackages                             marcin-orlowski/type-asserts - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. marcin-orlowski/type-asserts

ActiveLibrary[Testing &amp; Quality](/categories/testing)

marcin-orlowski/type-asserts
============================

Data type assertions.

2.0.0(3y ago)05.0k↑44.4%[1 PRs](https://github.com/MarcinOrlowski/php-type-asserts/pulls)3MITPHPPHP ^8.0||^8.1

Since Sep 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/MarcinOrlowski/php-type-asserts)[ Packagist](https://packagist.org/packages/marcin-orlowski/type-asserts)[ Docs](https://github.com/MarcinOrlowski/php-type-asserts)[ RSS](/packages/marcin-orlowski-type-asserts/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (6)Used By (3)

PHP Type Asserts
================

[](#php-type-asserts)

[![Latest Stable Version](https://camo.githubusercontent.com/843828218e3227069b3ceae0444264d58d59181d8ac5f9c9e074eb35231acb96/68747470733a2f2f706f7365722e707567782e6f72672f6d617263696e2d6f726c6f77736b692f7068702d747970652d617373657274732f762f737461626c65)](https://packagist.org/packages/marcin-orlowski/php-type-asserts)[![License](https://camo.githubusercontent.com/9e0b05e0b169058b14ac0e2d7963d8425b2c6ad2149b649a709b250bc60c3ea1/68747470733a2f2f706f7365722e707567782e6f72672f6d617263696e2d6f726c6f77736b692f7068702d747970652d617373657274732f6c6963656e7365)](https://packagist.org/packages/marcin-orlowski/php-type-asserts)

PHP Data type assertions.

---

This package provides helper methods to validate variable data type. While there are handy native methods like `is_string()` or `is_array()`, you can have then check for single type at a time. This package allows to validate against type union (i.e. `STRING|INT`) or ensure that priovided `string` refers to existing class. Also, contrary to native methods, if there's no match and variable contains data of non-welcomed type, exception is thrown which lets you simplify your code flow.

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

[](#installation)

```
composer require --dev marcin-orlowski/type-asserts
```

---

Usage example
-------------

[](#usage-example)

The following code ensures `$var` is of either `int` or `float` type before math is done:

```
use MarcinOrlowski\TypeAsserts\Type;
use MarcinOrlowski\TypeAsserts\Validator;

$var = 'foo';

Validator::assertIsType($var, [Type::INT, Type::FLOAT]);
$result = $var * 5;
```

The following code ensures `$var` refers to existing class, before we try to instantiate it:

```
use MarcinOrlowski\TypeAsserts\Type;
use MarcinOrlowski\TypeAsserts\Validator;

$cls = 'non-existing';

Validator::assertIsType($cls, Type::EXISTING_CLASS);
$obj = new $cls;
```

---

License
-------

[](#license)

- Written and copyrighted ©2014-2022 by Marcin Orlowski
- Open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

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

Total

4

Last Release

1283d ago

Major Versions

1.2.0 → 2.0.02022-11-04

PHP version history (2 changes)1.0.0PHP ^7.4||^8.0||^8.1

2.0.0PHP ^8.0||^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/8870db56c4a0f54e86e6d574b761bac8654795bdad7b52b3ccdb6a42f0d4af80?d=identicon)[MarcinOrlowski](/maintainers/MarcinOrlowski)

---

Top Contributors

[![MarcinOrlowski](https://avatars.githubusercontent.com/u/8041294?v=4)](https://github.com/MarcinOrlowski "MarcinOrlowski (28 commits)")

---

Tags

phpunitvalidatorhelperassertstestsunittestsphp8typehints

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/marcin-orlowski-type-asserts/health.svg)

```
[![Health](https://phpackages.com/badges/marcin-orlowski-type-asserts/health.svg)](https://phpackages.com/packages/marcin-orlowski-type-asserts)
```

###  Alternatives

[whatthejeff/nyancat-phpunit-resultprinter

Nyan Cat result printer for PHPUnit

283689.8k24](/packages/whatthejeff-nyancat-phpunit-resultprinter)[aik099/phpunit-mink

Library for using Mink in PHPUnit tests. Supports session sharing between tests in a test case.

72136.2k1](/packages/aik099-phpunit-mink)[phpunit/phpunit-dom-assertions

DOM assertions for PHPUnit

29343.5k11](/packages/phpunit-phpunit-dom-assertions)[janmarek/mockista

Mockista is library for mocking, which I've written, because I find mocking in PHPUnit awful.

29221.0k28](/packages/janmarek-mockista)[hot/phpunit-runner

The lib allows to watch phpunit tests

3066.9k4](/packages/hot-phpunit-runner)[code-distortion/adapt

A Laravel package that builds databases for your tests, improving their speed.

2835.5k](/packages/code-distortion-adapt)

PHPackages © 2026

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