edmondscommerce/typesafe-functions
Composer 安装命令:
composer create-project edmondscommerce/typesafe-functions
包简介
Type safe wrappers around internal functions that return mixed types
README 文档
README
To assist with boilerplate around working with internal functions but ensuing that your code keeps tools like phpstan and phpqa happy
See Alternative:
https://github.com/thecodingmachine/safe
This is a more comprehensive library of functions that is auto generated.
I prefer to only include functions that I actually use in this library, the vast majority of functions above will never be used and so I'm reluctant to bring them all in.
Functions Replaced:
File Functions
file_get_contents
returns false|string by default
replaced with \ts\file_get_contents
String Functions
strpos
returns false|int by default
multiple replacements depending on use case:
\ts\strpos to get the actual string position when it is known that the haystack contains the needle
\ts\stringContains to check if the haystack contains the needle
\ts\stringStartsWith to check if the haystack begins with the needle
stripos
//TODO - but will be as above, but case insensitive
Array Functions
in_array
By default this is not strict and requires a third parameter of true.
Simply replace with \ts\arrayContains instead to have this handled automatically.
This improves readability and also prevents various mutation testing escapees that would be otherwise hard to catch
Find: (|\\)in_array\((.+?),(.+?),.+?\)
Replace: \\ts\\arrayContains($2, $3)
Debug Functions
print_r
When passing true, this returns a string, for example
<?php $string=\print_r(['a'=>1], true);
To make this type safe, we replace with
<?php $string = \ts\varToString(['a'=>1]);
Reflection
ReflectionClass
Always returns a single type
Normalises the type, for example to empty strings or throws exceptions on failure
Find Replace
| Find | Replace |
|---|---|
new \ReflectionClass |
new \ts\Reflection\ReflectionClass |
: \ReflectionClass |
: \ts\Reflection\ReflectionClass |
@var \ReflectionClass |
@var \ts\Reflection\ReflectionClass |
(\ReflectionClass $ |
(\ts\Reflection\ReflectionClass $ |
@param \ReflectionClass $ |
@param \ts\Reflection\ReflectionClass $ |
edmondscommerce/typesafe-functions 适用场景与选型建议
edmondscommerce/typesafe-functions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.41k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 edmondscommerce/typesafe-functions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 edmondscommerce/typesafe-functions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 16.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-04