zeus/anti-guard-clause 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固