Completed
Push — master ( f177e6...6416fd )
by Thibaud
04:57 queued 02:14
created

OrderRepository::createOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of phraseanet/php-sdk.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhraseanetSDK\Orders;
13
14
use PhraseanetSDK\AbstractRepository;
15
use PhraseanetSDK\Exception\RuntimeException;
16
17
class OrderRepository extends AbstractRepository
18
{
19
20
    public function listOrders($pageIndex = 0, $pageSize = 20)
21
    {
22
        // 't' param is used for cache busting
23
        $parameters = [
24
            'page' => max($pageIndex, 0),
25
            'per_page' => max($pageSize, 1),
26
            'includes' => [ 'elements' ],
27
            't' => time()
28
        ];
29
30
        $response = $this->query('GET', 'v2/orders/', $parameters);
31
32
        if ($response->isEmpty()) {
33
            throw new RuntimeException('Response content is empty');
34
        }
35
36
        if (! $response->hasProperty('data')) {
37
            throw new RuntimeException('Missing \'data\' property in response');
38
        }
39
40
        if (! $response->hasProperty('meta')) {
41
            throw new RuntimeException('Missing \'meta\' property in response');
42
        }
43
44
        $meta = $response->getProperty('meta');
45
46
        return new OrderList($response->getProperty('data'), $meta->pagination);
0 ignored issues
show
Bug introduced by
It seems like $response->getProperty('data') targeting PhraseanetSDK\Http\APIResponse::getProperty() can also be of type null or object<stdClass>; however, PhraseanetSDK\Orders\OrderList::__construct() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
47
    }
48
49
    public function createOrder($usage, array $recordsIds)
50
    {
51
        $parameters = [
52
            'usage' => $usage,
53
            'deadline' => '',
54
            'records' => $recordsIds
55
        ];
56
57
        $response = $this->query('POST', 'v2/orders/', [], [ 'data' => $parameters ], ['Accept' => 'application/json']);
58
59
        return new Order($response->getProperty('data'));
0 ignored issues
show
Bug introduced by
It seems like $response->getProperty('data') targeting PhraseanetSDK\Http\APIResponse::getProperty() can also be of type array<integer,object<stdClass>> or null; however, PhraseanetSDK\Orders\Order::__construct() does only seem to accept object<stdClass>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
60
    }
61
}
62