Failed Conditions
Push — next ( 54e216...c9a2a9 )
by Bas
06:44
created

DatabaseClient::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArangoClient;
6
7
use GuzzleHttp\Exception\GuzzleException;
8
9
class DatabaseClient
10
{
11
    /**
12
     * @var Connector
13
     */
14
    protected Connector $connector;
15
16
    /**
17
     * Documents constructor.
18
     * @param  Connector  $connector
19
     */
20
    public function __construct(Connector $connector)
21
    {
22
        $this->connector = $connector;
23
    }
24
25
    /**
26
     * @return array<mixed>
27
     * @throws GuzzleException|Exceptions\ArangoDbException
28
     */
29
    public function read(): array
30
    {
31
        return (array) $this->connector->request('get', '/_api/database/current');
32
    }
33
34
    /**
35
     * @return array<mixed>
36
     *
37
     * @throws GuzzleException|Exceptions\ArangoDbException
38
     */
39
    public function listDatabases(): array
40
    {
41
        return (array) $this->connector->request('get', '/_api/database');
42
    }
43
44
    /**
45
     * @return array<mixed>
46
     *
47
     * @throws GuzzleException|Exceptions\ArangoDbException
48
     */
49
    public function listMyDatabases(): array
50
    {
51
        return (array) $this->connector->request('get', '/_api/database/user');
52
    }
53
54
    /**
55
     * @param  string  $name
56
     * @param  null  $options
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $options is correct as it would always require null to be passed?
Loading history...
57
     * @param  null  $users
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $users is correct as it would always require null to be passed?
Loading history...
58
     * @return bool
59
     * @throws Exceptions\ArangoDbException
60
     * @throws GuzzleException
61
     */
62
    public function create(string $name, $options = null, $users = null): bool
63
    {
64
        $database = json_encode((object)['name' => $name, 'options' => $options, 'users' => $users]);
65
66
        return (bool) $this->connector->request('post', '/_api/database', ['body' => $database]);
67
    }
68
69
    /**
70
     * @param  string  $name
71
     * @return bool
72
     * @throws Exceptions\ArangoDbException
73
     * @throws GuzzleException
74
     */
75
    public function delete(string $name): bool
76
    {
77
        $uri = '/_api/database/' . $name;
78
79
        return (bool) $this->connector->request('delete', $uri);
80
    }
81
}
82