PluginProbe
User Access Manager / 2.2.2
User Access Manager v2.2.2
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 +95 -12 2.3.182.2.2 View file →
@@ -1,64 +1,147 @@
1 1 <?php
2 +/**
3 + * Column.php
4 + *
5 + * The Column class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
2 15
3 16 declare(strict_types=1);
4 17
5 18 namespace UserAccessManager\Setup\Database;
6 19
20 +/**
21 + * Class Column
22 + *
23 + * @package UserAccessManager\Setup\Database
24 + */
7 25 class Column
8 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 + */
9 66 public function __construct(
10 - private string $name,
11 - private string $type,
12 - private bool $isNull = false,
13 - private mixed $default = null,
14 - private bool $isKey = false,
15 - private bool $isAutoIncrement = false
67 + string $name,
68 + string $type,
69 + $isNull = false,
70 + $default = null,
71 + $isKey = false,
72 + $isAutoIncrement = false
16 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;
17 80 }
18 81
82 + /**
83 + * @return string
84 + */
19 85 public function getName(): string
20 86 {
21 87 return $this->name;
22 88 }
23 89
90 + /**
91 + * @return string
92 + */
24 93 public function getType(): string
25 94 {
26 95 return $this->type;
27 96 }
28 97
29 - public function getDefault(): int|string|null
98 + /**
99 + * @return int|string
100 + */
101 + public function getDefault()
30 102 {
31 103 return $this->default;
32 104 }
33 105
106 + /**
107 + * @return bool
108 + */
34 109 public function isNull(): bool
35 110 {
36 111 return $this->isNull;
37 112 }
38 113
114 + /**
115 + * @return bool
116 + */
39 117 public function isKey(): bool
40 118 {
41 119 return $this->isKey;
42 120 }
43 121
122 + /**
123 + * @return bool
124 + */
44 125 public function isAutoIncrement(): bool
45 126 {
46 127 return $this->isAutoIncrement;
47 128 }
48 129
130 + /**
131 + * Returns a mysql column string.
132 + * @return string
133 + */
49 134 public function __toString(): string
50 135 {
51 136 $nullConstraint = ($this->isNull) ? 'NULL' : 'NOT NULL';
52 - // MySQL reports a declared INT as INT(11); normalise so schema comparison sees no difference.
53 - $type = $this->type === 'INT(11)' ? 'INT' : $this->type;
54 - $column = "`$this->name` $type $nullConstraint";
137 + $column = "`{$this->name}` {$this->type} {$nullConstraint}";
55 138
56 139 if ($this->default === null && $this->isNull) {
57 140 $column .= ' DEFAULT NULL';
58 141 } elseif ($this->default !== null) {
59 - $defaultValue = is_numeric($this->default) === false ? "'$this->default'" : $this->default;
60 - $column .= " DEFAULT $defaultValue";
142 + $defaultValue = is_numeric($this->default) === false ? "'{$this->default}'" : $this->default;
143 + $column .= " DEFAULT {$defaultValue}";
61 144 }
62 145
63 146 if ($this->isAutoIncrement) {
64 147 $column .= ' AUTO_INCREMENT';