roave/no-floaters 问题修复 & 功能扩展

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

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

roave/no-floaters

Composer 安装命令:

composer require roave/no-floaters

包简介

PHPStan Rules to Disallow Float proliferation in contexts where IEEE-754 rounding errors are not acceptable

README 文档

README

roave/no-floaters

Latest Stable Version

This library is a PHPStan plugin that disallows:

  • declaration of float properties
  • float method parameters
  • float method return types
  • assignment of float values to variables or properties

The reason for this restriction is that rounding errors coming from floating point arithmetic operations are not acceptable in certain business logic scenario, such as dealing with money, evaluating exam results, rocket science, etc.

An example of such problems can be seen with the following typical example:

var_dump((0.7 + 0.1) === 0.8); // output: bool(false)

This can mean no trouble at all, or a lot of trouble, depending on how many numbers you are running through your system, so it is advisable to avoid float for domains where rounding can potentially lead to trouble.

float is still perfectly acceptable in many programming contexts, and this ruleset should only be applied where it is critical not to introduce rounding errors.

Installation

composer require --dev roave/no-floaters

Configuration

In your phpstan.neon configuration, add following section:

includes:
    - vendor/roave/no-floaters/rules.neon

Optionally, you can configure the library to disallow any float-producing expression at all, by adding following to your phpstan.neon:

parameters:
    disallowFloatsEverywhere: true

If the above is enabled, given the following example-file.php contents:

<?php

$a = 1 / 3;

You should get something like following:

vendor/bin/phpstan analyse example-file.php -l 7
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ -----------------------------------------------------
  Line   example-file.php
 ------ -----------------------------------------------------
  3      Cannot assign float to $a - floats are not allowed.
 ------ -----------------------------------------------------


 [ERROR] Found 1 error

roave/no-floaters for enterprise

Available as part of the Tidelift Subscription.

The maintainers of roave/no-floaters and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more..

If you need help with setting up this library in your project, you can contact us at team@roave.com for consulting/support.

roave/no-floaters 适用场景与选型建议

roave/no-floaters 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 339.1k 次下载、GitHub Stars 达 216, 最近一次更新时间为 2019 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 roave/no-floaters 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 roave/no-floaters 我们能提供哪些服务?
定制开发 / 二次开发

基于 roave/no-floaters 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 216
  • Watchers: 4
  • Forks: 13
  • 开发语言: PHP

其他信息

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