Passed
Pull Request — master (#2)
by Thomas
03:05
created

ValidationRule   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 51
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A generateRuleString() 0 8 2
A getField() 0 4 1
A getType() 0 4 1
A isRequired() 0 4 1
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