cdn77 / functions
PHP Functions
Installs: 58 957
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 2
Requires
- php: ^8.2
- ext-ds: *
- azjezz/psl: ^2.9 || ^3.0
Requires (Dev)
- cdn77/coding-standard: ^7.0
- ergebnis/composer-normalize: ^2.23
- infection/infection: ^0.29.0
- php-ds/php-ds: ^1.4
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.11
- phpstan/phpstan-phpunit: ^1.0.0
- phpunit/phpunit: ^11.0
- shipmonk/composer-dependency-analyser: ^1.5
README
Functions
absurd()
Function that should have never been called.
Useful for default
case in exhaustive matching.
assert_return()
Asserts the value via the expression and returns it.
It's useful when you want to assert inline so for example you can keep the arrow function in place.
It uses native assert()
internally.
use function Cdn77\Functions\assert_return; array_map( fn (mixed $value) => new RequiresInt(assert_return($value, is_int(...))), [1, 2, 3] );
noop()
Does nothing. Useful e.g. for match
expression that currently supports single-line expressions in blocks.
match ($val) { '1' => throw new Exception, '2' => foo(), default => noop(), };
Ds
mapFromEntries()
Creates a map from an iterable of entries.
use function Cdn77\Functions\mapFromEntries; $map = mapFromEntries([ ['foo', 'bar'], ['baz', 'qux'], ]); assert($map->get('foo') === 'bar');
Iterable
find()
Finds a value in an iterable.
use function Cdn77\Functions\Iterable\find; $iterable = [0, 1, 2, 3]; $option = find($iterable, static fn (mixed $_, int $value) => $value < 2); assert($option->unwrap() === 0);