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.

ColumnFactory   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
D createInstance() 0 34 17
1
<?php
2
3
namespace Dami\Migration\Api;
4
5
class ColumnFactory
6
{
7
    /**
8
     * @param string $method A method name.
9
     * @param array  $params Parameters.
10
     */
11
    public function __construct($method, $params)
12
    {
13
        $this->method = $method;
0 ignored issues
show
Bug introduced by
The property method does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
        $this->params = $params;
0 ignored issues
show
Bug introduced by
The property params does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
    }
16
17
    /**
18
     * Create a new instance.
19
     *
20
     * @return Rentgen\Database\Column
21
     */
22
    public function createInstance()
23
    {
24
        switch ($this->method) {
25
            case 'addBigIntegerColumn':
26
            case 'addBinaryColumn':
27
            case 'addBooleanColumn':
28
            case 'addDateColumn':
29
            case 'addDateTimeColumn':
30
            case 'addDecimalColumn':
31
            case 'addFloatColumn':
32
            case 'addIntegerColumn':
33
            case 'addSmallIntegerColumn':
34
            case 'addStringColumn':
35
            case 'addTextColumn':
36
            case 'addTimeColumn':
37
                $namespace = 'Rentgen\\Database\\Column\\';
38
                $class = $namespace . ltrim($this->method, 'add');
39
                $options = isset($this->params[1]) ? $this->params[1] : array();
40
41
                if ('addStringColumn' === $this->method && !isset($options['limit'])) {
42
                    $options['limit'] = 255;
43
                }
44
                $column = new $class($this->params[0], $options);
45
46
                if (isset($options['comment'])) {
47
                    $column->setDescription($options['comment']);
48
                }
49
                break;
50
            default:
51
                throw new \Exception(sprintf("Unsupported method " . $this->method));
52
        }
53
54
        return $column;
55
    }
56
}
57