normalizeDocument()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 16
ccs 11
cts 11
cp 1
crap 3
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\Traits;
6
7
use LaravelFreelancerNL\FluentAQL\Expressions\PredicateExpression;
8
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
9
10
/**
11
 * Trait hasFunctions.
12
 *
13
 * AQL Function API calls.
14
 */
15
trait NormalizesMiscellaneousFunctions
16
{
17 4
    protected function normalizeAssert(QueryBuilder $queryBuilder): void
18
    {
19
        if (
20 4
            ! is_array($this->parameters['predicates'])
21 4
            && ! $this->parameters['predicates'] instanceof PredicateExpression
22
        ) {
23
            $this->parameters['predicates'] = [$this->parameters['predicates']];
0 ignored issues
show
Bug Best Practice introduced by
The property parameters does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
        }
25 4
        $this->parameters['predicates'] = $queryBuilder->normalizePredicates($this->parameters['predicates']);
26 4
        $this->parameters['errorMessage'] = $queryBuilder->normalizeArgument(
27 4
            $this->parameters['errorMessage'],
28 4
            ['Reference', 'Query', 'Bind']
29
        );
30
    }
31
32 1
    protected function normalizeDocument(QueryBuilder $queryBuilder): void
33
    {
34 1
        if ($this->parameters['id']  === null) {
35 1
            $this->parameters['id']  = $this->parameters['collection'];
0 ignored issues
show
Bug Best Practice introduced by
The property parameters does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
36 1
            unset($this->parameters['collection']);
37
        }
38
39 1
        if (isset($this->parameters['collection'])) {
40 1
            $this->parameters['collection'] = $queryBuilder->normalizeArgument(
41 1
                $this->parameters['collection'],
42 1
                ['Collection', 'Id', 'Query', 'Bind']
43
            );
44
        }
45 1
        $this->parameters['id'] = $queryBuilder->normalizeArgument(
46 1
            $this->parameters['id'],
47 1
            ['RegisteredVariable', 'Reference', 'Id', 'Key', 'Query', 'List', 'Bind']
48
        );
49
    }
50
51 1
    protected function normalizeFirstDocument(QueryBuilder $queryBuilder): void
52
    {
53 1
        $this->normalizeAny($queryBuilder);
0 ignored issues
show
Bug introduced by
The method normalizeAny() does not exist on LaravelFreelancerNL\Flue...sMiscellaneousFunctions. Did you maybe mean normalizeWarn()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $this->/** @scrutinizer ignore-call */ 
54
               normalizeAny($queryBuilder);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
    }
55
56 2
    protected function normalizeWarn(QueryBuilder $queryBuilder): void
57
    {
58 2
        $this->normalizeAssert($queryBuilder);
59
    }
60
}
61