-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Dropelikeit/WorkoverPricecalculatorV2-1
Workover pricecalculator v2 1
- Loading branch information
Showing
20 changed files
with
397 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
} | ||
], | ||
"require": { | ||
"php": ">=7.1", | ||
"php": ">=7.2", | ||
"ext-bcmath": "*" | ||
}, | ||
"require-dev": { | ||
|
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,24 @@ | ||
<?php | ||
|
||
namespace MarcelStrahl\PriceCalculator\Exceptions; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Class ConverterException | ||
* @author Marcel Strahl <[email protected]> | ||
* @package MarcelStrahl\PriceCalculator\Exceptions | ||
*/ | ||
class ConverterException extends Exception | ||
{ | ||
/** | ||
* @param float $amout | ||
* @return ConverterException | ||
*/ | ||
public static function fromZeroAmount(float $amout): self | ||
{ | ||
return new self( | ||
sprintf('Division by zero is not allowed. Please check your injection. Given amount: %f', $amout) | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
<?php | ||
|
||
namespace MarcelStrahl\PriceCalculator\Facade; | ||
|
||
use MarcelStrahl\PriceCalculator\Helpers\Entity\Vat; | ||
use MarcelStrahl\PriceCalculator\PriceCalculator as PriceCalculatorService; | ||
|
||
/** | ||
* Class PriceCalculator | ||
* @author Marcel Strahl <[email protected]> | ||
* @package MarcelStrahl\PriceCalculator\Facade | ||
*/ | ||
class PriceCalculator | ||
{ | ||
/** | ||
* @var Vat | ||
*/ | ||
private $vat; | ||
|
||
public function __construct() | ||
{ | ||
$this->vat = new Vat(); | ||
} | ||
|
||
/** | ||
* @param int $vat | ||
* @return PriceCalculatorService | ||
*/ | ||
public static function getPriceCalculator(int $vat) | ||
{ | ||
return (new self())->createPriceCalculator($vat); | ||
} | ||
|
||
/** | ||
* @param int $vat | ||
* @return PriceCalculatorService | ||
*/ | ||
private function createPriceCalculator(int $vat): PriceCalculatorService | ||
{ | ||
$this->vat->setVat($vat); | ||
return new PriceCalculatorService($this->vat); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace MarcelStrahl\PriceCalculator\Facade; | ||
|
||
use MarcelStrahl\PriceCalculator\UnitConverter as UnitConverterService; | ||
use MarcelStrahl\PriceCalculator\Factory\Converter as ConverterFactory; | ||
|
||
/** | ||
* Class UnitConverter | ||
* @author Marcel Strahl <[email protected]> | ||
* @package MarcelStrahl\PriceCalculator\Facade | ||
*/ | ||
class UnitConverter | ||
{ | ||
/** | ||
* @return UnitConverterService | ||
*/ | ||
public static function getConverter(): UnitConverterService | ||
{ | ||
return (new self)->createUnitConverter(); | ||
} | ||
|
||
/** | ||
* @return UnitConverterService | ||
*/ | ||
private function createUnitConverter(): UnitConverterService | ||
{ | ||
return new UnitConverterService($this->createFactory()); | ||
} | ||
|
||
/** | ||
* @return ConverterFactory | ||
*/ | ||
private function createFactory(): ConverterFactory | ||
{ | ||
return new ConverterFactory(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MarcelStrahl\PriceCalculator\Helpers\Converter; | ||
|
||
use MarcelStrahl\PriceCalculator\Exceptions\ConverterException; | ||
|
||
/** | ||
* Interface ConverterInterface | ||
* @author Marcel Strahl <[email protected]> | ||
|
@@ -12,6 +14,14 @@ interface ConverterInterface | |
/** | ||
* @param float $amount | ||
* @return float | ||
* @throws ConverterException | ||
*/ | ||
public function convert(float $amount): float; | ||
|
||
/** | ||
* @param float $amount | ||
* @return void | ||
* @throws ConverterException | ||
*/ | ||
public function isZeroAmount(float $amount): void; | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MarcelStrahl\PriceCalculator\Helpers\Converter; | ||
|
||
use MarcelStrahl\PriceCalculator\Exceptions\ConverterException; | ||
|
||
/** | ||
* Class CentToEuro | ||
* @author Marcel Strahl <[email protected]> | ||
|
@@ -14,6 +16,17 @@ class CentToEuro implements ConverterInterface | |
*/ | ||
public function convert(float $amount): float | ||
{ | ||
$this->isZeroAmount($amount); | ||
return (float)bcdiv($amount, 100, 2); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function isZeroAmount(float $amount): void | ||
{ | ||
if (empty($amount)) { | ||
throw ConverterException::fromZeroAmount($amount); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MarcelStrahl\PriceCalculator\Helpers\Converter; | ||
|
||
use MarcelStrahl\PriceCalculator\Exceptions\ConverterException; | ||
|
||
/** | ||
* Class EuroToCent | ||
* @author Marcel Strahl <[email protected]> | ||
|
@@ -14,6 +16,17 @@ class EuroToCent implements ConverterInterface | |
*/ | ||
public function convert(float $amount): float | ||
{ | ||
$this->isZeroAmount($amount); | ||
return (float)bcmul($amount, 100); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function isZeroAmount(float $amount): void | ||
{ | ||
if (empty($amount)) { | ||
throw ConverterException::fromZeroAmount($amount); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,21 +2,20 @@ | |
|
||
namespace MarcelStrahl\PriceCalculator\Helpers\Entity; | ||
|
||
use MarcelStrahl\PriceCalculator\Helpers\Types\PercentInterface; | ||
use MarcelStrahl\PriceCalculator\Helpers\Types\DiscountInterface; | ||
use MarcelStrahl\PriceCalculator\Helpers\Types\NumberInterface; | ||
use MarcelStrahl\PriceCalculator\Helpers\Types\PercentInterface; | ||
|
||
/** | ||
* Class Discount | ||
* @author Marcel Strahl <[email protected]> | ||
* @package MarcelStrahl\PriceCalculator\Helpers\Entity | ||
*/ | ||
class Discount implements DiscountInterface, PercentInterface, NumberInterface | ||
class Discount implements DiscountInterface, PercentInterface | ||
{ | ||
/** | ||
* @var float | ||
*/ | ||
private $percent = 0.0; | ||
private $percent = .0; | ||
|
||
/** | ||
* @param float $percent | ||
|
Oops, something went wrong.