GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PrimaryKey::disableAutoIncrement()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Rentgen\Database\Constraint;
4
5
use Rentgen\Database\Table;
6
7
class PrimaryKey implements ConstraintInterface
8
{
9
    private $columns;
10
    private $isAutoIncrement = true;
11
    private $autoCreateColumn = false;
12
    private $table;
13
14
    /**
15
     * Constructor.
16
     *
17
     * @param array|string $columns Column names.
18
     * @param Table        $table   Table instance.
19
     */
20
    public function __construct($columns = null, Table $table = null)
21
    {
22
        $this->columns = is_string($columns) ? array($columns) : $columns;
23
        if (empty($this->columns)) {
24
            $this->autoCreateColumn = true;
25
        }
26
        $this->table = $table;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getName()
33
    {
34
        return $this->table->getName() . '_pkey';
35
    }
36
37
    // TODO hmmmmmm....
38
    public function getColumns()
39
    {
40
        return empty($this->columns)
41
            ? $this->table->getName() . '_id'
42
            : implode(',', $this->columns);
43
    }
44
45
    /**
46
     * Return true if the primary key is auto create column.
47
     *
48
     * @return bool Auto create column
49
     */
50
    public function isAutoCreateColumn()
51
    {
52
        return $this->autoCreateColumn;
53
    }
54
55
    /**
56
     * Return true if the primary key is multi.
57
     *
58
     * @return bool Multi columns.
59
     */
60
    public function isMulti()
61
    {
62
        return count($this->columns) > 1;
63
    }
64
65
    /**
66
     * Disable auto increment.
67
     *
68
     * @return PrimaryKey Self.
69
     */
70
    public function disableAutoIncrement()
71
    {
72
        $this->isAutoIncrement = false;
73
74
        return $this;
75
    }
76
77
    /**
78
     * Return true if the primary key is auto increment.
79
     *
80
     * @return bool Auto increment.
81
     */
82
    public function isAutoIncrement()
83
    {
84
        return true === $this->isAutoIncrement;
85
    }
86
87
    // TODO Remove this code
88
    public function __toString()
89
    {
90
        return  sprintf('CONSTRAINT %s PRIMARY KEY (%s)'
91
            , $this->getName()
92
            , $this->getColumns()
93
        );
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function getTable()
100
    {
101
        return $this->table;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->table; of type null|Rentgen\Database\Table adds the type Rentgen\Database\Table to the return on line 101 which is incompatible with the return type declared by the interface Rentgen\Database\Constra...aintInterface::getTable of type Rentgen\Database\Constraint\Table.
Loading history...
102
    }
103
104
    /**
105
     * Set table instance.
106
     *
107
     * @param Table $table Table instance.
108
     *
109
     * @return PrimaryKey Self.
110
     */
111
    public function setTable(Table $table)
112
    {
113
        $this->table = $table;
114
115
        return $this;
116
    }
117
}
118