Skip to content

Commit

Permalink
feat (php 7): safe alpha trait
Browse files Browse the repository at this point in the history
  • Loading branch information
NikarashiHatsu committed Oct 5, 2023
1 parent 38f2386 commit 8183dbf
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 null $alpha
*
* @return $this|float
*/
public function localeSafeAlpha($alpha)
{
setlocale(LC_NUMERIC, 'C');

$safeAlpha = $alpha;

setlocale(LC_NUMERIC, 0);

return $safeAlpha;
}

/**
Expand Down

0 comments on commit 8183dbf

Please sign in to comment.