GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Charge::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 1
1
<?php
2
3
namespace CMPayments\PaymentSdk\Entities;
4
5
use CMPayments\PaymentSdk\MoneyConverter;
6
use Money\Money;
7
8
/**
9
 * Class Charge
10
 * @package CMPayments\PaymentSdk\Entities
11
 * @author Jory Geerts <[email protected]>
12
 */
13
class Charge
14
{
15
    /**
16
     * @var Money
17
     */
18
    private $money;
19
20
    /**
21
     * @var Payment[]
22
     */
23
    private $payments;
24
25
    /**
26
     * Charge constructor.
27
     *
28
     * @param Money $money
29
     * @param array|null $payments
30
     */
31 4
    public function __construct(Money $money, array $payments = null)
32
    {
33 4
        $this->money = $money;
34 4
        $this->payments = $payments ? $payments : [];
35 4
    }
36
37
    /**
38
     * @param Payment $payment
39
     * @return Charge
40
     */
41 1
    public function addPayment(Payment $payment)
42
    {
43 1
        $this->payments[] = $payment;
44 1
        return $this;
45
    }
46
47
    /**
48
     * Create an array structure that represents the charge.
49
     *
50
     * @return array
51
     */
52 2
    public function toArray()
53
    {
54
        return [
55 2
            'amount'   => (new MoneyConverter())->toFloat($this->money),
56 2
            'currency' => $this->money->getCurrency(),
57 2
            'payments' => array_map(function (Payment $p) {
58 2
                return $p->toArray();
59 2
            }, $this->payments),
60 2
        ];
61
    }
62
}
63