Passed
Push — next ( 381d12...e3594a )
by Bas
05:57
created

HandlesViews::getAllViews()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns;
6
7
use ArangoClient\Exceptions\ArangoException;
8
9
trait HandlesViews
10
{
11
    /**
12
     * @param  array<mixed>  $properties
13
     *
14
     * @throws ArangoException
15
     */
16 65
    public function createView(string $name, array $properties, string $type = 'arangosearch')
17
    {
18 65
        $view = $properties;
19 65
        $view['name'] = $name;
20 65
        $view['type'] = $type;
21
22 65
        $this->schemaManager->createView($view);
23
    }
24
25
    /**
26
     * @throws ArangoException
27
     */
28 2
    public function getView(string $name): \stdClass
29
    {
30 2
        return $this->schemaManager->getView($name);
31
    }
32
33 59
    public function hasView($view)
34
    {
35 59
        return $this->handleExceptionsAsQueryExceptions(function () use ($view) {
0 ignored issues
show
Bug introduced by
It seems like handleExceptionsAsQueryExceptions() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

35
        return $this->/** @scrutinizer ignore-call */ handleExceptionsAsQueryExceptions(function () use ($view) {
Loading history...
36 59
            return $this->schemaManager->hasView($view);
37 59
        });
38
    }
39
40
    /**
41
     * @throws ArangoException
42
     */
43 8
    public function getViews(): array
44
    {
45 8
        return $this->schemaManager->getViews();
46
    }
47
48
    /**
49
     * @throws ArangoException
50
     */
51 2
    public function editView(string $name, array $properties)
52
    {
53 2
        $this->schemaManager->updateView($name, $properties);
54
    }
55
56
    /**
57
     * @throws ArangoException
58
     */
59 2
    public function renameView(string $from, string $to)
60
    {
61 2
        $this->schemaManager->renameView($from, $to);
62
    }
63
64
    /**
65
     * @throws ArangoException
66
     */
67 2
    public function dropView(string $name)
68
    {
69 2
        $this->schemaManager->deleteView($name);
70
    }
71
72
    /**
73
     * @throws ArangoException
74
     */
75 59
    public function dropViewIfExists(string $name): bool
76
    {
77 59
        if ($this->hasView($name)) {
78 24
            $this->schemaManager->deleteView($name);
79
        }
80
81 59
        return true;
82
    }
83
84
    /**
85
     * Drop all views from the schema.
86
     *
87
     * @throws ArangoException
88
    */
89 35
    public function dropAllViews(): void
90
    {
91 35
        $this->schemaManager->deleteAllViews();
92
    }
93
}
94