Passed
Push — 4.x ( b027a1...820cf2 )
by Kit Loong
62:09
created

ShowColumn   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 82
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A getNull() 0 3 1
A __construct() 0 14 1
A getField() 0 3 1
A getExtra() 0 3 1
A getKey() 0 3 1
A getDefault() 0 3 1
1
<?php
2
3
namespace KitLoong\MigrationsGenerator\Schema\MySQL;
4
5
use Illuminate\Support\Collection;
6
use stdClass;
7
8
/**
9
 * Class ShowColumn
10
 *
11
 * Entity from MySQL SHOW COLUMNS statement
12
 * @see https://dev.mysql.com/doc/refman/5.7/en/show-columns.html
13
 * @see https://dev.mysql.com/doc/refman/8.0/en/show-columns.html
14
 *
15
 * @package KitLoong\MigrationsGenerator\Schema\MySQL
16
 */
17
class ShowColumn
18
{
19
    /** @var string */
20
    private $field;
21
22
    /** @var string */
23
    private $type;
24
25
    /** @var string */
26
    private $null;
27
28
    /** @var string */
29
    private $key;
30
31
    /** @var string|null */
32
    private $default;
33
34
    /** @var string */
35
    private $extra;
36
37
    public function __construct(stdClass $column)
38
    {
39
        // Convert column property to case insensitive
40
        // Issue https://github.com/kitloong/laravel-migrations-generator/issues/34
41
        $lowerKey = (new Collection($column))->mapWithKeys(function ($item, $key) {
42
            return [strtolower($key) => $item];
43
        });
44
45
        $this->field   = $lowerKey['field'];
46
        $this->type    = $lowerKey['type'];
47
        $this->null    = $lowerKey['null'];
48
        $this->key     = $lowerKey['key'];
49
        $this->default = $lowerKey['default'];
50
        $this->extra   = $lowerKey['extra'];
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getField(): string
57
    {
58
        return $this->field;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getType(): string
65
    {
66
        return $this->type;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getNull(): string
73
    {
74
        return $this->null;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getKey(): string
81
    {
82
        return $this->key;
83
    }
84
85
    /**
86
     * @return string|null
87
     */
88
    public function getDefault(): ?string
89
    {
90
        return $this->default;
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function getExtra(): string
97
    {
98
        return $this->extra;
99
    }
100
}
101