Passed
Push — main ( a3d595...383cbf )
by Dylan
02:02
created

Address::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Lifeboat\Models;
4
5
use Lifeboat\Exceptions\ApiException;
6
use Lifeboat\Exceptions\InvalidArgumentException;
7
use Lifeboat\Exceptions\OAuthException;
8
use Lifeboat\Resource\ListResource;
9
10
/**
11
 * Class Address
12
 * @package Lifeboat\Models
13
 *
14
 * @property string $Name
15
 * @property string $Address
16
 * @property string $AddressL2
17
 * @property string $City
18
 * @property string $SubdivisionCode
19
 * @property string $CountryCode
20
 * @property string $PostCode
21
 * @property string $Notes
22
 * @property string $Latitude
23
 * @property string $Longitude
24
 * @property string $Email
25
 * @property string $Tel
26
 * @property string $VATNo
27
 * @property int $isDefault
28
 * @property string $Country
29
 * @property string $Subdivision
30
 * @property int $CustomerID
31
 */
32
class Address extends Model {
33
34
    /**
35
     * @param int $id
36
     * @return Model|null
37
     * @throws ApiException
38
     * @throws OAuthException
39
     * @throws InvalidArgumentException If param $id is less than 1
40
     */
41
    public function retrieve(int $id = -1): ?Model
42
    {
43
        if ($id <= 0) {
44
            throw new InvalidArgumentException("Address::fetch() expects parameter 1 to be a positive integer");
45
        }
46
47
        return $this->curl_for_model('api/addresses/address/' . $id);
48
    }
49
50
    /**
51
     * @return ListResource
52
     */
53
    public function all(): ListResource
54
    {
55
        return new ListResource($this->getClient(), 'api/addresses/all', [], 20);
0 ignored issues
show
Bug introduced by
It seems like $this->getClient() can also be of type null; however, parameter $client of Lifeboat\Resource\ListResource::__construct() does only seem to accept Lifeboat\Connector, maybe add an additional type check? ( Ignorable by Annotation )

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

55
        return new ListResource(/** @scrutinizer ignore-type */ $this->getClient(), 'api/addresses/all', [], 20);
Loading history...
56
    }
57
58
    /**
59
     * @param string $search
60
     * @return ListResource
61
     */
62
    public function search(string $search): ListResource
63
    {
64
        $all = $this->all();
65
        return $all->setParams(['search' => $search]);
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    protected function getSaveURL(): string
72
    {
73
        return 'api/addresses/address/' . $this->ID;
74
    }
75
}
76