Skip to content

Commit

Permalink
Workover of pricecalculator class and test
Browse files Browse the repository at this point in the history
* add scale to the other price calculator methods
* add unit converter facade
  • Loading branch information
Dropelikeit committed Apr 27, 2018
1 parent cbd3492 commit dbcfdcf
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
38 changes: 38 additions & 0 deletions src/Facade/UnitConverter.php
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();
}
}
4 changes: 2 additions & 2 deletions src/PriceCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(VatInterface $vat)
*/
public function addPrice(float $total, float $price): float
{
return (float)bcadd($total, $price);
return (float)bcadd($total, $price,2);
}

/**
Expand All @@ -59,7 +59,7 @@ public function subPrice(float $total, float $price): float
*/
public function mulPrice(float $amount, float $price): float
{
return (float)bcmul($price, $amount);
return (float)bcmul($price, $amount, 2);
}

/**
Expand Down
35 changes: 35 additions & 0 deletions tests/Facade/UnitConverterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace MarcelStrahl\PriceCalculator\Tests\Facade;

use MarcelStrahl\PriceCalculator\UnitConverterInterface;
use PHPUnit\Framework\TestCase;
use MarcelStrahl\PriceCalculator\Facade\UnitConverter as UnitConverterFacade;

/**
* Class UnitConverterTest
* @author Marcel Strahl <[email protected]>
* @package MarcelStrahl\PriceCalculator\Tests\Facade
*/
class UnitConverterTest extends TestCase
{
/**
* @return void
*/
public function testCanInitPriceCalculatorFacade(): void
{
$facade = new UnitConverterFacade();
$this->assertInstanceOf(UnitConverterFacade::class, $facade);
}

/**
* @return void
*/
public function testCanGetUnitConverter(): void
{
$facade = new UnitConverterFacade();
$unitConverter = $facade::getConverter();

$this->assertInstanceOf(UnitConverterInterface::class, $unitConverter);
}
}

0 comments on commit dbcfdcf

Please sign in to comment.