Join   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 50
ccs 18
cts 18
cp 1
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 7 2
A __construct() 0 9 2
A getParams() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Generic\Clause;
6
7
use InvalidArgumentException;
8
use QB\Generic\IQueryPart;
9
10
class Join implements IJoin
11
{
12
    public string $type;
13
    public ITable|string $table;
14
    public IQueryPart|string|null $on;
0 ignored issues
show
Bug introduced by
The type QB\Generic\Clause\null was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
    /**
17
     * Join constructor.
18
     *
19
     * @param string                 $type
20
     * @param ITable|string          $table
21
     * @param IQueryPart|string|null $on
22
     */
23 27
    public function __construct(string $type, ITable|string $table, IQueryPart|string|null $on)
24
    {
25 27
        if (!in_array($type, IJoin::VALID_TYPES)) {
26 1
            throw new InvalidArgumentException(sprintf('invalid join type: %s', $type));
27
        }
28
29 26
        $this->type  = $type;
30 26
        $this->table = $table;
31 26
        $this->on    = $on;
32 26
    }
33
34
    /**
35
     * @return string
36
     */
37 23
    public function __toString(): string
38
    {
39 23
        if ($this->on) {
40 22
            return sprintf('%s %s ON %s', $this->type, (string)$this->table, (string)$this->on);
41
        }
42
43 1
        return sprintf('%s %s', $this->type, (string)$this->table);
44
    }
45
46
    /**
47
     * @return array
48
     */
49 6
    public function getParams(): array
50
    {
51 6
        $params = [];
52 6
        if ($this->table instanceof ITable) {
53 5
            $params = array_merge($params, $this->table->getParams());
54
        }
55 6
        if ($this->on instanceof IQueryPart) {
56 4
            $params = array_merge($params, $this->on->getParams());
57
        }
58
59 6
        return $params;
60
    }
61
}
62