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

CartDiscountAbstract   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getDescription() 0 4 1
A getPriceAfterDiscount() 0 4 1
applyDiscount() 0 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;
13
14
use Money\Money;
15
16
abstract class CartDiscountAbstract implements CartDiscountInterface
17
{
18
    protected $price;
19
20
    protected $currency;
21
    
22
    protected $description;
23
24
    protected $priceAfterDiscount;
25
26 3
    public function __construct(string $description, CartInterface $cart, array $config = [])
27
    {
28 3
        $this->description  = $description;
29 3
        $this->price        = $cart->totalAfterDiscounts();
30 3
        $this->currency     = $cart->getCurrency();
31
32 3
        foreach ($config as $property => $value) {
33 3
            $this->$property = $value;
34
        }
35
        
36 3
        $this->applyDiscount();
37 3
    }
38
39 1
    public function getDescription(): string
40
    {
41 1
        return $this->description;
42
    }
43
44 1
    public function getPriceAfterDiscount(): Money
45
    {
46 1
        return $this->priceAfterDiscount;
47
    }
48
49
    abstract protected function applyDiscount(): void;
50
}
51