Skip to content

ThoroughPHP/TypeGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeGuard - PHP type validation partly inspired by Ceylon Union and Intersection types

Build Status Coverage Status License: MIT PHPStan

Features

TypeGuard can validate:

  • Scalar types: string, integer, etc.:
(new TypeGuard('string'))->match('foo'); // => true
  • Object types: ArrayAccess, stdClass, etc.:
(new TypeGuard('stdClass'))->match(new stdClass()); // => true
  • Union types: string|integer:
$guard = new TypeGuard('string|integer');
$guard->match('foo'); // => true
$guard->match(1); // => true
  • Intersection types: ArrayAccess&Countable:
(new TypeGuard('ArrayAccess&Countable'))->match(new ArrayIterator()); // => true
  • Optional types: ?string:
(new TypeGuard('?string'))->match(null); // => true