Skip to content

DjThossi/Ensure

Repository files navigation

Ensure

Some PHP Traits for ensuring values Build Status SensioLabsInsight Code Climate Test Coverage

How it works

The provided Ensure Traits will test if provided $valueToTest has expected value.

  • If $valueToTest is valid nothing happens
  • If $valueToTest is invalid InvalidValueException is thrown

Available Ensure Traits

  • EnsureIsBooleanTrait
  • EnsureIsGreaterThanTrait
  • EnsureIsIntegerTrait
  • EnsureIsLowerThanTrait
  • EnsureIsNotEmptyTrait
  • EnsureIsStringTrait
  • EnsureIsUrlTrait

How to install

You have several options to install this package

Composer

composer require djthossi/ensure

Git

git clone https://github.com/DjThossi/Ensure.git

Download

https://github.com/DjThossi/Ensure/archive/master.zip

Example

class Message
{
    use EnsureIsStringTrait;
    
    const MESSAGE_IS_NOT_A_STRING = 1;
    
    /**
     * @param string $message
     */
    public function __construct($message)
    {
        $this->ensureIsString('Message', $message, self::MESSAGE_IS_NOT_A_STRING);
    }
}

About

Some PHP Traits for ensuring some values

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages