Skip to content

Commit

Permalink
Merge pull request #40 from jaulz/patch-1
Browse files Browse the repository at this point in the history
fix: use float instead of int to avoid warnings
  • Loading branch information
ozdemirburak authored Feb 8, 2023
2 parents 49a4190 + ddb6bc3 commit 314ff1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions src/BaseColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ public function __construct(string $code)
}

/**
* @param int $percent
* @param float $percent
*
* @return mixed
*/
public function saturate(int $percent)
public function saturate(float $percent)
{
$color = $this->toHsl();
$saturation = $this->clamp(($color->saturation() + $percent) / 100);
return $color->saturation($saturation * 100)->back($this);
}

/**
* @param int $percent
* @param float $percent
*
* @return mixed
*/
public function desaturate(int $percent)
public function desaturate(float $percent)
{
$color = $this->toHsl();
$saturation = $this->clamp(($color->saturation() - $percent) / 100);
Expand All @@ -108,11 +108,11 @@ public function grayscale()
}

/**
* @param int $percent
* @param float $percent
*
* @return mixed
*/
public function brighten(int $percent)
public function brighten(float $percent)
{
$percent *= -1;
$color = $this->toRgb();
Expand All @@ -123,23 +123,23 @@ public function brighten(int $percent)
}

/**
* @param int $percent
* @param float $percent
*
* @return mixed
*/
public function lighten(int $percent)
public function lighten(float $percent)
{
$color = $this->toHsl();
$lightness = $this->clamp(($color->lightness() + $percent) / 100);
return $color->lightness($lightness * 100)->back($this);
}

/**
* @param int $percent
* @param float $percent
*
* @return mixed
*/
public function darken(int $percent)
public function darken(float $percent)
{
$color = $this->toHsl();
$lightness = $this->clamp(($color->lightness() - $percent) / 100);
Expand All @@ -166,11 +166,11 @@ public function isDark()
}

/**
* @param int $percent
* @param float $percent
*
* @return mixed
*/
public function spin(int $percent)
public function spin(float $percent)
{
$color = $this->toHsl();
$hue = ($color->hue() + $percent) % 360;
Expand All @@ -183,7 +183,7 @@ public function spin(int $percent)
*
* @return mixed
*/
public function mix(BaseColor $color, int $percent = 50)
public function mix(BaseColor $color, float $percent = 50)
{
$first = $this->toRgb();
$second = $color->toRgb();
Expand All @@ -197,7 +197,7 @@ public function mix(BaseColor $color, int $percent = 50)
/**
* @link https://github.com/less/less.js/blob/master/packages/less/src/less/functions/color.js
*
* @param int $percent
* @param float $percent
*
* @return mixed
*/
Expand All @@ -211,7 +211,7 @@ public function tint($percent = 50)
/**
* @link https://github.com/less/less.js/blob/master/packages/less/src/less/functions/color.js
*
* @param int $percent
* @param float $percent
*
* @return mixed
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/AlphaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait AlphaTrait
public function alpha($alpha = null): float|static
{
if ($alpha !== null) {
$this->alpha = min($alpha, 1);
$this->alpha = min(round($alpha, 2), 1);
return $this;
}
return $this->alpha;
Expand Down

0 comments on commit 314ff1b

Please sign in to comment.