Skip to content

Commit

Permalink
PHP CS Fixer - ordered_types (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis authored Oct 14, 2023
1 parent 501a273 commit ea60d1b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));

Expand Down
8 changes: 4 additions & 4 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ea60d1b

Please sign in to comment.