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::createInstance()   D
last analyzed

Complexity

Conditions 17
Paths 97

Size

Total Lines 34
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 4.9807
c 0
b 0
f 0
cc 17
eloc 26
nc 97
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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