Skip to content

Commit

Permalink
Merge pull request #3 from guil95/master
Browse files Browse the repository at this point in the history
Include argument types
  • Loading branch information
mattiasgeniar authored May 22, 2020
2 parents e4115db + 14c0984 commit 905f8ca
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/Percentage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,65 @@

namespace Mattiasgeniar\Percentage;

class Percentage
final class Percentage
{
/**
* @param float $a
* @param float $b
* @return float
*
* What is the percentage increase or decrease from $a to $b ?
*/
public static function differenceBetween($a, $b): float
public static function differenceBetween(float $a, float $b): float
{
return floatval(($b - $a) / $a * 100);
}

/**
* @param float $a
* @param float $b
* @return float
*
* What is the absolute percentage increase or decrease from $a to $b ?
*/
public static function absoluteDifferenceBetween($a, $b): float
public static function absoluteDifferenceBetween(float $a, float $b): float
{
return floatval(abs(static::differenceBetween($a, $b)));
}

/**
* @param float $a
* @param float $b
* @return float
*
* How much is $a of $b in percentages?
*/
public static function calculate($a, $b): float
public static function calculate(float $a, float $b): float
{
return floatval($a * 100 / $b);
}

/**
* @param float $percentage
* @param float $number
* @return float
*
* Get a percentage return from a number.
*/
public static function of($percentage, $number): float
public static function of(float $percentage, float $number): float
{
return floatval($number * ($percentage / 100));
}

/**
* @param float $percentage
* @param float $a
* @param float $b
* @return float
*
* Get the absolute value if you extend range $a to $b with $percentage.
*/
public static function extension($percentage, $a, $b): float
public static function extension(float $percentage, float $a, float $b): float
{
$movement = abs($a - $b);

Expand Down

0 comments on commit 905f8ca

Please sign in to comment.