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

HandlesAnalyzers::createAnalyzer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
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 HandlesAnalyzers
10
{
11
    /**
12
     * @param  array<mixed>  $properties
13
     *
14
     * @throws ArangoException
15
     */
16
    public function createAnalyzer(string $name, array $properties)
17
    {
18
        $analyzer = $properties;
19
        $analyzer['name'] = $name;
20
21
        $this->schemaManager->createAnalyzer($analyzer);
22
    }
23
24
    /**
25
     * @param  array<mixed>  $properties
26
     *
27
     * @throws ArangoException
28
     */
29
    public function replaceAnalyzer(string $name, array $properties)
30
    {
31
        $this->schemaManager->replaceAnalyzer($name, $properties);
32
    }
33
34
    /**
35
     * @throws ArangoException
36
     */
37
    public function getAnalyzer(string $name): \stdClass
38
    {
39
        return $this->schemaManager->getAnalyzer($name);
40
    }
41
42
    public function hasAnalyzer(string $analyzer): bool
43
    {
44
        return $this->handleExceptionsAsQueryExceptions(function () use ($analyzer) {
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

44
        return $this->/** @scrutinizer ignore-call */ handleExceptionsAsQueryExceptions(function () use ($analyzer) {
Loading history...
45
            return $this->schemaManager->hasAnalyzer($analyzer);
46
        });
47
    }
48
49
    /**
50
     * @throws ArangoException
51
     */
52
    public function getAllAnalyzers(): array
53
    {
54
        return $this->schemaManager->getAnalyzers();
55
    }
56
57
    /**
58
     * @throws ArangoException
59
     */
60
    public function dropAnalyzer(string $name)
61
    {
62
        $this->schemaManager->deleteAnalyzer($name);
63
    }
64
65
    /**
66
     * @throws ArangoException
67
     */
68
    public function dropAnalyzerIfExists(string $name): bool
69
    {
70
        if ($this->hasAnalyzer($name)) {
71
            $this->schemaManager->deleteAnalyzer($name);
72
        }
73
74
        return true;
75
    }
76
}