AgendaEndpoint   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 69
rs 10
c 0
b 0
f 0

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
    const ENDPOINT = 'agendas';
21
22
    /**
23
     * @return Agenda[]
24
     *
25
     * @throws \Http\Client\Exception
26
     */
27
    public function getAll()
28
    {
29
        return $this->getClient()->call(null, null, self::ENDPOINT, Agenda::class, true, 'GET');
30
    }
31
32
    /**
33
     * @param int $id
34
     *
35
     * @return Agenda
36
     *
37
     * @throws \Http\Client\Exception
38
     */
39
    public function get(int $id): Agenda
40
    {
41
        return $this->getClient()->call(null, $id, self::ENDPOINT, Agenda::class, false, 'GET');
42
    }
43
44
    /**
45
     * @param Agenda $agenda
46
     * @param bool   $lazyLoad if false the agenda object only holds the ID
47
     *
48
     * @return Agenda
49
     *
50
     * @throws \Http\Client\Exception
51
     */
52
    public function create(Agenda $agenda, $lazyLoad = false): Agenda
53
    {
54
        $payload = $this->getClient()->getSerializer()->serialize(['agendas' => [$agenda]], 'json');
55
        $agenda = $this->getClient()->call($payload, null, self::ENDPOINT, Agenda::class, false, 'POST');
56
57
        if ($lazyLoad) {
58
            return $this->get($agenda->getId());
59
        }
60
61
        return $agenda;
62
    }
63
64
    /**
65
     * @param Agenda $agenda
66
     *
67
     * @return void|
68
     *
69
     * @throws \Http\Client\Exception
70
     */
71
    public function update(Agenda $agenda)
72
    {
73
        $payload = $this->getClient()->getSerializer()->serialize(['agendas' => [$agenda]], 'json');
74
        $this->getClient()->call($payload, $agenda->getId(), self::ENDPOINT, null, false, 'PUT');
75
    }
76
77
    /**
78
     * @param Agenda $agenda
79
     *
80
     * @return mixed
81
     *
82
     * @throws \Http\Client\Exception
83
     */
84
    public function delete(int $id): void
85
    {
86
        $this->getClient()->call(null, $id, self::ENDPOINT, null, false, 'DELETE');
87
    }
88
}
89