Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 646 Bytes

README.md

File metadata and controls

27 lines (21 loc) · 646 Bytes

guard

An extension for beberlei/assert that adds some extra assertions and a factory function to simplify usage.

installation

composer require texdc/guard

usage

namespace my\lib;

use function texdc\guard\verify;

function storeRating(int $rating) : void {
    verify($rating)->numericRange(1, 10, 'rating should be from 1 - 10');
    // ...
}

function speak(string $message, ?int $times = null) : void {
    verify($message)->notEmpty('message is required')->length(256, 'message is too long');
    verify($times, 'invalid multiplier')->nullOr()->isModulus(8);
    // ...
}