Completed
Push — master ( 3c4917...c12914 )
by Gabriel
03:23
created

Variables::fetchOne()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Waredesk;
4
5
use Waredesk\Mappers\VariableMapper;
6
use Waredesk\Mappers\VariablesMapper;
7
use Waredesk\Models\Variable;
8
9
class Variables extends Controller
10
{
11
    private const ENDPOINT = '/v1-alpha/variables';
12
13 1
    public function create(Variable $variable): Variable
14
    {
15 1
        return $this->doCreate(
16 1
            self::ENDPOINT,
17
            $variable,
18
            function ($response) use ($variable) {
19 1
                return (new VariableMapper())->map($variable, $response);
20 1
            }
21
        );
22
    }
23
24 1
    public function update(Variable $variable): Variable
25
    {
26 1
        $this->validateIsNotNewEntity($variable->getId());
27 1
        return $this->doUpdate(
28 1
            self::ENDPOINT."/{$variable->getId()}",
29
            $variable,
30
            function ($response) use ($variable) {
31 1
                return (new VariableMapper())->map($variable, $response);
32 1
            }
33
        );
34
    }
35
36 1
    public function delete(Variable $variable): bool
37
    {
38 1
        $this->validateIsNotNewEntity($variable->getId());
39 1
        return $this->doDelete(self::ENDPOINT."/{$variable->getId()}");
40
    }
41
42
    /**
43
     * @return Collections\Variables|Variable[]
44
     */
45 1
    public function fetch(): Collections\Variables
46
    {
47 1
        return $this->doFetch(
48 1
            self::ENDPOINT,
49
            function ($response) {
50 1
                return (new VariablesMapper())->map(new Collections\Variables(), $response);
51 1
            }
52
        );
53
    }
54
55 2
    public function fetchOne(string $orderBy = null, string $order = self::ORDER_BY_ASC): ? Variable
56
    {
57 2
        return $this->doFetchOne(
58 2
            self::ENDPOINT,
59
            $orderBy,
60
            $order,
61 2
            function ($response) {
62 2
                return (new VariablesMapper())->map(new Collections\Variables(), $response);
63 2
            }
64
        );
65
    }
66
}
67