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

MigrationFieldAbstract::fillObject()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
ccs 0
cts 16
cp 0
rs 8.8571
cc 5
eloc 10
nc 5
nop 1
crap 30

1 Method

Rating   Name   Duplication   Size   Complexity  
A MigrationFieldAbstract::parseOptions() 0 16 4
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