HasAutomaticBalance   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBalanceCHF() 0 4 1
A getFormattedBalance() 0 3 1
A getBalanceEUR() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Traits;
6
7
use Application\Utility;
8
use Doctrine\ORM\Mapping as ORM;
9
use Ecodev\Felix\Api\Scalar\CHFType;
10
use Ecodev\Felix\Api\Scalar\EURType;
11
use GraphQL\Doctrine\Attribute as API;
12
use Money\Money;
13
14
trait HasAutomaticBalance
15
{
16
    #[ORM\Column(type: 'CHF', options: ['default' => 0])]
17
    private Money $balanceCHF;
18
19
    #[ORM\Column(type: 'EUR', options: ['default' => 0])]
20
    private Money $balanceEUR;
21
22
    /**
23
     * Get total balance.
24
     *
25
     * Read only, computed by SQL triggers
26
     */
27 9
    #[API\Field(type: CHFType::class)]
28
    public function getBalanceCHF(): Money
29
    {
30 9
        return $this->balanceCHF;
31
    }
32
33
    /**
34
     * Get total balance.
35
     *
36
     * Read only, computed by SQL triggers
37
     */
38 7
    #[API\Field(type: EURType::class)]
39
    public function getBalanceEUR(): Money
40
    {
41 7
        return $this->balanceEUR;
42
    }
43
44
    /**
45
     * Returns the non-zero balance formatted as string.
46
     */
47 9
    public function getFormattedBalance(): string
48
    {
49 9
        return Utility::getFormattedBalance($this);
50
    }
51
}
52