Passed
Pull Request — master (#12)
by Bas
02:32
created

HasSupportCommands::raw()   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 1 Features 0
Metric Value
cc 3
eloc 6
nc 4
nop 3
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
c 1
b 1
f 0
1
<?php
2
3
namespace LaravelFreelancerNL\FluentAQL\AQL;
4
5
use LaravelFreelancerNL\FluentAQL\Clauses\RawClause;
6
use LaravelFreelancerNL\FluentAQL\Expressions\LiteralExpression;
7
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
8
9
/**
10
 * Trait hasFunctions.
11
 *
12
 * AQL Function API calls.
13
 */
14
trait HasSupportCommands
15
{
16
17
    abstract public function addCommand($command);
18
    abstract public function bind($data, $to = null);
19
    abstract public function registerCollections($collections, $mode = 'write');
20
21
    /**
22
     * @param  string  $aql
23
     * @param  array  $binds
24
     * @param  array  $collections
25
     * @return $this|QueryBuilder
26
     */
27 3
    public function raw(string $aql, $binds = [], $collections = []): self
28
    {
29 3
        foreach ($binds as $key => $value) {
30 1
            $this->bind($value, $key);
31
        }
32
33 3
        foreach ($collections as $mode => $modeCollections) {
34 1
            $this->registerCollections($modeCollections, $mode);
35
        }
36
37 3
        $this->addCommand(new RawClause($aql));
38
39 3
        return $this;
40
    }
41
42
    /**
43
     * @param  string  $aql
44
     * @param  array  $binds
45
     * @param  array  $collections
46
     * @return LiteralExpression
47
     */
48 3
    public function rawExpression(string $aql, $binds = [], $collections = []): LiteralExpression
49
    {
50 3
        foreach ($binds as $key => $value) {
51 1
            $this->bind($value, $key);
52
        }
53
54 3
        foreach ($collections as $mode => $modeCollections) {
55 1
            $this->registerCollections($modeCollections, $mode);
56
        }
57
58 3
        return new LiteralExpression($aql);
59
    }
60
}
61