Passed
Push — next ( bea07e...b4e6e6 )
by Bas
05:12 queued 01:45
created

HandlesGraphs   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
dl 0
loc 64
ccs 18
cts 20
cp 0.9
rs 10
c 1
b 0
f 1
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createGraph() 0 3 1
A hasGraph() 0 4 1
A getGraph() 0 3 1
A getGraphs() 0 4 1
A dropGraphIfExists() 0 7 2
A dropGraph() 0 3 1
A dropAllGraphs() 0 3 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 HandlesGraphs
10
{
11
    /**
12
     * @param  array<mixed>  $properties
13
     * @throws ArangoException
14
     *
15
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
16
     */
17 8
    public function createGraph(string $name, array $properties = [], bool $waitForSync = false)
18
    {
19 8
        $this->schemaManager->createGraph($name, $properties, $waitForSync);
20
    }
21
22 2
    public function hasGraph(string $name): bool
23
    {
24 2
        return $this->handleExceptionsAsQueryExceptions(function () use ($name) {
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

24
        return $this->/** @scrutinizer ignore-call */ handleExceptionsAsQueryExceptions(function () use ($name) {
Loading history...
25 2
            return $this->schemaManager->hasGraph($name);
26 2
        });
27
    }
28
29
    /**
30
     * @param string $name
31
     * @return mixed[]
32
     * @throws ArangoException
33
     */
34
    public function getGraph(string $name): array
35
    {
36
        return (array) $this->schemaManager->getGraph($name);
37
    }
38
39
    /**
40
     * @return mixed[]
41
     * @throws ArangoException
42
     */
43 8
    public function getGraphs(): array
44
    {
45 8
        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

45
        return $this->/** @scrutinizer ignore-call */ mapResultsToArray(
Loading history...
46 8
            $this->schemaManager->getGraphs(),
47 8
        );
48
    }
49
50
    /**
51
     * @throws ArangoException
52
     */
53 1
    public function dropGraph(string $name)
54
    {
55 1
        $this->schemaManager->deleteGraph($name);
56
    }
57
58
    /**
59
     * @throws ArangoException
60
     */
61 2
    public function dropGraphIfExists(string $name): bool
62
    {
63 2
        if ($this->hasGraph($name)) {
64 1
            $this->schemaManager->deleteGraph($name);
65
        }
66
67 2
        return true;
68
    }
69
70 35
    public function dropAllGraphs(): void
71
    {
72 35
        $this->schemaManager->deleteAllGraphs();
73
    }
74
}
75