zeus/anti-guard-clause
最新稳定版本:v1.0.1
Composer 安装命令:
composer require zeus/anti-guard-clause
包简介
a small library that will save you from typing tons of if-else
README 文档
README
Anti guard clause
I will not tell you what a guard clause is, those who want can research what it is, this library is written to prevent guard clause formation.
for install with composer
composer require zeus/anti-guard-clause
The using
An Example of the anti-guard clause
let's create a some class
Age class
use Zues\Less\IfInterface; readonly class Age implements IfInterface { public function __construct(private int $age) { } /** * @return mixed */ public function make(): mixed { return 'age must be greater than 18'; } /** * @return bool */ public function isTrue(): bool { return 18<=$this->age; } }
The Man class
use Zues\Less\IfInterface; readonly class Man implements IfInterface { public function __construct(private string $gender) { } public function make(): string { return 'gender must be a man'; } /** * @return bool */ public function isTrue(): bool { return $this->gender === 'man'; } }
let's create e default class for else
use Zues\Less\ElseInterface; readonly class ElseGender implements ElseInterface { /** * @return mixed */ public function make(): string { return 'else condition'; } }
and using it
$gender = 'man'; $age = 16; $condition = new Condition(); $condition ->if(new Age($age)) ->ifNot(new Man($gender)) ->else(new ElseGender()); echo $condition->getMake(); //get Result
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-25