-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add calculators, refactoring [fixed #7][BC break]
- Loading branch information
MartkCz
committed
Feb 27, 2019
1 parent
d852fba
commit 0cd19ab
Showing
39 changed files
with
564 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
paths: | ||
tests: tests | ||
output: tests/_output | ||
data: tests/_data | ||
support: tests/_support | ||
envs: tests/_envs | ||
actor_suffix: Tester | ||
extensions: | ||
enabled: | ||
- Codeception\Extension\RunFailed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace WebChemistry\Invoice\Calculators; | ||
|
||
class BcCalculator implements ICalculator { | ||
|
||
/** @var int */ | ||
private $scale; | ||
|
||
public function __construct(int $scale = 0) { | ||
if (!function_exists('bcadd')) { | ||
throw new \RuntimeException('BC math is not installed.'); | ||
} | ||
$this->scale = $scale; | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return string | ||
*/ | ||
public function add($op1, $op2): string { | ||
return bcadd((string) $op1, (string) $op2, $this->scale); | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return string | ||
*/ | ||
public function mul($op1, $op2): string { | ||
return bcmul((string) $op1, (string) $op2, $this->scale); | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return string|null | ||
*/ | ||
public function div($op1, $op2): ?string { | ||
return bcdiv((string) $op1, (string) $op2, $this->scale); | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return string | ||
*/ | ||
public function sub($op1, $op2) { | ||
return bcsub((string) $op1, (string) $op2, $this->scale); | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return int | ||
*/ | ||
public function comp($op1, $op2): int { | ||
return bccomp((string) $op1, (string) $op2, $this->scale); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace WebChemistry\Invoice\Calculators; | ||
|
||
class FloatCalculator implements ICalculator { | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return float|int | ||
*/ | ||
public function add($op1, $op2) { | ||
return $op1 + $op2; | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return float|int | ||
*/ | ||
public function mul($op1, $op2) { | ||
return $op1 * $op2; | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return float|int | ||
*/ | ||
public function div($op1, $op2) { | ||
return $op1 / $op2; | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return float|int | ||
*/ | ||
public function sub($op1, $op2) { | ||
return $op1 - $op2; | ||
} | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return int | ||
*/ | ||
public function comp($op1, $op2): int { | ||
return $op1 <=> $op2; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace WebChemistry\Invoice\Calculators; | ||
|
||
interface ICalculator { | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return mixed | ||
*/ | ||
public function add($op1, $op2); | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return mixed | ||
*/ | ||
public function mul($op1, $op2); | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return mixed | ||
*/ | ||
public function div($op1, $op2); | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return mixed | ||
*/ | ||
public function sub($op1, $op2); | ||
|
||
/** | ||
* @param string|int|float $op1 | ||
* @param string|int|float $op2 | ||
* @return int | ||
*/ | ||
public function comp($op1, $op2): int; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.