PHP code example of vancodx / php-data-assertion

1. Go to this page and download the library: Download vancodx/php-data-assertion 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/ */

    

vancodx / php-data-assertion example snippets


 declare(strict_types=1);

use VanCodX\Data\Assertion\Assertion as A;

/**
 * @param list<int> $ids
 * @return void
 */
function printIds(array $ids): void
{
    A::argIsListLenOfIntId($ids);
    \PHPStan\dumpType($ids); // Reports: Dumped type: non-empty-list<int<1, max>>
    echo 'IDs: ', implode(', ', $ids), "\n";
}

 declare(strict_types=1);

use VanCodX\Data\Assertion\Assertion as A;

/**
 * @return void
 */
function printUsername(): void
{
    $username = getenv('USER');
    A::valIsStrLen($username);
    \PHPStan\dumpType($username); // Reports: Dumped type: non-empty-string
    echo 'Username: ', $username, "\n";
}