定制 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
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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