Tickets::list()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 10
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\Resources;
6
7
use InShore\Bookwhen\Contracts\Resources\TicketsContract;
8
use InShore\Bookwhen\Responses\Tickets\ListResponse;
9
use InShore\Bookwhen\Responses\Tickets\RetrieveResponse;
10
use InShore\Bookwhen\ValueObjects\Transporter\Payload;
11
12
final class Tickets implements TicketsContract
13
{
14
    use Concerns\Transportable;
15
16
    /**
17
     * Returns a list of tickets that belong to the user's organization's event.
18
     *
19
     * @see https://api.bookwhen.com/v2#tag/Ticket/paths/~1tickets/get
20
     */
21 1
    public function list(array $parameters): ListResponse // @todo change
22
    {
23 1
        $payload = Payload::list('tickets', $parameters);
24
25
        /** @var array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>} $result */
26 1
        $result = $this->transporter->requestObject($payload);
27
28 1
        if (!array_key_exists('included', $result)) {
29 1
            return ListResponse::from($result);
30
        } else {
31
            return ListResponse::from($result, $result['included']);
0 ignored issues
show
Unused Code introduced by
The call to InShore\Bookwhen\Respons...ts\ListResponse::from() has too many arguments starting with $result['included']. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            return ListResponse::/** @scrutinizer ignore-call */ from($result, $result['included']);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
32
        }
33
    }
34
35
    /**
36
     * Returns information about a specific ticket.
37
     *
38
     * @see https://api.bookwhen.com/v2#tag/Ticket/paths/~1tickets~1%7Bticket_id%7D/get
39
     */
40 1
    public function retrieve(string $ticketId): RetrieveResponse
41
    {
42 1
        $payload = Payload::retrieve('tickets', $ticketId);
43
44
        /** @var array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null} $result */
45 1
        $result = $this->transporter->requestObject($payload);
46
47 1
        if (!array_key_exists('included', $result)) {
48 1
            return RetrieveResponse::from($result['data']);
49
        } else {
50
            return RetrieveResponse::from($result['data'], $result['included']);
51
        }
52
    }
53
}
54