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.

AddConstraintCommand::getSql()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3143
cc 3
eloc 15
nc 3
nop 0
1
<?php
2
namespace Rentgen\Schema\Manipulation;
3
4
use Rentgen\Schema\Command;
5
use Rentgen\Database\Constraint\ConstraintInterface;
6
use Rentgen\Database\Constraint\ForeignKey;
7
use Rentgen\Database\Constraint\Unique;
8
use Rentgen\Database\Table;
9
10
class AddConstraintCommand extends Command
11
{
12
    private $constraint;
13
14
    /**
15
     * Set a constraint.
16
     *
17
     * @param ConstraintInterface $constraint A constraint instance.
18
     *
19
     * @return AddConstraintCommand
20
     */
21
    public function setConstraint(ConstraintInterface $constraint)
22
    {
23
        $this->constraint = $constraint;
24
25
        return $this;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getSql()
32
    {
33
        if ($this->constraint instanceof ForeignKey) {
34
            return sprintf('ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s) MATCH SIMPLE ON UPDATE %s ON DELETE %s;'
35
                , $this->constraint->getTable()->getQualifiedName()
36
                , $this->constraint->getName()
37
                , implode(',', $this->constraint->getColumns())
38
                , $this->constraint->getReferencedTable()->getQualifiedName()
39
                , implode(',', $this->constraint->getReferencedColumns())
40
                , $this->constraint->getUpdateAction()
41
                , $this->constraint->getDeleteAction()
42
            );
43
        }
44
        if ($this->constraint instanceof Unique) {
45
            return sprintf('ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s);'
46
                , $this->constraint->getTable()->getQualifiedName()
47
                , $this->constraint->getName()
48
                , implode(',', $this->constraint->getColumns())
49
            );
50
        }
51
    }
52
}
53