Passed
Branch next (ee2197)
by Bas
02:37
created

HasDocumentFunctions   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 117
ccs 29
cts 29
cp 1
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A unset() 0 13 2
A parseIdentifier() 0 3 1
A matches() 0 12 1
A keepAttributes() 0 13 2
A attributes() 0 9 1
A merge() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\AQL;
6
7
use LaravelFreelancerNL\FluentAQL\Expressions\Expression;
8
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression;
9
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
10
11
/**
12
 * Geo AQL functions.
13
 *
14
 * @see https://www.arangodb.com/docs/stable/aql/functions-geo.html
15
 */
16
trait HasDocumentFunctions
17
{
18
    /**
19
     * Return the top-level attribute keys of the document as an array.
20
     *
21
     * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#attributes
22
     *
23
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
24
     */
25 1
    public function attributes(
26
        string|object $document,
27
        bool|object $removeInternal = false,
28
        bool|object $sort = false
29
    ): FunctionExpression {
30 1
        return new FunctionExpression('ATTRIBUTES', [
31 1
            'document' => $document,
32 1
            'removeInternal' => $removeInternal,
33 1
            'sort' => $sort,
34
        ]);
35
    }
36
37
    /**
38
     * Keep only the defined attributes of the document.
39
     * All other attributes will be removed from the result.
40
     *
41
     * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#keep
42
     *
43
     * @param string|array<mixed>|object  $document
44
     * @param string|array<mixed>|object $attributes
45
     */
46 2
    public function keepAttributes(
47
        string|array|object $document,
48
        string|array|object $attributes
49
    ): FunctionExpression {
50 2
        if (! is_array($attributes)) {
0 ignored issues
show
introduced by
The condition is_array($attributes) is always true.
Loading history...
51 1
            $attributes = [$attributes];
52
        }
53
54 2
        $arguments = [
55 2
            "document" => $document,
56 2
            "attributes" => $attributes,
57
        ];
58 2
        return new FunctionExpression('KEEP', $arguments);
59
    }
60
61
    /**
62
     * Compare the given document against each example document provided.
63
     *
64
     * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#matches
65
     *
66
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
67
     *
68
     * @param array<mixed>|object $document
69
     * @param array<mixed>|object $examples
70
     * @param bool|QueryBuilder|Expression $returnIndex
71
     * @return FunctionExpression
72
     */
73 1
    public function matches(
74
        array|object $document,
75
        array|object $examples,
76
        bool|QueryBuilder|Expression $returnIndex = false
77
    ): FunctionExpression {
78 1
        $arguments = [
79 1
            "document" => $document,
80 1
            "examples" => $examples,
81 1
            "returnIndex" => $returnIndex,
82
        ];
83
84 1
        return new FunctionExpression('MATCHES', $arguments);
85
    }
86
87
    /**
88
     * Calculate the distance between two coordinates with the Haversine formula.
89
     *
90
     * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#merge
91
     *
92
     * @param  array<mixed>  $documents
93
     * @return FunctionExpression
94
     */
95 2
    public function merge(array ...$documents): FunctionExpression
96
    {
97 2
        return new FunctionExpression('MERGE', $documents);
98
    }
99
100
    /**
101
     * Compare the given document against each example document provided.
102
     *
103
     * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#parse_identifier
104
     *
105
     * @param string|object $documentHandle
106
     * @return FunctionExpression
107
     */
108 1
    public function parseIdentifier(mixed $documentHandle): FunctionExpression
109
    {
110 1
        return new FunctionExpression('PARSE_IDENTIFIER', [$documentHandle]);
111
    }
112
113
    /**
114
     * Remove attributes from document.
115
     *
116
     * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#unset
117
     *
118
     * @param string|array<mixed>|object $attributes
119
     */
120 2
    public function unset(
121
        string|object $document,
122
        string|array|object $attributes
123
    ): FunctionExpression {
124 2
        if (! is_array($attributes)) {
0 ignored issues
show
introduced by
The condition is_array($attributes) is always true.
Loading history...
125 1
            $attributes = [$attributes];
126
        }
127
128 2
        $arguments = [
129 2
            "document" => $document,
130 2
            "attributes" => $attributes,
131
        ];
132 2
        return new FunctionExpression('UNSET', $arguments);
133
    }
134
}
135