Passed
Push — master ( ed94ae...15a67e )
by Ludwig
02:43
created

AgendaEndpoint   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 4 1
A getAll() 0 3 1
A delete() 0 3 1
A create() 0 10 2
A get() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of datamolino client.
5
 *
6
 * (c) 2018 cwd.at GmbH <[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
declare(strict_types=1);
13
14
namespace Cwd\Datamolino\Endpoints;
15
16
use Cwd\Datamolino\Model\Agenda;
17
18
class AgendaEndpoint extends AbstractEndpoint
19
{
20
    /**
21
     * @return Agenda[]
22
     *
23
     * @throws \Http\Client\Exception
24
     */
25
    public function getAll()
26
    {
27
        return $this->getClient()->call(null, null, 'agendas', Agenda::class, true, 'GET');
28
    }
29
30
    /**
31
     * @param int $id
32
     *
33
     * @return Agenda
34
     *
35
     * @throws \Http\Client\Exception
36
     */
37
    public function get(int $id): Agenda
38
    {
39
        return $this->getClient()->call(null, $id, 'agendas', Agenda::class, false, 'GET');
40
    }
41
42
    /**
43
     * @param Agenda $agenda
44
     * @param bool   $lazyLoad if false the agenda object only holds the ID
45
     *
46
     * @return Agenda
47
     *
48
     * @throws \Http\Client\Exception
49
     */
50
    public function create(Agenda $agenda, $lazyLoad = false): Agenda
51
    {
52
        $payload = $this->getClient()->getSerializer()->serialize(['agendas' => [$agenda]], 'json');
53
        $agenda = $this->getClient()->call($payload, null, 'agendas', Agenda::class, false, 'POST');
54
55
        if ($lazyLoad) {
56
            return $this->get($agenda->getId());
57
        }
58
59
        return $agenda;
60
    }
61
62
    /**
63
     * @param Agenda $agenda
64
     *
65
     * @return void|
66
     *
67
     * @throws \Http\Client\Exception
68
     */
69
    public function update(Agenda $agenda)
70
    {
71
        $payload = $this->getClient()->getSerializer()->serialize(['agendas' => [$agenda]], 'json');
72
        $this->getClient()->call($payload, $agenda->getId(), 'agendas', null, false, 'PUT');
73
    }
74
75
    /**
76
     * @param Agenda $agenda
77
     *
78
     * @return mixed
79
     *
80
     * @throws \Http\Client\Exception
81
     */
82
    public function delete(int $id): void
83
    {
84
        $this->getClient()->call(null, $id, 'agendas', null, false, 'DELETE');
85
    }
86
}
87