Improved abstraction for dealing with union and named types.

Overview

Better types

Check whether a reflection type or method accepts a given input

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads


function (FooInterface $foo) {}

$reflectionType = …

$type = new Type($reflectionType);

$type->accepts(new Foo()); // true
$type->accepts('invalid string'); // false
function (?FooInterface $foo, ?BarInterface $bar) {}

$reflectionMethod = …

$method = new Method($reflectionMethod);

$method->accepts(new Foo(), new Bar()); // true
$method->accepts(bar: new Bar() foo: new Foo()); // true
$method->accepts(null, new Bar()); // true
$method->accepts(null, null); // true

$method->accepts('string', 1); // false
$method->accepts(new Foo()); // false, you can't omit values
class Foo
{
    public function acceptsString(string $a) {}
    
    public function acceptsStringToo(string $a) {}
    
    public function acceptsInt(int $a) {}
}

$reflectionClass = …

$handlers = new Handlers($reflectionClass);

$handlers->accepts('string')->all(); // ['acceptsString', 'acceptsStringToo']
$handlers->accepts(1)->first(); // 'acceptsInt'

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/better-types

Usage

$better-types = new Spatie\BetterTypes();
echo $better-types->echoPhrase('Hello, Spatie!');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
PHP library to validate and format license plate numbers.
PHP library to validate and format license plate numbers.

License plate validator and formatter CI Status Lint Coverage Tests This library can be used to validate and format license plate numbers. Countries s

Modern PHP validator on steroids for validating forms and/or array's.

Modern PHP Validator - Standalone Validation on Steroids Introduction Head first example Installation Adding fields for validation Execute validation

Division, District, Upazila/Thana and Union data of Bangladesh for Laravel application.

Bangladesh Geocode Division, District, Upazila/Thana and Union data of Bangladesh for Laravel application. Migration and seeders are ready. Just publi

SecLists is the security tester's companion. It's a collection of multiple types of lists used during security assessments, collected in one place. List types include usernames, passwords, URLs, sensitive data patterns, fuzzing payloads, web shells, and many more. Use your Laravel named routes in JavaScript
Use your Laravel named routes in JavaScript

Ziggy – Use your Laravel routes in JavaScript Ziggy provides a JavaScript route() helper function that works like Laravel's, making it easy to use you

A full PHP implementation of Minecraft's Named Binary Tag (NBT) format.

php-nbt A full PHP implementation of Minecraft's Named Binary Tag (NBT) format. In contrast to other implementations, this library provides full suppo

Use your Laravel named routes in JavaScript
Use your Laravel named routes in JavaScript

Ziggy – Use your Laravel routes in JavaScript Ziggy provides a JavaScript route() helper function that works like Laravel's, making it easy to use you

This is a Reddit-like clone named Scroller, made for the project component of COSC 360 - Web Programming.

The COSC 360 Project Due Dates: See Milestone Dates Overview: The project is designed to help develop your skills for full stack development. With thi

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

This car rental project system project in PHP focuses mainly on dealing with customers regarding their car rental hours and certain transactions.
This car rental project system project in PHP focuses mainly on dealing with customers regarding their car rental hours and certain transactions.

Car-Rental Online Car Rental Management System This car rental project system project in PHP focuses mainly on dealing with customers regarding their

PHP library for dealing with European VAT

ibericode/vat This is a simple PHP library to help you deal with Europe's VAT rules. Fetch VAT rates for any EU member state using ibericode/vat-rates

Sslurp is a simple library which aims to make properly dealing with SSL in PHP suck less.

Sslurp v1.0 by Evan Coury Introduction Dealing with SSL properly in PHP is a pain in the ass and completely insecure by default. Sslurp aims to make i

Improved File Manager package for YunoHost
Improved File Manager package for YunoHost

IFM for YunoHost Lire ce readme en français. This package allows you to install IFM quickly and simply on a YunoHost server. If you don't have YunoHos

Improved Laravel dot notation for explicit array keys.

Laravel Explicit Array Improved Laravel dot notation for explicit array keys. 🤝 Supporting If you are using one or more Renoki Co. open-source packag

An improved helper for working with cache

Laravel Cache Installation To get the latest version of Laravel Cache, simply require the project using Composer: $ composer require dragon-code/larav

Much improved replacement for Zend_Cache_Backend_File - works great with Magento!

Cm_Cache_Backend_File The stock Zend_Cache_Backend_File backend has extremely poor performance for cleaning by tags making it become unusable as the n

Extra validation rules for dealing with images in Laravel 5.

Image-Validator Extra validation rules for dealing with images in Laravel 5. NOTE: As of Laravel version 5.2, there are now built-in validation rules

A PHP wrapper around the OpenSSL extension that provides a user-friendly interface for dealing with OpenSSL.

php-openssl-proxy About A PHP wrapper around the OpenSSL extension that provides a user-friendly interface for dealing with OpenSSL. What's up with th

An improved version of the PHP port of KuzuhaScript

KuzuhaScriptPHP+ (くずはすくりぷとPHP+) An improved version of the PHP port of KuzuhaScript (くずはすくりぷと). To my knowledge, it works with PHP version 4.1.0 and a

Comments
  • Add acceptsTypes method to Handlers

    Add acceptsTypes method to Handlers

    I created this PR as a potential solution for https://github.com/spatie/laravel-event-sourcing/issues/341

    This PR adds an acceptsTypes function to the Handlers class that takes an array of strings and filters methods that match the provided types. This should add the flexibility needed in the event-sourcing library to ignore functions with a single untyped or mixed argument.

    opened by zackrowe 3
  • PHPStan

    PHPStan

    • Install phpstan
    • Fix phpstan complaints
    • Raise phpstan level
    • Raise phpstan level
    • Raise phpstan level
    • Enable generic object types
    • Increase phpstan level
    • Increase phpstan level
    • Run php-cs-fixer
    opened by abenerd 2
  • Add accepts types method

    Add accepts types method

    I created this PR as a potential solution for https://github.com/spatie/laravel-event-sourcing/issues/341

    This PR adds an acceptsTypes function to the Handlers class that takes an array of strings and filters methods that match the provided types. This should add the flexibility needed in the event-sourcing library to ignore functions with a single untyped or mixed argument.

    opened by zackrowe 1
Releases(0.1.2)
Owner
Spatie
We create open source, digital products and courses for the developer community
Spatie
Lightweight and feature-rich PHP validation and filtering library. Support scene grouping, pre-filtering, array checking, custom validators, custom messages. 轻量且功能丰富的PHP验证、过滤库。支持场景分组,前置过滤,数组检查,自定义验证器,自定义消息。

PHP Validate 一个简洁小巧且功能完善的php验证、过滤库。 简单方便,支持添加自定义验证器 支持前置验证检查, 自定义如何判断非空 支持将规则按场景进行分组设置。或者部分验证 支持在进行验证前对值使用过滤器进行净化过滤内置过滤器 支持在进行验证前置处理和后置处理独立验证处理 支持自定义每

Inhere 246 Jan 5, 2023
Validate and sanitize arrays and objects.

Aura.Filter This package provides tools to validate and sanitize objects and arrays. Foreword Installation This library requires PHP 5.4 or later; we

Aura for PHP 153 Jan 2, 2023
PHP library to validate and convert ISBNs and EANs

biblys/isbn biblys/isbn can be used to: validate a string against the ISBN-10, ISBN-13 and EAN-13 formats convert an ISBN to ISBN-10, ISBN-13, EAN-13

Biblys 48 Apr 10, 2022
This package provides tools to validate and sanitize objects and arrays.

Aura.Filter This package provides tools to validate and sanitize objects and arrays. Foreword Installation This library requires PHP 7.2 or later; we

Aura for PHP 153 Jan 2, 2023
File uploads with validation and storage strategies

Upload This component simplifies file validation and uploading. Usage Assume a file is uploaded with this HTML form: <form method="POST" enctype="mult

Brandon Savage 1.7k Dec 27, 2022
Abstracts HTTP request input handling, providing an easy interface for data hydration and validation

Linio Input Linio Input is yet another component of the Linio Framework. It aims to abstract HTTP request input handling, allowing a seamless integrat

Linio 41 Dec 12, 2021
Light and extendable schema validation library

Light PHP validation library For everyone who uses MongoDB or other NoSQL solution and cares about what client sends to his/her database and looking f

Alexander Serkin 43 Sep 28, 2022
A simple package to validate against common passwords and help keep your application secure.

common-passwords A simple package to validate against common passwords and help keep your application secure. composer require crumbls/common-password

Crumbls 4 Oct 16, 2021
Validation rules for Money and Currency

money-validation-laravel Validation rules for Money and Currency Installation composer require brokeyourbike/money-validation-laravel Usage Package us

Ivan Stasiuk 1 Oct 25, 2021
Argentinian CUIT and CUIL Validator

CUIT/CUIL Validator Argentinian CUIT and CUIL Rules for laravel validation Installation $ composer require iutrace/laravel-cuit-validator Usage Exampl

iutrace 6 Sep 20, 2022