<commit_before><?php

/**
 * This file is part of the Valit package.
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2017 <NAME>
 * @license   MIT
 */
use Valit\Check;
use Valit\Ensure;
use Valit\Exceptions\InvalidValueException;

require 'vendor/autoload.php';

/*
|----------------------------------------------------------
| Teaser
|----------------------------------------------------------
*/

$age = 42;

Ensure::that($age)
    ->isNumeric()
    ->isGreaterThanOrEqual(18)
    ->isLowerThanOrEqual(75);

/*
|----------------------------------------------------------
| Validity
|----------------------------------------------------------
|
| You can determine if a variable passes all your criteria
| by using the `valid` method.
|
| Conversely you can use the `invalid` method to check if
| one or more checks did not pass.
|
*/

$x = 42; // the variable to validate

$valid = Check::that($x)
    ->isInt()                   // Success
    ->isGreaterThanOrEqual(42)  // Success
    ->isLessThan(100)           // Success
    ->valid();                  // true

var_dump($valid);  // bool(true)

/*
|----------------------------------------------------------
| Error Messages
|----------------------------------------------------------
|
| If you want to know precisely which checks failed, you
| can use the `errorMessages` method.
|
*/

$x = 42; // the variable to validate

$errors = Check::that($x)
    ->isNumeric()       // Success
    ->isFloat()         // Fail
    ->isCloseTo(40)     // Fail
    ->errorMessages();

print_r($errors);

/*
Array
(
    [0] => value must have the type "double"
    [1] => value must equal 40 with a margin of error of 1.0e-5
)<commit_msg>Use success() instead of valid()<commit_after><?php

/**
 * This file is part of the Valit package.
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2017 <NAME>
 * @license   MIT
 */
use Valit\Check;
use Valit\Ensure;
use Valit\Exceptions\InvalidValueException;

require 'vendor/autoload.php';

/*
|----------------------------------------------------------
| Teaser
|----------------------------------------------------------
*/

$age = 42;

Ensure::that($age)
    ->isNumeric()
    ->isGreaterThanOrEqual(18)
    ->isLowerThanOrEqual(75);

/*
|----------------------------------------------------------
| Validity
|----------------------------------------------------------
|
| You can determine if a variable passes all your criteria
| by using the `valid` method.
|
| Conversely you can use the `invalid` method to check if
| one or more checks did not pass.
|
*/

$x = 42; // the variable to validate

$valid = Check::that($x)
    ->isInt()                   // Success
    ->isGreaterThanOrEqual(42)  // Success
    ->isLessThan(100)           // Success
    ->success();                // true

var_dump($valid);  // bool(true)

/*
|----------------------------------------------------------
| Error Messages
|----------------------------------------------------------
|
| If you want to know precisely which checks failed, you
| can use the `errorMessages` method.
|
*/

$x = 42; // the variable to validate

$errors = Check::that($x)
    ->isNumeric()       // Success
    ->isFloat()         // Fail
    ->isCloseTo(40)     // Fail
    ->errorMessages();

print_r($errors);

/*
Array
(
    [0] => value must have the type "double"
    [1] => value must equal 40 with a margin of error of 1.0e-5
)
{'fraction_non_alphanumeric': 0.325567679150693, 'fraction_numerical': 0.016514302565614862, 'mean_word_length': 1.3185235816814764, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6007364', 'n_tokens_mistral': 971, 'n_tokens_neox': 921, 'n_words': 276}