Test Failed
Push — master ( 2e4880...adaadd )
by Mr
02:02
created

Availability::instance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Resova\Endpoints;
4
5
use Resova\Client;
6
use Resova\Interfaces\QueryInterface;
7
use Resova\Models\Instance;
8
use Resova\Models\InstancePricing;
9
use Resova\Models\Pricing;
10
11
/**
12
 * Availability represents the time slots (instances) and spaces
13
 * that are available or occupied on a given Item.
14
 *
15
 * @package Resova\Endpoints
16
 */
17
class Availability extends Client
18
{
19
    /**
20
     * Retrieve daily availability
21
     * Retrieve the instances for items across a date range.
22
     *
23
     * @param string $start_date The start date for the availability range
24
     * @param string $end_date   The end date for the availability range.
25
     * @param array  $item_ids   Limit the availability results by item ids
26
     *
27
     * @return \Resova\Interfaces\QueryInterface
28
     */
29
    public function calendar(string $start_date, string $end_date, array $item_ids = []): QueryInterface
30
    {
31
        // Default parameters
32
        $params = [
33
            'start_date' => $start_date,
34
            'end_date'   => $end_date,
35
        ];
36
37
        // Optional: Limit the availability results by item ids
38
        if (!empty($item_ids)) {
39
            $params['item_ids'] = implode(',', $item_ids);
40
        }
41
42
        // Set HTTP params
43
        $this->type     = 'get';
44
        $this->endpoint = '/availability/calendar' . '?' . http_build_query($params);
45
        $this->response = \Resova\Models\Availability::class;
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
46
47
        return $this;
48
    }
49
50
    /**
51
     * Retrieve an instance
52
     * Retrieve the details of a specific instance.
53
     *
54
     * @param string $instance_id The Instance Id
55
     *
56
     * @return \Resova\Interfaces\QueryInterface
57
     */
58
    public function instance(string $instance_id): QueryInterface
59
    {
60
        // Set HTTP params
61
        $this->type     = 'get';
62
        $this->endpoint = '/availability/instance/' . $instance_id;
63
        $this->response = Instance::class;
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
64
65
        return $this;
66
    }
67
68
    /**
69
     * Retrieve instance pricing
70
     * Retrieve the pricing for an instance for the quantities passed.
71
     *
72
     * @param string                 $instance_id
73
     * @param \Resova\Models\Pricing $pricing
74
     *
75
     * @return \Resova\Interfaces\QueryInterface
76
     */
77
    public function instancePricing(string $instance_id, Pricing $pricing): QueryInterface
78
    {
79
        $pricing->setRequired([
80
            'quantities'
81
        ]);
82
83
        // Set HTTP params
84
        $this->type     = 'post';
85
        $this->endpoint = '/availability/instance/' . $instance_id . '/pricing';
86
        $this->params   = $pricing;
87
        $this->response = InstancePricing::class;
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
88
89
        return $this;
90
    }
91
92
}
93