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   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 50
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A addPayment() 0 5 1
A toArray() 0 10 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