Completed
Push — master ( c7c0ed...b4dd43 )
by Ivan
03:12
created

TableRelation   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 66
ccs 0
cts 19
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
1
<?php
2
namespace vakata\database\schema;
3
4
/**
5
 * A table definition
6
 */
7
class TableRelation
8
{
9
    /**
10
     * @var string
11
     */
12
    public $name;
13
    /**
14
     * @var Table
15
     */
16
    public $table;
17
    /**
18
     * @var string[]
19
     */
20
    public $keymap;
21
    /**
22
     * @var bool
23
     */
24
    public $many;
25
    /**
26
     * @var Table|null
27
     */
28
    public $pivot;
29
    /**
30
     * @var string[]
31
     */
32
    public $pivot_keymap;
33
    /**
34
     * @var string|null
35
     */
36
    public $sql;
37
    /**
38
     * @var array|null
39
     */
40
    public $par;
41
42
    /**
43
     * Create a new instance
44
     * @param  string      $name   the name of the relation
45
     * @param  Table       $table  the foreign table definition
46
     * @param  array       $keymap the keymap (local => foreign)
47
     * @param  bool        $many   is it a one to many rows relation, defaults to false
48
     * @param  Table|null  $pivot  the pivot table definition (if exists), defaults to null
49
     * @param  array|null  $keymap the keymap (local => foreign), defaults to null
50
     * @param  string|null $sql    additional where clauses to use, default to null
51
     * @param  array       $par    parameters for the above statement, defaults to null
52
     */
53
    public function __construct(
54
        string $name,
55
        Table $table,
56
        array $keymap,
57
        bool $many = false,
58
        Table $pivot = null,
59
        array $pivot_keymap = null,
60
        string $sql = null,
61
        array $par = null
62
    ) {
63
        $this->name = $name;
64
        $this->table = $table;
65
        $this->keymap = $keymap;
66
        $this->many = $many;
67
        $this->pivot = $pivot;
68
        $this->pivot_keymap = $pivot_keymap;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pivot_keymap can be null. However, the property $pivot_keymap is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
69
        $this->sql = $sql;
70
        $this->par = $par;
71
    }
72
}
73