Skip to content

Commit

Permalink
ADD Enum helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-cervenak committed Feb 20, 2024
1 parent eac0590 commit 73dc486
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/Enums/ToArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types = 1);

namespace Wame\Utils\Enums;

trait ToArray
{
public static function toArray(): array
{
$return = [];

foreach (self::cases() as $case) {
$return[$case->value] = $case->title();
}

return $return;
}
}
13 changes: 13 additions & 0 deletions src/Enums/Values.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace Wame\Utils\Enums;

trait Values
{
public static function values(): array
{
return array_column(self::cases(), 'value');
}
}
8 changes: 4 additions & 4 deletions src/Helpers/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public static function calculate($number, $coefficient, $decimal, $round): float


/**
* @param float $number
* @param int|float $number
*
* @return float
* @return int|float
*/
public static function normalize($number): float
public static function normalize($number): int|float
{
return (float) str_replace(',', '.', $number);
return str_replace(',', '.', $number);
}
}

0 comments on commit 73dc486

Please sign in to comment.