Passed
Push — master ( f4d366...672a66 )
by Thomas
03:42 queued 01:49
created

MigrationFieldAbstract   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 60
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A parseOptions() 0 16 4
A getName() 0 4 1
A isNullable() 0 4 1
A isUnique() 0 4 1
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Contracts;
4
5
use Webfactor\Laravel\Generators\Traits\CrudColumn;
6
use Webfactor\Laravel\Generators\Traits\CrudField;
7
use Webfactor\Laravel\Generators\Traits\ValidationRule;
8
9
abstract class MigrationFieldAbstract implements MigrationFieldTypeInterface
10
{
11
    use CrudColumn, CrudField, ValidationRule;
12
13
    private $name;
14
15
    private $nullable;
16
17
    private $unique;
18
19
    public function __construct(string $name, array $options = [])
20
    {
21
        $this->name = $name;
22
23
        foreach ($options as $option) {
24
            $this->parseOptions($option);
25
        }
26
    }
27
28
    private function parseOptions(string $param)
29
    {
30
        if ($param == 'nullable') {
31
            return $this->nullable = true;
32
        }
33
34
        if ($param == 'unique') {
35
            return $this->unique = true;
36
        }
37
38
        if (starts_with($param, 'default(')) {
39
            preg_match('/\((.*)\)/', $param, $match);
40
41
            return $this->default = $match[1];
0 ignored issues
show
Bug introduced by
The property default 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...
42
        }
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getName()
49
    {
50
        return $this->name;
51
    }
52
53
    /**
54
     * @return bool
55
     */
56
    public function isNullable()
57
    {
58
        return $this->nullable;
59
    }
60
61
    /**
62
     * @return bool
63
     */
64
    public function isUnique(): bool
65
    {
66
        return $this->unique;
67
    }
68
}
69