PluginProbe
User Access Manager / 2.2.25
User Access Manager v2.2.25
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Setup/Database/Column.php +77 -10 2.3.172.2.25 View file →
@@ -23,59 +23,126 @@
23 23 * @package UserAccessManager\Setup\Database
24 24 */
25 25 class Column
26 26 {
27 + /**
28 + * @var string
29 + */
30 + private $name;
31 +
32 + /**
33 + * @var string
34 + */
35 + private $type;
36 +
37 + /**
38 + * @var int|string
39 + */
40 + private $default;
41 +
42 + /**
43 + * @var bool
44 + */
45 + private $isNull;
46 +
47 + /**
48 + * @var bool
49 + */
50 + private $isKey;
51 +
52 + /**
53 + * @var bool
54 + */
55 + private $isAutoIncrement;
56 +
57 + /**
58 + * Column constructor.
59 + * @param string $name
60 + * @param string $type
61 + * @param bool $isNull
62 + * @param mixed $default
63 + * @param bool $isKey
64 + * @param bool $isAutoIncrement
65 + */
27 66 public function __construct(
28 - private string $name,
29 - private string $type,
30 - private bool $isNull = false,
31 - private mixed $default = null,
32 - private bool $isKey = false,
33 - private bool $isAutoIncrement = false
67 + string $name,
68 + string $type,
69 + $isNull = false,
70 + $default = null,
71 + $isKey = false,
72 + $isAutoIncrement = false
34 73 ) {
74 + $this->name = $name;
75 + $this->type = $type;
76 + $this->isNull = $isNull;
77 + $this->default = $default;
78 + $this->isKey = $isKey;
79 + $this->isAutoIncrement = $isAutoIncrement;
35 80 }
36 81
82 + /**
83 + * @return string
84 + */
37 85 public function getName(): string
38 86 {
39 87 return $this->name;
40 88 }
41 89
90 + /**
91 + * @return string
92 + */
42 93 public function getType(): string
43 94 {
44 95 return $this->type;
45 96 }
46 97
47 - public function getDefault(): int|string|null
98 + /**
99 + * @return int|string
100 + */
101 + public function getDefault()
48 102 {
49 103 return $this->default;
50 104 }
51 105
106 + /**
107 + * @return bool
108 + */
52 109 public function isNull(): bool
53 110 {
54 111 return $this->isNull;
55 112 }
56 113
114 + /**
115 + * @return bool
116 + */
57 117 public function isKey(): bool
58 118 {
59 119 return $this->isKey;
60 120 }
61 121
122 + /**
123 + * @return bool
124 + */
62 125 public function isAutoIncrement(): bool
63 126 {
64 127 return $this->isAutoIncrement;
65 128 }
66 129
130 + /**
131 + * Returns a mysql column string.
132 + * @return string
133 + */
67 134 public function __toString(): string
68 135 {
69 136 $nullConstraint = ($this->isNull) ? 'NULL' : 'NOT NULL';
70 137 $type = $this->type === 'INT(11)' ? 'INT' : $this->type;
71 - $column = "`$this->name` $type $nullConstraint";
138 + $column = "`{$this->name}` {$type} {$nullConstraint}";
72 139
73 140 if ($this->default === null && $this->isNull) {
74 141 $column .= ' DEFAULT NULL';
75 142 } elseif ($this->default !== null) {
76 - $defaultValue = is_numeric($this->default) === false ? "'$this->default'" : $this->default;
77 - $column .= " DEFAULT $defaultValue";
143 + $defaultValue = is_numeric($this->default) === false ? "'{$this->default}'" : $this->default;
144 + $column .= " DEFAULT {$defaultValue}";
78 145 }
79 146
80 147 if ($this->isAutoIncrement) {
81 148 $column .= ' AUTO_INCREMENT';