Passed
Branch master (168fd2)
by Dariusz
06:34
created

TotalPriceThresholdDiscount   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyDiscount() 0 8 2
A getTreshold() 0 6 1
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the Plane\Shop package.
5
 *
6
 * (c) Dariusz Korsak <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Plane\Shop\Discount;
13
14
use Money\Money;
15
use Money\Currency;
16
use Money\Currencies\ISOCurrencies;
17
use Money\Parser\DecimalMoneyParser;
18
use Plane\Shop\CartDiscountAbstract;
19
20
class TotalPriceThresholdDiscount extends CartDiscountAbstract
21
{
22
    protected $treshold;
23
    
24
    protected $discount;
25
26 3
    protected function applyDiscount(): void
27
    {
28 3
        $this->priceAfterDiscount = $this->price;
29
        
30 3
        if ($this->price->greaterThanOrEqual($this->getTreshold($this->currency))) {
31 2
            $this->priceAfterDiscount = $this->price->subtract($this->price->multiply($this->discount));
32
        }
33 3
    }
34
35 3
    private function getTreshold(string $currency): Money
36
    {
37 3
        $moneyParser = new DecimalMoneyParser(new ISOCurrencies());
38
        
39 3
        return $moneyParser->parse((string) $this->treshold, new Currency($currency));
40
    }
41
}
42