Forms   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 33
c 3
b 0
f 0
dl 0
loc 62
rs 10
wmc 22

3 Methods

Rating   Name   Duplication   Size   Complexity  
D getType() 0 35 20
A __construct() 0 3 1
A getFormStub() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: shamaseen
5
 * Date: 09/04/19
6
 * Time: 12:02 م.
7
 */
8
9
namespace Shamaseen\Repository\Generator\Forms;
10
11
use Doctrine\DBAL\Schema\Column;
12
use Illuminate\Support\Facades\Config;
13
14
abstract class Forms
15
{
16
    /**
17
     * @var Column
18
     */
19
    protected $column;
20
21
    public $type = 'text';
22
23
    /**
24
     * Forms constructor.
25
     *
26
     * @param Column $column
27
     */
28
    public function __construct(Column $column)
29
    {
30
        $this->column = $column;
31
    }
32
33
    abstract public function template();
34
35
    public function getType(): string
36
    {
37
        switch ($this->column->getName()) {
38
            case 'email':
39
                return 'email';
40
            case 'password':
41
                return 'password';
42
        }
43
44
        switch ($this->column->getType()) {
45
            case 'integer':
46
            case 'int':
47
            case 'mediumint':
48
            case 'bigint':
49
            case 'decimal':
50
            case 'float':
51
            case 'double':
52
                return 'number';
53
54
            case 'time':
55
                return 'time';
56
57
            case 'date':
58
            case 'datetime':
59
            case 'timestamp':
60
            case 'year':
61
                return 'date';
62
63
            case 'boolean':
64
            case 'bool':
65
            case 'varchat':
66
            case 'enum':
67
            case 'text':
68
            default:
69
                return 'text';
70
        }
71
    }
72
73
    public function getFormStub($type)
74
    {
75
        return file_get_contents(Config::get('repository.stubs_path').'/fields-'.$type.'.stub');
76
    }
77
}
78