Skip to content

Commit

Permalink
Merge pull request #46 from NikarashiHatsu/safe-alpha
Browse files Browse the repository at this point in the history
[PHP 7] feat: safe alpha trait
  • Loading branch information
ozdemirburak authored Oct 5, 2023
2 parents 38f2386 + 01d01c6 commit c7a3187
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Traits/AlphaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,26 @@ trait AlphaTrait
public function alpha($alpha = null)
{
if ($alpha !== null) {
$this->alpha = min($alpha, 1);
$this->alpha = $this->localeSafeAlpha(min($alpha, 1));
return $this;
}
return $this->alpha;
return $this->localeSafeAlpha($this->alpha);
}

/**
* @param float $alpha
*
* @return $this|float
*/
public function localeSafeAlpha($alpha)
{
setlocale(LC_NUMERIC, 'C');

$safeAlpha = round($alpha, 2);

setlocale(LC_NUMERIC, 0);

return $safeAlpha;
}

/**
Expand Down

0 comments on commit c7a3187

Please sign in to comment.