ReplaceClause   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 17
c 3
b 0
f 0
dl 0
loc 46
ccs 15
cts 15
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compile() 0 16 1
A __construct() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\Clauses;
6
7
use LaravelFreelancerNL\FluentAQL\Expressions\Expression;
8
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
9
10
class ReplaceClause extends Clause
11
{
12
    /**
13
     * @var array<mixed>|string|object
14
     */
15
    protected array|string|object $document;
16
17
    /**
18
     * @var array<mixed>|string|object
19
     */
20
    protected array|string|object $with;
21
22
    protected string|QueryBuilder|Expression $collection;
23
24
    /**
25
     * @param array<mixed>|string|object  $document
26
     * @param array<mixed>|string|object  $with
27
     */
28 1
    public function __construct(
29
        array|string|object $document,
30
        array|string|object $with,
31
        string|QueryBuilder|Expression $collection
32
    ) {
33 1
        parent::__construct();
34
35 1
        $this->document = $document;
36 1
        $this->with = $with;
37 1
        $this->collection = $collection;
38
    }
39
40 1
    public function compile(QueryBuilder $queryBuilder): string
41
    {
42 1
        $this->document = $queryBuilder->normalizeArgument(
43 1
            $this->document,
44 1
            ['RegisteredVariable', 'Key', 'Object', 'Bind']
45
        );
46
47 1
        $this->with = $queryBuilder->normalizeArgument($this->with, ['Object', 'Bind']);
48
49 1
        $this->collection = $queryBuilder->normalizeArgument($this->collection, ['Collection', 'Bind']);
50 1
        $queryBuilder->registerCollections($this->collection->compile($queryBuilder));
51
52
53 1
        return "REPLACE {$this->document->compile($queryBuilder)} " .
54 1
            "WITH {$this->with->compile($queryBuilder)} " .
55 1
            "IN {$this->collection->compile($queryBuilder)}";
56
    }
57
}
58