PHP code example of awjudd / guard-clauses

1. Go to this page and download the library: Download awjudd/guard-clauses 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/ */

    

awjudd / guard-clauses example snippets


use JuddDev\GuardClauses\Guards\Numeric\IntegerGuard;

class PositiveInteger
{
    public function __construct(int $value)
    {
        IntegerGuard::isPositiveOrZero($value);
    }
}

use JuddDev\GuardClauses\Guards\Numeric\IntegerGuard;


class BankAccount
{
    public function __construct(private int $balance)
    {
    }

    public function withdraw(int $amount): bool
    {
        IntegerGuard::isPositiveOrZero($amount);

        // Logic to remove
    }
}

use JuddDev\GuardClauses\Guards\Numeric\IntegerGuard;

class BankAccount
{
    public function __construct(private int $balance)
    {
    }

    public function withdraw(int $amount): bool
    {
        if($amount <= 0) {
            return false;
        }

        // Logic to remove
    }
}