Completed
Branch 2.0 (acba87)
by Vermeulen
02:20
created

JoinTrait::createJoin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BfwSql\Queries;
4
5
trait JoinTrait
6
{
7
    /**
8
     * Define the sql prefix to use for each join object
9
     * 
10
     * @return void
11
     */
12
    protected function joinDefinePrefix()
13
    {
14
        $this->queriesParts['join']->setPartPrefix('INNER JOIN');
15
        $this->queriesParts['joinLeft']->setPartPrefix('LEFT JOIN');
16
        $this->queriesParts['joinRight']->setPartPrefix('RIGHT JOIN');
17
    }
18
    
19
    /**
20
     * Add a INNER JOIN to the request
21
     * 
22
     * @return $this
23
     */
24
    public function join(...$args): self
25
    {
26
        array_unshift($args, 'join');
27
        return $this->createJoin(...$args);
1 ignored issue
show
Bug introduced by
The call to BfwSql\Queries\JoinTrait::createJoin() has too few arguments starting with table. ( Ignorable by Annotation )

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

27
        return $this->/** @scrutinizer ignore-call */ createJoin(...$args);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
28
    }
29
    
30
    /**
31
     * Add a LEFT JOIN to the request
32
     * 
33
     * @return $this
34
     */
35
    public function joinLeft(...$args): self
36
    {
37
        array_unshift($args, 'joinLeft');
38
        return $this->createJoin(...$args);
1 ignored issue
show
Bug introduced by
The call to BfwSql\Queries\JoinTrait::createJoin() has too few arguments starting with table. ( Ignorable by Annotation )

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

38
        return $this->/** @scrutinizer ignore-call */ createJoin(...$args);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
39
    }
40
    
41
    /**
42
     * Add a RIGHT JOIN to the request
43
     * 
44
     * @return $this
45
     */
46
    public function joinRight(...$args): self
47
    {
48
        array_unshift($args, 'joinRight');
49
        return $this->createJoin(...$args);
1 ignored issue
show
Bug introduced by
The call to BfwSql\Queries\JoinTrait::createJoin() has too few arguments starting with table. ( Ignorable by Annotation )

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

49
        return $this->/** @scrutinizer ignore-call */ createJoin(...$args);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
50
    }
51
    
52
    /**
53
     * Add a (inner|left|right) join to the request
54
     * 
55
     * @param string       $joinType The name of the property in this class
56
     *  where the join is add
57
     * @param string|array $table    Name of the table concerned by
58
     * the join. Or an array with the table shortcut in key.
59
     * @param string       $on       SQL part "ON" for this join
60
     * @param string|array $columns  Columns from the table joined to add in
61
     *  the SELECT part of the request
62
     * 
63
     * @return $this
64
     */
65
    protected function createJoin(
66
        string $joinType,
67
        $table,
68
        string $on,
69
        $columns = null
70
    ): self {
71
        $this->queriesParts[$joinType]($table, $on, $columns);
72
        
73
        return $this;
74
    }
75
}
76