Passed
Push — master ( 54e3cc...a9003e )
by Dmitry
14:11
created

ProgressivePriceCalculationTrace   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 26
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A toShortString() 0 6 1
A __toString() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hiqdev\php\billing\price;
6
7
use hiqdev\php\units\Quantity;
8
use Money\Money;
9
use Stringable;
10
11
/**
12
 * Class ProgressivePriceCalculationTrace represents a single step in the calculation of a progressive price.
13
 *
14
 * @author Dmytro Naumenko <[email protected]>
15
 */
16
final class ProgressivePriceCalculationTrace implements Stringable
17
{
18
    public function __construct(
19
        public ProgressivePriceThreshold $threshold,
20
        public Quantity $billedUsage,
21
        public Money $charged,
22
    ) {
23
    }
24
25
    public function __toString(): string
26
    {
27
        return sprintf(
28
            "%s%s * %s = %s",
29
            $this->billedUsage->getQuantity(),
30
            $this->billedUsage->getUnit()->getName(),
31
            $this->threshold->getRawPrice(),
32
            number_format($this->charged->getAmount()/100, 2),
33
        );
34
    }
35
36
    public function toShortString(): string
37
    {
38
        return sprintf(
39
            "%s*%s",
40
            $this->billedUsage->getQuantity(),
41
            $this->threshold->getRawPrice(),
42
        );
43
    }
44
}
45