Purchases::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Resova\Endpoints\Baskets;
4
5
use Resova\Client;
6
use Resova\Models\PurchaseRequest;
7
8
class Purchases extends Client
9
{
10
    /**
11
     * Create a basket purchase
12
     * Creates a new basket purchase object
13
     *
14
     * @param PurchaseRequest $purchase
15
     *
16
     * @return $this
17
     */
18
    public function create(PurchaseRequest $purchase): self
19
    {
20
        $purchase->setRequired([
21
            'gift_voucher_id',
22
        ]);
23
24
        // Set HTTP params
25
        $this->type     = 'post';
26
        $this->endpoint = '/baskets/' . $this->basket_id . '/purchases';
0 ignored issues
show
Bug introduced by
Are you sure $this->basket_id of type boolean|object can be used in concatenation? ( Ignorable by Annotation )

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

26
        $this->endpoint = '/baskets/' . /** @scrutinizer ignore-type */ $this->basket_id . '/purchases';
Loading history...
Bug Best Practice introduced by
The property basket_id does not exist on Resova\Endpoints\Baskets\Purchases. Since you implemented __get, consider adding a @property annotation.
Loading history...
27
        $this->params   = $purchase;
28
29
        return $this;
30
    }
31
32
    /**
33
     * Retrieve a basket purchase
34
     * Retrieves the details of a basket purchase. Provide the unique id for the basket purchase.
35
     *
36
     * @param int $purchase_id The basket purchase id
37
     *
38
     * @return $this
39
     */
40
    public function __invoke(int $purchase_id): self
41
    {
42
        $this->purchase_id = $purchase_id;
0 ignored issues
show
Bug Best Practice introduced by
The property purchase_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
44
        // Set HTTP params
45
        $this->type     = 'get';
46
        $this->endpoint = '/baskets/' . $this->basket_id . '/purchases/' . $purchase_id;
0 ignored issues
show
Bug Best Practice introduced by
The property basket_id does not exist on Resova\Endpoints\Baskets\Purchases. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
Are you sure $this->basket_id of type boolean|object can be used in concatenation? ( Ignorable by Annotation )

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

46
        $this->endpoint = '/baskets/' . /** @scrutinizer ignore-type */ $this->basket_id . '/purchases/' . $purchase_id;
Loading history...
47
48
        return $this;
49
    }
50
51
    /**
52
     * Delete a basket purchase
53
     * Permanently deletes a basket purchase. It cannot be undone.
54
     *
55
     * @return $this
56
     */
57
    public function delete(): self
58
    {
59
        // Set HTTP params
60
        $this->type     = 'delete';
61
        $this->endpoint = '/baskets/' . $this->basket_id . '/purchases/' . $this->purchase_id;
0 ignored issues
show
Bug Best Practice introduced by
The property basket_id does not exist on Resova\Endpoints\Baskets\Purchases. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
Are you sure $this->basket_id of type boolean|object can be used in concatenation? ( Ignorable by Annotation )

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

61
        $this->endpoint = '/baskets/' . /** @scrutinizer ignore-type */ $this->basket_id . '/purchases/' . $this->purchase_id;
Loading history...
62
63
        return $this;
64
    }
65
66
    /**
67
     * Update a basket purchase
68
     * Updates the specified basket purchase by setting the values of the parameters passed.
69
     * Any parameters not provided will be left unchanged.
70
     * This request accepts mostly the same arguments as the basket purchase creation call.
71
     *
72
     * @param PurchaseRequest $purchase
73
     *
74
     * @return $this
75
     */
76
    public function update(PurchaseRequest $purchase): self
77
    {
78
        // Set HTTP params
79
        $this->type     = 'put';
80
        $this->endpoint = '/baskets/' . $this->basket_id . '/purchases/' . $this->purchase_id;
0 ignored issues
show
Bug introduced by
Are you sure $this->basket_id of type boolean|object can be used in concatenation? ( Ignorable by Annotation )

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

80
        $this->endpoint = '/baskets/' . /** @scrutinizer ignore-type */ $this->basket_id . '/purchases/' . $this->purchase_id;
Loading history...
Bug Best Practice introduced by
The property basket_id does not exist on Resova\Endpoints\Baskets\Purchases. Since you implemented __get, consider adding a @property annotation.
Loading history...
81
        $this->params   = $purchase;
82
83
        return $this;
84
    }
85
86
    /**
87
     * List all basket purchases
88
     * Returns a list of your basket purchases.
89
     * The basket purchases are returned sorted by creation date, with the most recent basket purchase appearing first.
90
     *
91
     * @return $this
92
     */
93
    public function all(): self
94
    {
95
        // Set HTTP params
96
        $this->type     = 'get';
97
        $this->endpoint = '/baskets/' . $this->basket_id . '/purchases';
0 ignored issues
show
Bug Best Practice introduced by
The property basket_id does not exist on Resova\Endpoints\Baskets\Purchases. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
Are you sure $this->basket_id of type boolean|object can be used in concatenation? ( Ignorable by Annotation )

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

97
        $this->endpoint = '/baskets/' . /** @scrutinizer ignore-type */ $this->basket_id . '/purchases';
Loading history...
98
99
        return $this;
100
    }
101
}
102