Accountant::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Assimtech\Fiat\Twig\Extension;
6
7
use Assimtech\Fiat;
8
use Twig\Extension\AbstractExtension;
9
use Twig\TwigFunction;
10
11
class Accountant extends AbstractExtension
12
{
13
    protected $accountant;
14
15 8
    public function __construct(
16
        Fiat\Accountant $accountant
17
    ) {
18 8
        $this->accountant = $accountant;
19 8
    }
20
21 1
    public function getFunctions(): array
22
    {
23
        return [
24 1
            new TwigFunction('add_money', [$this, 'add']),
25 1
            new TwigFunction('subtract_money', [$this, 'subtract']),
26 1
            new TwigFunction('multiply_money', [$this, 'multiply']),
27 1
            new TwigFunction('divide_money', [$this, 'divide']),
28 1
            new TwigFunction('sum_monies', [$this, 'sum']),
29
        ];
30
    }
31
32
    /**
33
     * $money1 + $money2
34
     */
35 1
    public function add(
36
        Fiat\Money $money1,
37
        Fiat\Money $money2
38
    ): Fiat\Money {
39 1
        return $this->accountant->add($money1, $money2);
40
    }
41
42
    /**
43
     * $money1 - $money2
44
     */
45 1
    public function subtract(
46
        Fiat\Money $money1,
47
        Fiat\Money $money2
48
    ): Fiat\Money {
49 1
        return $this->accountant->subtract($money1, $money2);
50
    }
51
52
    /**
53
     * $money * $fraction
54
     *
55
     * @param float|integer $fraction
56
     */
57 1
    public function multiply(
58
        Fiat\Money $money,
59
        $fraction
60
    ): Fiat\Money {
61 1
        return $this->accountant->multiply($money, $fraction);
62
    }
63
64
    /**
65
     * $money / $fraction
66
     *
67
     * @param float|integer $fraction
68
     */
69 1
    public function divide(
70
        Fiat\Money $money,
71
        $fraction
72
    ): Fiat\Money {
73 1
        return $this->accountant->divide($money, $fraction);
74
    }
75
76
    /**
77
     * @param array<Fiat\Money> $monies
78
     */
79 1
    public function sum(
80
        array $monies
81
    ): ?Fiat\Money {
82 1
        return $this->accountant->sum($monies);
83
    }
84
85 1
    public function getName(): string
86
    {
87 1
        return 'assimtech_fiat_accountant';
88
    }
89
}
90