PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
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 +103 -21 2.3.20 → 2.1.11 View file →
@@ -1,64 +1,146 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * Column.php
4 + *
5 + * The Column class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
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 + */
5 15 namespace UserAccessManager\Setup\Database;
6 16
17 +/**
18 + * Class Column
19 + *
20 + * @package UserAccessManager\Setup\Database
21 + */
7 22 class Column
8 23 {
24 + /**
25 + * @var string
26 + */
27 + private $name;
28 +
29 + /**
30 + * @var string
31 + */
32 + private $type;
33 +
34 + /**
35 + * @var int|string
36 + */
37 + private $default = null;
38 +
39 + /**
40 + * @var bool
41 + */
42 + private $isNull;
43 +
44 + /**
45 + * @var bool
46 + */
47 + private $isKey;
48 +
49 + /**
50 + * @var bool
51 + */
52 + private $isAutoIncrement;
53 +
54 + /**
55 + * Column constructor.
56 + *
57 + * @param string $name
58 + * @param string $type
59 + * @param bool $isNull
60 + * @param mixed $default
61 + * @param bool $isKey
62 + * @param bool $isAutoIncrement
63 + */
9 64 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
65 + $name,
66 + $type,
67 + $isNull = false,
68 + $default = null,
69 + $isKey = false,
70 + $isAutoIncrement = false
16 71 ) {
72 + $this->name = $name;
73 + $this->type = $type;
74 + $this->isNull = $isNull;
75 + $this->default = $default;
76 + $this->isKey = $isKey;
77 + $this->isAutoIncrement = $isAutoIncrement;
17 78 }
18 79
19 - public function getName(): string
80 + /**
81 + * @return string
82 + */
83 + public function getName()
20 84 {
21 85 return $this->name;
22 86 }
23 87
24 - public function getType(): string
88 + /**
89 + * @return string
90 + */
91 + public function getType()
25 92 {
26 93 return $this->type;
27 94 }
28 95
29 - public function getDefault(): int|string|null
96 + /**
97 + * @return int|string
98 + */
99 + public function getDefault()
30 100 {
31 101 return $this->default;
32 102 }
33 103
34 - public function isNull(): bool
104 + /**
105 + * @return bool
106 + */
107 + public function isNull()
35 108 {
36 109 return $this->isNull;
37 110 }
38 111
39 - public function isKey(): bool
112 + /**
113 + * @return bool
114 + */
115 + public function isKey()
40 116 {
41 117 return $this->isKey;
42 118 }
43 119
44 - public function isAutoIncrement(): bool
120 + /**
121 + * @return bool
122 + */
123 + public function isAutoIncrement()
45 124 {
46 125 return $this->isAutoIncrement;
47 126 }
48 127
49 - public function __toString(): string
128 + /**
129 + * Returns a mysql column string.
130 + *
131 + * @return string
132 + */
133 + public function __toString()
50 134 {
51 135 $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";
136 + $column = "`{$this->name}` {$this->type} {$nullConstraint}";
55 137
56 138 if ($this->default === null && $this->isNull) {
57 139 $column .= ' DEFAULT NULL';
58 140 } elseif ($this->default !== null) {
59 - $defaultValue = is_numeric($this->default) === false ? "'$this->default'" : $this->default;
60 - $column .= " DEFAULT $defaultValue";
141 + $defaultValue = is_numeric($this->default) === false ? "'{$this->default}'" : $this->default;
142 + $column .= " DEFAULT {$defaultValue}";
61 143 }
62 144
63 145 if ($this->isAutoIncrement) {
64 146 $column .= ' AUTO_INCREMENT';