Failed Conditions
Push — refactor/improve-static-analys... ( ba8000...c6edde )
by Bas
14:06
created

HandlesViews::editView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
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
    public function createView(string $name, array $properties, string $type = 'arangosearch')
17
    {
18
        $view = $properties;
19
        $view['name'] = $name;
20
        $view['type'] = $type;
21
22
        $this->schemaManager->createView($view);
23
    }
24
25
    /**
26
     * @throws ArangoException
27
     */
28
    public function getView(string $name): \stdClass
29
    {
30
        return $this->schemaManager->getView($name);
31
    }
32
33
    public function hasView($view)
34
    {
35
        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
            return $this->schemaManager->hasView($view);
37
        });
38
    }
39
40
    /**
41
     * @throws ArangoException
42
     */
43
    public function getAllViews(): array
44
    {
45
        return $this->schemaManager->getViews();
46
    }
47
48
    /**
49
     * @throws ArangoException
50
     */
51
    public function editView(string $name, array $properties)
52
    {
53
        $this->schemaManager->updateView($name, $properties);
54
    }
55
56
    /**
57
     * @throws ArangoException
58
     */
59
    public function renameView(string $from, string $to)
60
    {
61
        $this->schemaManager->renameView($from, $to);
62
    }
63
64
    /**
65
     * @throws ArangoException
66
     */
67
    public function dropView(string $name)
68
    {
69
        $this->schemaManager->deleteView($name);
70
    }
71
72
    /**
73
     * @throws ArangoException
74
     */
75
    public function dropViewIfExists(string $name): bool
76
    {
77
        if ($this->hasView($name)) {
78
            $this->schemaManager->deleteView($name);
79
        }
80
81
        return true;
82
    }
83
84
    /**
85
     * Drop all views from the schema.
86
     *
87
     * @throws ArangoException
88
     */
89
    public function dropAllViews(): void
90
    {
91
        $views = $this->schemaManager->getViews();
92
93
        foreach ($views as $view) {
94
            $this->schemaManager->deleteView($view->name);
95
        }
96
    }
97
}