digitalrevolution / utils
A library for everyday use utility classes
Installs: 14 152
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 4
Open Issues: 3
Requires
- php: >=8.1
Requires (Dev)
- digitalrevolution/phpunit-file-coverage-inspection: ^v2.0.0
- mikey179/vfsstream: ^1.6.11
- nikic/php-parser: ^4.10
- phpmd/phpmd: ^2.13
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.2
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.7
README
DR Utility Classes
A library with everyday use classes and methods:
Arrays
first
- Get the first element of an array, exception otherwise.firstOrNull
- Get the first element of an array, null otherwise.last
- Get the last element of an array, exception otherwise.lastOrNull
- Get the last element of an array, null otherwise.find
- Find the first element in an array that matches a predicate, exception otherwise.findOrNull
- Find the first element in an array that matches a predicate, null otherwise.contains
- Test if the given value is contained within items. SupportsEquatableInterface
.diff
- Get the difference between two arrays. SupportsComparableInterface
.equals
- Tests if two arrays have equal contents, ignoring order. SupportsComparableInterface
.explode
- Explode a string or null into an array, with exploding empty string to empty array.mapAssoc
- Map an array to a new array using a callback, preserving keys.reindex
- Reindex an array with new keys based on the result of the callback.groupBy
- Group items by the given return value of the callback.remove
- Remove an element from an array based on the callback. SupportsEquatableInterface
.removeKey
- Remove an element from an array based on the key.removeKeys
- Remove multiple elements from an array based on the keys.removeTypes
- Filters an array by removing all values that match the provided types.removeNull
- Filters an array by removing all null values.search
- Find the key of an element in an array or false otherwise. SupportsEquatableInterface
.unique
- Remove duplicate values from an array. SupportsEquatableInterface
.wrap
- Wrap a value in an array, unless it is already an array.
Assert
Fluent assertion methods, inspired by webmozart/assert
:
null
notNull
isArray
inArray
isCallable
resource
object
scalar
integer
numeric
float
string
startsWith
notStartsWith
endsWith
notEndsWith
boolean
true
false
notFalse
nonEmptyString
isInstanceOf
fileExists
file
directory
readable
writable
Example
$value = Assert::notNull($this->repository->find(123));
Installation
composer require digitalrevolution/utils
About us
At 123inkt (Part of Digital Revolution B.V.), every day more than 50 development professionals are working on improving our internal ERP and our several shops. Do you want to join us? We are looking for developers.