Passed
Push — next ( e3594a...9991ed )
by Bas
10:46 queued 05:19
created

HandlesIndexes::hasIndex()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 4
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 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 HandlesIndexes
10
{
11
    /**
12
     * Determine if the given table has a given index.
13
     *
14
     * @param  string  $table
15
     * @param  string|array<string>  $index
16
     * @param  string|null  $type
17
     * @return bool
18
     */
19 2
    public function hasIndex($table, $index, $type = null, array $options = [])
20
    {
21 2
        $name = $index;
22
23 2
        if ($type === null) {
24 2
            $type = 'persistent';
25
        }
26
27 2
        if (is_array($index)) {
28 1
            $name = $this->createIndexName($type, $index, $options, $table);
0 ignored issues
show
Bug introduced by
It seems like createIndexName() 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

28
            /** @scrutinizer ignore-call */ 
29
            $name = $this->createIndexName($type, $index, $options, $table);
Loading history...
29
        }
30
31 2
        return !!$this->schemaManager->getIndexByName($table, $name);
32
    }
33
34
    /**
35
     * @param string $id
36
     * @return array<mixed>
37
     */
38
    public function getIndex(string $id)
39
    {
40
        return (array) $this->schemaManager->getIndex($id);
41
    }
42
43
    /**
44
     * @param string $table
45
     * @return mixed[]
46
     * @throws ArangoException
47
     */
48 4
    public function getIndexes($table)
49
    {
50 4
        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

50
        return $this->/** @scrutinizer ignore-call */ mapResultsToArray(
Loading history...
51 4
            $this->schemaManager->getIndexes($table),
52 4
        );
53
    }
54
}
55