From f4bb7bcbff3770387c2fecfa91ce4a60b916a474 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 27 Nov 2020 08:04:00 +0000 Subject: update composer libs --- vendor/ramsey/collection/src/Tool/TypeTrait.php | 73 +++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 vendor/ramsey/collection/src/Tool/TypeTrait.php (limited to 'vendor/ramsey/collection/src/Tool/TypeTrait.php') diff --git a/vendor/ramsey/collection/src/Tool/TypeTrait.php b/vendor/ramsey/collection/src/Tool/TypeTrait.php new file mode 100644 index 000000000..8214e9654 --- /dev/null +++ b/vendor/ramsey/collection/src/Tool/TypeTrait.php @@ -0,0 +1,73 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Tool; + +use function is_array; +use function is_bool; +use function is_callable; +use function is_float; +use function is_int; +use function is_numeric; +use function is_object; +use function is_resource; +use function is_scalar; +use function is_string; + +/** + * Provides functionality to check values for specific types. + */ +trait TypeTrait +{ + /** + * Returns `true` if value is of the specified type. + * + * @param string $type The type to check the value against. + * @param mixed $value The value to check. + */ + protected function checkType(string $type, $value): bool + { + switch ($type) { + case 'array': + return is_array($value); + case 'bool': + case 'boolean': + return is_bool($value); + case 'callable': + return is_callable($value); + case 'float': + case 'double': + return is_float($value); + case 'int': + case 'integer': + return is_int($value); + case 'null': + return $value === null; + case 'numeric': + return is_numeric($value); + case 'object': + return is_object($value); + case 'resource': + return is_resource($value); + case 'scalar': + return is_scalar($value); + case 'string': + return is_string($value); + case 'mixed': + return true; + default: + return $value instanceof $type; + } + } +} -- cgit v1.2.3