ayeo/price 问题修复 & 功能扩展

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

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

ayeo/price

最新稳定版本:2.0.6

Composer 安装命令:

composer require ayeo/price

包简介

Simple price model

关键字:

README 文档

README

Build Status Software License Packagist Version Coverage

Price

Simple DDD price model. The goal is to make model usage as easy as possible. Creating object is easy and dont require any additional objects. Object acts as Value Object - is immutable and self-validating. It is designed to be side effect free.

API

Building

$price = new Price(float $nett, float $gross, "GBP")
$price = Price::buildByNett(float $nett, integer $tax, "USD") - returns Price
$price = Price::buildByGross(float $gross, integer $tax, "EUR") - returns Price

Tax

Tax aspects may be a bit confusing at first glance. You may need to build price providing tax rate:

$price = Price::buildByNett(100.00, 8, "USD"):

In this case tax rate is known and it is equal to 8%. When you adding or subtracting prices with same tax rate the result price will come up with same rate. But if you operate with different rates result price has unknown tax rate.

$A = Price::buildByNett(100.00, 8, "USD"):
$B = Price::buildByNett(10.00, 11, "USD"):
$C = $A->add($B);
$C->hasTaxRate(); //returns false

You can still get tax percentage value (but it is not the rate!) using:

$C->getTax()->getValue(); 

Operations

$priceA->add(Price $priceB) - returns Price
$priceA->subtract(Price $priceB) - returns Price
$priceA->multiply(integer $times) - returns Price

$priceA->addGross(float $value) - returns Price
$priceA->subtractGross(float $value) - returns Price

Immutable

Operations creates new instances

$A = new Price(100.00, 120.00, 'USD');
$B = new Price(10.00, 12.00, 'USD');

$sum = $A->add($B);
$sum->getGross(); //returns 132.00
$A->getGross(); //returns 120.00
$B->getGross(); //returns 12.00

Comparing

$priceA->isEqual(Price $priceB) - returns bool
$priceA->isLower(Price $priceB) - returns bool
$priceA->isGreater(Price $priceB) - returns bool

Constraints

  • Nett and gross must be positive
  • Gross must not be lower than nett
  • Tax must be integer
  • Currency symbol is optional but if appears must follow iso 4217 (3 uppercase chars)

Todo

There exists currencies with different precision than 2. The map must be developed. https://en.wikipedia.org/wiki/ISO_4217#Active_codes

Contributing

Feel free to PR, tests must pass.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-12-14