rumd3x/php-countable 问题修复 & 功能扩展

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

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

rumd3x/php-countable

Composer 安装命令:

composer require rumd3x/php-countable

包简介

Library providing several Object Oriented Counters and utilities for counting stuff

README 文档

README

Library providing several Object Oriented utilities for Counting stuff.

Build Status Codecov PHP Version

Install

composer require rumd3x/php-countable

Usage Examples

  • As a while loop exit condition:
use use Rumd3x\Countable\Counters\BasicCounter;

$counter = new BasicCounter(10);

while (!$counter->isZero()) {
    // Do stuff...
    $counter->decrement();
}
  • As an iterator counter:
use use Rumd3x\Countable\Counters\BasicCounter;

$counter = new BasicCounter();

foreach($myArrayOfStuff as $value) {
    // Do stuff...

    $counter->incrementBy($value->quantity);
}

echo "Found {$counter->getCounter()} stuff";

API Description

This Library provides:

  • 2 counter interfaces Decrementable and Incrementable.
  • A basic AbstractCounter that can be extended upon.
  • 4 counter implementations, all of them implementing both interfaces, and using AbstractCounter as a base.

The Incrementable and Decrementable interfaces provides the following methods:

    /** Incrementable **/
    public function increment(): int; // Increment the counter by one and returns the previous value
    public function incrementBy(int $incrementQuantity): int; //Increments the counter by incrementQuantity and returns the previous value

    /** Decrementable **/
    public function decrement(): int; // Decrements the counter by one and returns the previous value
    public function decrementBy(int $decrementQuantity): int; // Decrements the counter by decrementQuantity and returns the previous value

Each Counter implementation handles incrementing and decrementing the counter differently:

BasicCounter

Rumd3x\Countable\Counters\BasicCounter

It is the most basic implementation of both Incrementable and Decrementable interfaces, it does not do any transformation with your inputs, and does not raise any Exceptions.

StandardCounter

Rumd3x\Countable\Counters\StandardCounter

StandardCounter holds a counter, and can increment or decrement its value by implementing both Incrementable and Decrementable interfaces. It can also count to negatives.

SmartCounter

Rumd3x\Countable\Counters\SmartCounter

SmartCounter is the same as StandardCounter, but it does not throw Rumd3x\Countable\Exceptions\NegativeQuantityException when trying to increment or decrement by negatives, instead it swiftly converts the value to a positive one.

AbsoluteCounter

Rumd3x\Countable\Counters\AbsoluteCounter

The AbsoluteCounter is just like a StandardCounter but throws Rumd3x\Countable\Exceptions\NegativeCounterExpcetion if tries the program tries to decrement past 0. It ensures the counter is always positive.

AbstractCounter

The AbstractCounter implements the following methods below: (Which makes it also available for all 4 Counter implementations provided by the library)

    /**
     * Retrieve the current counter value
     * @return integer
     */
    public function getCounter(): int;

    /**
     * Returns true if the counter is zero, false otherwise
     * @return boolean
     */
    public function isZero(): bool;

    /**
     * Returns true if the counter is less than zero, false otherwise
     * @return boolean
     */
    public function isNegative(): bool;

    /**
     * Returns true if the counter is greater than zero, false otherwise
     * @return boolean
     */
    public function isPositive(): bool;

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固