UpdateClause::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 3
b 0
f 0
nc 1
nop 3
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 1
rs 10
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 UpdateClause extends Clause
11
{
12
    /**
13
     * @var array<mixed>|object|string $document
14
     */
15
    protected array|object|string $document;
16
17
    /**
18
     * @var array<mixed>|object|string $with
19
     */
20
    protected array|object|string $with;
21
22
    /**
23
     * @var string|QueryBuilder|Expression $collection
24
     */
25
    protected string|QueryBuilder|Expression $collection;
26
27
    /**
28
     * @param array<mixed>|object|string $document
29
     * @param array<mixed>|object|string $with
30
     * @param string|QueryBuilder|Expression $collection
31
     */
32 2
    public function __construct(
33
        array|object|string $document,
34
        array|object|string $with,
35
        string|QueryBuilder|Expression $collection
36
    ) {
37 2
        parent::__construct();
38
39 2
        $this->document = $document;
40 2
        $this->with = $with;
41 2
        $this->collection = $collection;
42
    }
43
44 2
    public function compile(QueryBuilder $queryBuilder): string
45
    {
46 2
        $this->document = $queryBuilder->normalizeArgument(
47 2
            $this->document,
48 2
            ['RegisteredVariable', 'Key', 'Object', 'Bind']
49
        );
50 2
        $this->with = $queryBuilder->normalizeArgument($this->with, ['Object', 'Bind']);
51 2
        $this->collection = $queryBuilder->normalizeArgument($this->collection, ['Collection', 'Bind']);
52 2
        $queryBuilder->registerCollections($this->collection->compile($queryBuilder));
53
54 2
        return "UPDATE {$this->document->compile($queryBuilder)} " .
55 2
            "WITH {$this->with->compile($queryBuilder)} " .
56 2
            "IN {$this->collection->compile($queryBuilder)}";
57
    }
58
}
59