PaymentService::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Link0\Bunq\Service;
4
5
use Link0\Bunq\Client;
6
use Link0\Bunq\Domain\Alias;
7
use Link0\Bunq\Domain\Id;
8
use Link0\Bunq\Domain\Payment;
9
use Link0\Bunq\Domain\User;
10
use Money\Money;
11
12
final class PaymentService
13
{
14
    /**
15
     * @var Client
16
     */
17
    private $client;
18
19
    /**
20
     * @var Id
21
     */
22
    private $userId;
23
24
    /**
25
     * @var Id
26
     */
27
    private $monetaryAccountId;
28
29
    /**
30
     * @param Client $client
31
     */
32
    public function __construct(Client $client, Id $userId, Id $monetaryAccountId)
33
    {
34
        $this->client = $client;
35
        $this->userId = $userId;
36
        $this->monetaryAccountId = $monetaryAccountId;
37
    }
38
39
    /**
40
     * @return Payment[]
41
     */
42
    public function all(): array
43
    {
44
        return $this->client->get(
45
            'user/' . $this->userId .
46
            '/monetary-account/' . $this->monetaryAccountId .
47
            '/payment'
48
        );
49
    }
50
51
    /**
52
     * This method performs a payment and returns a payment Id
53
     *
54
     * @param Money $money
55
     * @param Alias $alias
56
     * @param string $description
57
     * @param Id[] $attachments,
0 ignored issues
show
Documentation introduced by
There is no parameter named $attachments,. Did you maybe mean $attachments?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
58
     * @param string $merchantReference
59
     * @return Id
60
     */
61
    public function pay(
62
        Money $money,
63
        Alias $alias,
64
        string $description,
65
        array $attachments = [],
66
        string $merchantReference = ''
67
    ): Id {
68
        $data = [
69
            'money' => [
70
                'amount' => $money->getAmount(),
71
                'currency' => $money->getCurrency()->getCode(),
72
            ],
73
            'counterparty_alias' => [
74
                'type' => $alias->type(),
75
                'value' => $alias->value(),
76
                'name' => $alias->name(),
77
            ],
78
            'description' => $description,
79
            'merchant_reference' => $merchantReference,
80
        ];
81
82
        foreach ($attachments as $attachment) {
83
            // Currently an array of Ids
84
            $data['attachment'][]['id'] = $attachment;
85
        }
86
87
        return $this->client->post(
88
            'user/' . $this->userId .
89
            '/monetary-account/' . $this->monetaryAccountId .
90
            '/payment',
91
            $data
92
        )['Id'];
93
    }
94
}
95