承接 atournayre/null 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

atournayre/null

Composer 安装命令:

composer require atournayre/null

包简介

Provides a null object

关键字:

README 文档

README

This package provides a way to handle nullable values in your application.

Getting started

Installation

$ composer require atournayre/null

Usage

Title is from the Fixture namespace in Tests.

Nominal case

Before you used to have return type string and now you can use Title object.

$title = Title::create('My title');

$title->title; // 'My title'
$title->isNull(); // false
$title->isNotNull(); // true

Nullable case

Before you used to have return type null and now you can use Title object.

$title = Title::asNull();

$title->title; // 'Empty title'
$title->isNull(); // true
$title->isNotNull(); // false

Maybe nullable case

Before you used to have return type ?string and now you can use Title object.

If you are not sure if the value is null or not, you can use orNull() method, it's a replacement of ?-> operator.

$title = Title::create('My title')
    ->orNull()
    ->title; // 'My title'
$title = Title::asNull()
    ->orNull()
    ->title; // 'Empty title'

Instead of using orNull() method, you can use orThrow() method to throw an exception if the value is null.

$title = Title::asNull()
    ->orThrow(new \RuntimeException('Title is null'));

orThrow() also accepts a callable to throw an exception with a custom message.

$title = Title::asNull()
    ->orThrow(fn () => new \RuntimeException('Title is null'));    

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

After writing your fix/feature, you can run following commands to make sure that everything is still ok.

# Install dev dependencies
$ composer install

# Running tests and quality tools locally
$ make all

Authors

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固