HandlesAnalyzers   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 93
rs 10
c 1
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A createAnalyzer() 0 10 1
A replaceAnalyzer() 0 10 1
A hasAnalyzer() 0 4 1
A dropAnalyzer() 0 3 1
A getAnalyzer() 0 3 1
A dropAllAnalyzers() 0 3 1
A dropAnalyzerIfExists() 0 7 2
A getAnalyzers() 0 4 1
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
     * @param  array<string>  $features
14
     *
15
     * @throws ArangoException
16
     */
17
    public function createAnalyzer(string $name, string $type, array $properties = null, array $features = null)
18
    {
19
        $analyzer = array_filter([
20
            'name' => $name,
21
            'type' => $type,
22
            'properties' => $properties,
23
            'features' => $features,
24
        ]);
25
26
        $this->schemaManager->createAnalyzer($analyzer);
27
    }
28
29
    /**
30
     * @param  array<mixed>  $properties
31
     * @param  array<string>  $features
32
     *
33
     * @throws ArangoException
34
     */
35
    public function replaceAnalyzer(string $name, string $type, array $properties = null, array $features = null)
36
    {
37
        $analyzer = array_filter([
38
            'name' => $name,
39
            'type' => $type,
40
            'properties' => $properties,
41
            'features' => $features,
42
        ]);
43
44
        $this->schemaManager->replaceAnalyzer($name, $analyzer);
45
    }
46
47
    /**
48
     * @param string $name
49
     * @return mixed[]
50
     * @throws ArangoException
51
     */
52
    public function getAnalyzer(string $name): array
53
    {
54
        return (array) $this->schemaManager->getAnalyzer($name);
55
    }
56
57
    public function hasAnalyzer(string $analyzer): bool
58
    {
59
        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

59
        return $this->/** @scrutinizer ignore-call */ handleExceptionsAsQueryExceptions(function () use ($analyzer) {
Loading history...
60
            return $this->schemaManager->hasAnalyzer($analyzer);
61
        });
62
    }
63
64
    /**
65
     * @throws ArangoException
66
     */
67
    public function getAnalyzers(): array
68
    {
69
        return $this->mapResultsToArray(
0 ignored issues
show
Bug introduced by
It seems like mapResultsToArray() 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

69
        return $this->/** @scrutinizer ignore-call */ mapResultsToArray(
Loading history...
70
            $this->schemaManager->getAnalyzers(),
71
        );
72
    }
73
74
    /**
75
     * @throws ArangoException
76
     */
77
    public function dropAnalyzer(string $name)
78
    {
79
        $this->schemaManager->deleteAnalyzer($name);
80
    }
81
82
    /**
83
     * @throws ArangoException
84
     */
85
    public function dropAnalyzerIfExists(string $name): bool
86
    {
87
        if ($this->hasAnalyzer($name)) {
88
            $this->schemaManager->deleteAnalyzer($name);
89
        }
90
91
        return true;
92
    }
93
94
    /**
95
     * Drop all custom analyzers from the schema.
96
     *
97
     * @throws ArangoException
98
     */
99
    public function dropAllAnalyzers(): void
100
    {
101
        $this->schemaManager->deleteAllAnalyzers();
102
    }
103
}
104