phariscope/safephp

A PHP库,作为SafePHP的补充,包含目前尚未支持的函数。

1.0.2 2023-11-26 05:31 UTC

This package is auto-updated.

Last update: 2024-09-26 07:31:07 UTC


README

一组核心PHP函数的重写,当遇到错误时抛出异常而不是返回false

这些函数补充了优秀的SafePHP工具https://github.com/thecodingmachine/safe的功能。

安装

composer require phariscope/safephp

用法

use function SafePHP\boolval;
use function SafePHP\floatval;
use function SafePHP\intval;
use function SafePHP\strval;

use function SafePHP\hash_file;

use function SafePHP\getenv;
use function SafePHP\getenvOrWithENV;

$value = boolval(1); // return true
$value = floatval("123.456"); // return 123.456
$value = intval("123"); // return 123
$value = strval(1); // return "1"

$value = hash_file("md2", $filename); // return a string like "080bf15137e26254e9cd8870b68aec86"

$value = getenv('PWD'); // return string of current PWD
$value = getenv(); // return array of all getenv (be carreful some $_ENV may hav been forgotten) 

$value = getenvOrWithENV('PWD'); // return string of current PWD even if it is in $_ENV only

为phariscope/SafePHP做贡献

要求

  • docker
  • git

安装

单元测试

bin/phpunit

使用测试驱动开发(TDD)原则(感谢Kent Beck等人),遵循良好实践(感谢Uncle Bob等人)。

质量

  • phpcs PSR12
  • phpstan级别9
  • 覆盖率100%
  • infection MSI >99%

快速检查使用

./codecheck

使用以下方法检查覆盖率

bin/phpunit --coverage-html var

并使用浏览器查看'var/index.html'

使用以下方法检查infection

bin/infection

并使用浏览器查看'var/infection.html'