Currency::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
namespace NotificationChannels\WhatsApp\Component;
4
5
class Currency extends Component
6
{
7
    protected float $amount;
8
9
    /**
10
     * Currency code as defined in ISO 4217.
11
     */
12
    protected string $code;
13
14 3
    public function __construct(float $amount, string $code = 'EUR')
15
    {
16 3
        $this->amount = $amount;
17 3
        $this->code = $code;
18
    }
19
20 2
    public function toArray(): array
21
    {
22 2
        return [
23 2
            'type' => 'currency',
24 2
            'currency' => [
25 2
                'code' => $this->code,
26 2
                'amount_1000' => (int) ($this->amount * 1000),
27 2
            ],
28 2
        ];
29
    }
30
}
31