| @@ -11,11 +11,8 @@ | ||
| 11 | 11 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 12 | 12 | * @version SVN: $id$ |
| 13 | 13 | * @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 14 | 14 | */ |
| 15 | - | |
| 16 | -declare(strict_types=1); | |
| 17 | - | |
| 18 | 15 | namespace UserAccessManager\Setup\Database; |
| 19 | 16 | |
| 20 | 17 | /** |
| 21 | 18 | * Class Column |
| @@ -23,59 +20,127 @@ | ||
| 23 | 20 | * @package UserAccessManager\Setup\Database |
| 24 | 21 | */ |
| 25 | 22 | class Column |
| 26 | 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 | + */ | |
| 27 | 64 | 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 | |
| 65 | + $name, | |
| 66 | + $type, | |
| 67 | + $isNull = false, | |
| 68 | + $default = null, | |
| 69 | + $isKey = false, | |
| 70 | + $isAutoIncrement = false | |
| 34 | 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; | |
| 35 | 78 | } |
| 36 | 79 | |
| 37 | - public function getName(): string | |
| 80 | + /** | |
| 81 | + * @return string | |
| 82 | + */ | |
| 83 | + public function getName() | |
| 38 | 84 | { |
| 39 | 85 | return $this->name; |
| 40 | 86 | } |
| 41 | 87 | |
| 42 | - public function getType(): string | |
| 88 | + /** | |
| 89 | + * @return string | |
| 90 | + */ | |
| 91 | + public function getType() | |
| 43 | 92 | { |
| 44 | 93 | return $this->type; |
| 45 | 94 | } |
| 46 | 95 | |
| 47 | - public function getDefault(): int|string|null | |
| 96 | + /** | |
| 97 | + * @return int|string | |
| 98 | + */ | |
| 99 | + public function getDefault() | |
| 48 | 100 | { |
| 49 | 101 | return $this->default; |
| 50 | 102 | } |
| 51 | 103 | |
| 52 | - public function isNull(): bool | |
| 104 | + /** | |
| 105 | + * @return bool | |
| 106 | + */ | |
| 107 | + public function isNull() | |
| 53 | 108 | { |
| 54 | 109 | return $this->isNull; |
| 55 | 110 | } |
| 56 | 111 | |
| 57 | - public function isKey(): bool | |
| 112 | + /** | |
| 113 | + * @return bool | |
| 114 | + */ | |
| 115 | + public function isKey() | |
| 58 | 116 | { |
| 59 | 117 | return $this->isKey; |
| 60 | 118 | } |
| 61 | 119 | |
| 62 | - public function isAutoIncrement(): bool | |
| 120 | + /** | |
| 121 | + * @return bool | |
| 122 | + */ | |
| 123 | + public function isAutoIncrement() | |
| 63 | 124 | { |
| 64 | 125 | return $this->isAutoIncrement; |
| 65 | 126 | } |
| 66 | 127 | |
| 67 | - public function __toString(): string | |
| 128 | + /** | |
| 129 | + * Returns a mysql column string. | |
| 130 | + * | |
| 131 | + * @return string | |
| 132 | + */ | |
| 133 | + public function __toString() | |
| 68 | 134 | { |
| 69 | 135 | $nullConstraint = ($this->isNull) ? 'NULL' : 'NOT NULL'; |
| 70 | - $type = $this->type === 'INT(11)' ? 'INT' : $this->type; | |
| 71 | - $column = "`$this->name` $type $nullConstraint"; | |
| 136 | + $column = "`{$this->name}` {$this->type} {$nullConstraint}"; | |
| 72 | 137 | |
| 73 | 138 | if ($this->default === null && $this->isNull) { |
| 74 | 139 | $column .= ' DEFAULT NULL'; |
| 75 | 140 | } elseif ($this->default !== null) { |
| 76 | - $defaultValue = is_numeric($this->default) === false ? "'$this->default'" : $this->default; | |
| 77 | - $column .= " DEFAULT $defaultValue"; | |
| 141 | + $defaultValue = is_numeric($this->default) === false ? "'{$this->default}'" : $this->default; | |
| 142 | + $column .= " DEFAULT {$defaultValue}"; | |
| 78 | 143 | } |
| 79 | 144 | |
| 80 | 145 | if ($this->isAutoIncrement) { |
| 81 | 146 | $column .= ' AUTO_INCREMENT'; |