Passed
Push — master ( 3cb518...ba9ea6 )
by Thomas
40s
created

ValidationRule::getField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Schemas;
4
5
class ValidationRule
6
{
7
    private $type;
8
9
    private $field;
10
11
    private $required = true;
12
13
    public function __construct(MigrationField $migrationField)
14
    {
15
        if ($migrationField->isNullable()) {
16
            $this->required = false;
17
        }
18
19
        $this->type = $migrationField->getType();
20
        $this->field = $migrationField->getName();
21
    }
22
23
    public function generateRuleString(): ?string
24
    {
25
        if ($this->isRequired()) {
26
            return 'required';
27
        }
28
29
        return null;
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getField()
36
    {
37
        return $this->field;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getType()
44
    {
45
        return $this->type;
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    public function isRequired()
52
    {
53
        return $this->required;
54
    }
55
}
56