PHP code example of okeyaki / preport

1. Go to this page and download the library: Download okeyaki/preport library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

okeyaki / preport example snippets


use Preport\Reporter;

$reporter = new Reporter;

$reporter->report('too_short_input')
    ->where(function () use ($input) {
        return strlen($input) < 4;
    });

$reporter->report('too_long_input')
    ->where(function () use ($input) {
        return strlen($input) > 8;
    })
    ->unless('too_short_input');

$reporter->report('no_input')
    ->where(function () use ($input) {
        return !$input;
    });
    ->when('too_short_input');

$reports = $reporter->walk();

foreach ($reports as $report) {
    echo $report->subject();
}

> $input = 'foo';
too_short_input

> $input = '';
too_short_input
no_input

> $input = 'foobarbaz';
too_long_input