From ea60d1b86dee1dee47e1435bde22cb3299ef8450 Mon Sep 17 00:00:00 2001 From: Denis Smetannikov Date: Sat, 14 Oct 2023 22:08:31 +0300 Subject: [PATCH] PHP CS Fixer - `ordered_types` (#46) --- src/Arr.php | 12 ++++++------ src/Dates.php | 8 ++++---- src/Env.php | 6 +++--- src/Filter.php | 8 ++++---- src/Str.php | 8 ++++---- src/Xml.php | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Arr.php b/src/Arr.php index 3c73897..1711187 100644 --- a/src/Arr.php +++ b/src/Arr.php @@ -62,7 +62,7 @@ public static function key(mixed $key, array $array, bool $returnValue = false): * Check is value exists in the array. * @SuppressWarnings(PHPMD.ShortMethodName) */ - public static function in(mixed $value, array $array, bool $returnKey = false): string|int|bool|null + public static function in(mixed $value, array $array, bool $returnKey = false): null|bool|int|string { $inArray = \in_array($value, $array, true); @@ -96,7 +96,7 @@ public static function last(array $array): mixed /** * Returns the first key in an array. */ - public static function firstKey(array $array): int|string|null + public static function firstKey(array $array): null|int|string { \reset($array); @@ -106,7 +106,7 @@ public static function firstKey(array $array): int|string|null /** * Returns the last key in an array. */ - public static function lastKey(array $array): int|string|null + public static function lastKey(array $array): null|int|string { \end($array); @@ -148,7 +148,7 @@ static function (mixed $value, int|string $key) use (&$flattened, $preserveKeys) */ public static function search( array $array, - null|bool|int|float|string $search, + null|bool|float|int|string $search, ?string $field = null, ): bool|string { // *grumbles* stupid PHP type system @@ -402,11 +402,11 @@ public static function implode(string $glue, array $array): string /** * Remove all items from array by value. */ - public static function removeByValue(array $array, float|bool|int|string|null $value): array + public static function removeByValue(array $array, null|bool|float|int|string $value): array { return \array_filter( $array, - static fn (float|bool|int|string|null $arrayItem): bool => $value !== $arrayItem, + static fn (null|bool|float|int|string $arrayItem): bool => $value !== $arrayItem, \ARRAY_FILTER_USE_BOTH, ); } diff --git a/src/Dates.php b/src/Dates.php index 50ee4e6..65b5bfa 100644 --- a/src/Dates.php +++ b/src/Dates.php @@ -31,7 +31,7 @@ final class Dates /** * Convert to timestamp. */ - public static function toStamp(\DateTime|int|string|null $time = null, bool $currentIsDefault = true): int + public static function toStamp(null|\DateTime|int|string $time = null, bool $currentIsDefault = true): int { if ($time instanceof \DateTime) { return (int)$time->format('U'); @@ -51,7 +51,7 @@ public static function toStamp(\DateTime|int|string|null $time = null, bool $cur /** * Build PHP \DateTime object from mixed input. */ - public static function factory(mixed $time = null, \DateTimeZone|string|null $timeZone = null): \DateTime + public static function factory(mixed $time = null, null|\DateTimeZone|string $timeZone = null): \DateTime { $timeZone = self::timezone($timeZone); @@ -68,7 +68,7 @@ public static function factory(mixed $time = null, \DateTimeZone|string|null $ti /** * Returns a DateTimeZone object based on the current timezone. */ - public static function timezone(\DateTimeZone|string|null $timezone = null): \DateTimeZone + public static function timezone(null|\DateTimeZone|string $timezone = null): \DateTimeZone { if ($timezone instanceof \DateTimeZone) { return $timezone; @@ -94,7 +94,7 @@ public static function is(?string $date): bool /** * Convert time for sql format. */ - public static function sql(int|string|null $time = null): string + public static function sql(null|int|string $time = null): string { return self::factory($time)->format(self::SQL_FORMAT); } diff --git a/src/Env.php b/src/Env.php index 784b1d9..e92b615 100644 --- a/src/Env.php +++ b/src/Env.php @@ -30,9 +30,9 @@ final class Env */ public static function get( string $envVarName, - string|float|int|bool|null $default = null, + null|bool|float|int|string $default = null, int $options = self::VAR_STRING, - ): string|float|int|bool|null { + ): null|bool|float|int|string { $envKey = \trim($envVarName); $value = \getenv($envKey); @@ -52,7 +52,7 @@ public static function get( /** * Converts the type of values like "true", "false", "null" or "123". */ - public static function convert(?string $value, int $options = self::VAR_STRING): string|float|int|bool|null + public static function convert(?string $value, int $options = self::VAR_STRING): null|bool|float|int|string { $cleanedValue = \trim(Filter::stripQuotes((string)$value)); diff --git a/src/Filter.php b/src/Filter.php index 0561a3d..901b975 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -173,7 +173,7 @@ public static function float(mixed $value, int $round = 10): float /** * Smart convert any string to int. */ - public static function int(float|bool|int|string|null $value): int + public static function int(null|bool|float|int|string $value): int { $cleaned = (string)\preg_replace('#[^0-9-+.,]#', '', (string)$value); \preg_match('#[-+]?[\d]+#', $cleaned, $matches); @@ -247,7 +247,7 @@ public static function trimExtend(string $value): string /** * Cleanup array. No empty values. */ - public static function arr(mixed $value, string|\Closure|null $filter = null): array + public static function arr(mixed $value, null|\Closure|string $filter = null): array { $array = (array)$value; @@ -355,7 +355,7 @@ public static function esc(string $string): string /** * Returns Data object from array. */ - public static function data(Data|array $data): Data + public static function data(array|Data $data): Data { if ($data instanceof Data) { return $data; @@ -367,7 +367,7 @@ public static function data(Data|array $data): Data /** * Returns JSON object from array. */ - public static function json(JSON|array $data): JSON + public static function json(array|JSON $data): JSON { if ($data instanceof JSON) { return $data; diff --git a/src/Str.php b/src/Str.php index b8b9fe2..128e478 100644 --- a/src/Str.php +++ b/src/Str.php @@ -606,7 +606,7 @@ public static function uuid(): string /** * Get class name without namespace. */ - public static function getClassName(object|string|null $object, bool $toLower = false): ?string + public static function getClassName(null|object|string $object, bool $toLower = false): ?string { if (\is_object($object)) { $className = $object::class; @@ -789,8 +789,8 @@ public static function listToDescription(array $data, bool $alignByKeys = false) return $acc; } - if ($acc < \strlen((string)$key)) { - $acc = \strlen((string)$key); + if ($acc < self::len((string)$key)) { + $acc = self::len((string)$key); } return $acc; @@ -805,7 +805,7 @@ public static function listToDescription(array $data, bool $alignByKeys = false) if (!isStrEmpty($value)) { $keyFormated = $key; if ($alignByKeys) { - $keyFormated = \str_pad($key, $maxWidth, ' ', \STR_PAD_RIGHT); + $keyFormated = $key . \str_repeat(' ', $maxWidth - self::len($key)); } if (\is_numeric($key) || isStrEmpty($key)) { diff --git a/src/Xml.php b/src/Xml.php index 5a5ae68..1d1206b 100644 --- a/src/Xml.php +++ b/src/Xml.php @@ -24,7 +24,7 @@ final class Xml /** * Escape string before save it as xml content. */ - public static function escape(float|int|string|null $rawXmlContent): string + public static function escape(null|float|int|string $rawXmlContent): string { $rawXmlContent = (string)$rawXmlContent;