eihmels/integer-value-objects

一些值对象

1.0.2 2020-11-23 14:56 UTC

This package is auto-updated.

Last update: 2024-09-23 23:40:07 UTC


README

灵感来自 https://martinfowler.com.cn/bliki/ValueObject.html

在此包中包含一系列具有验证的整数值对象。您可以继承这些基值以适应您的需求。

安装

    composer require eihmels/integer-value-objects

值对象

所有值对象都继承自NumberInterface。在此接口中定义了一些基本函数。请参阅src/NumberInterface.php。

初始化后不允许更改值。

基本整数

src/Integer.php

示例

    $one = Integer:create(1);

自然数

src/NaturalNumber.php

自然数是正整数。

示例

    $one = NaturalNumber:create(1);

0不是有效的自然数。如果您要将0定义为自然数,请使用NaturalNumbersWithNull。

示例

    $null = NaturalNumberWithNull:create(0);

代码质量工具

运行phpUnit

    php ./vendor/bin/phpunit.phar --configuration ./phpunit.xml
    php ./vendor/bin/phpunit.phar --coverage-html ./coverage-report

运行phpstan

   php ./vendor/bin/phpcs.phar --standard=./ruleset.xml  ./src/*/
   php ./vendor/bin/phpcs.phar --standard=./ruleset.xml  ./tests/*

运行phpstan

   php ./vendor/bin/phpstan.phar analyse -l max  ./src/