FixDiscountStrategy::make()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Cart\DiscountStrategy;
5
6
use Cart\Contracts\DiscountContract;
7
8
class FixDiscountStrategy implements DiscountContract
9
{
10
    /**
11
     * @var int
12
     */
13
    protected $sign;
14
15 3
    public function __construct(int $sign)
16
    {
17 3
        $this->sign = $sign;
18 3
    }
19
20
    /**
21
     * Make Discount
22
     *
23
     * @param int $basePrice
24
     * @return float
25
     */
26 2
    public function make(int $basePrice): float
27
    {
28 2
        $price = $basePrice - $this->sign;
29 2
        if ($price < 0) {
30 2
            $price =  0 ;
31
        }
32 2
        return $price;
33
    }
34
}