dev-master
9999999-devType safe wrappers around internal functions that return mixed types
MIT
The Requires
- php ^7.1
The Development Requires
Type safe wrappers around internal functions that return mixed types
To assist with boilerplate around working with internal functions but ensuing that your code keeps tools like phpstan and phpqa happy, (*1)
https://github.com/thecodingmachine/safe, (*2)
This is a more comprehensive library of functions that is auto generated., (*3)
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., (*4)
file_get_contents
returns false|string by default, (*5)
replaced with \ts\file_get_contents
, (*6)
strpos
returns false|int by default, (*7)
multiple replacements depending on use case:, (*8)
\ts\strpos
to get the actual string position when it is known that the haystack contains the needle, (*9)
\ts\stringContains
to check if the haystack contains the needle, (*10)
\ts\stringStartsWith
to check if the haystack begins with the needle, (*11)
stripos
//TODO - but will be as above, but case insensitive, (*12)
in_array
By default this is not strict and requires a third parameter of true., (*13)
Simply replace with \ts\arrayContains
instead to have this handled automatically., (*14)
This improves readability and also prevents various mutation testing escapees that would be otherwise hard to catch, (*15)
Find: (|\\)in_array\((.+?),(.+?),.+?\)
, (*16)
Replace: \\ts\\arrayContains($2, $3)
, (*17)
print_r
When passing true, this returns a string, for example, (*18)
<?php $string=\print_r(['a'=>1], true);
To make this type safe, we replace with, (*19)
<?php $string = \ts\varToString(['a'=>1]);
Always returns a single type, (*20)
Normalises the type, for example to empty strings or throws exceptions on failure, (*21)
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 $ |
Type safe wrappers around internal functions that return mixed types
MIT