| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 122 | public function __construct(string $prefix) |
||
| 123 | { |
||
| 124 | parent::__construct(); |
||
| 125 | |||
| 126 | $gedcom = $this->createTable($prefix . 'gedcom'); |
||
| 127 | $gedcom->addColumn('gedcom_id', Types::INTEGER, ['autoincrement' => true]); |
||
| 128 | $gedcom->addColumn('gedcom_name', Types::STRING, ['length' => 255]); |
||
| 129 | $gedcom->addColumn('sort_order', Types::INTEGER, ['default' => 0]); |
||
| 130 | $gedcom->setPrimaryKey(['gedcom_id']); |
||
| 131 | $gedcom->addUniqueIndex(['gedcom_name']); |
||
| 132 | $gedcom->addIndex(['sort_order']); |
||
| 133 | |||
| 134 | $gedcom_setting = $this->createTable($prefix . 'gedcom_setting'); |
||
| 135 | $gedcom_setting->addColumn('gedcom_id', Types::INTEGER); |
||
| 136 | $gedcom_setting->addColumn('setting_name', Types::STRING, ['length' => 32]); |
||
| 137 | $gedcom_setting->addColumn('setting_value', Types::STRING, ['length' => 255, 'platformOptions' => self::OPTIONS]); |
||
| 138 | $gedcom_setting->setPrimaryKey(['gedcom_id', 'setting_name']); |
||
| 139 | $gedcom_setting->addForeignKeyConstraint($gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
||
| 140 | |||
| 141 | $site_setting = $this->createTable($prefix . 'site_setting'); |
||
| 142 | $site_setting->addColumn('setting_name', Types::STRING, ['length' => 32]); |
||
| 143 | $site_setting->addColumn('setting_value', Types::STRING, ['length' => 2000, 'platformOptions' => self::OPTIONS]); |
||
| 144 | $site_setting->setPrimaryKey(['setting_name']); |
||
| 145 | |||
| 146 | $user = $this->createTable($prefix . 'user'); |
||
| 147 | $user->addColumn('user_id', Types::INTEGER, ['autoincrement' => true]); |
||
| 148 | $user->addColumn('user_name', Types::STRING, ['length' => 32]); |
||
| 149 | $user->addColumn('real_name', Types::STRING, ['length' => 64]); |
||
| 150 | $user->addColumn('email', Types::STRING, ['length' => 64]); |
||
| 151 | $user->addColumn('password', Types::STRING, ['length' => 128]); |
||
| 152 | $user->setPrimaryKey(['user_id']); |
||
| 153 | $user->addUniqueIndex(['user_name']); |
||
| 154 | $user->addUniqueIndex(['email']); |
||
| 155 | |||
| 156 | $user_gedcom_setting = $this->createTable($prefix . 'user_gedcom_setting'); |
||
| 157 | $user_gedcom_setting->addOption('charset', 'utf8mb4'); |
||
| 158 | $user_gedcom_setting->addOption('collation', 'utf8mb4_bin'); |
||
| 159 | $user_gedcom_setting->addOption('create_options', self::OPTIONS); |
||
| 160 | $user_gedcom_setting->addColumn('user_id', Types::INTEGER); |
||
| 161 | $user_gedcom_setting->addColumn('gedcom_id', Types::INTEGER); |
||
| 162 | $user_gedcom_setting->addColumn('setting_name', Types::STRING, ['length' => 32]); |
||
| 163 | $user_gedcom_setting->addColumn('setting_value', Types::STRING, ['length' => 255]); |
||
| 164 | $user_gedcom_setting->setPrimaryKey(['user_id', 'gedcom_id', 'setting_name']); |
||
| 165 | $user_gedcom_setting->addIndex(['gedcom_id']); |
||
| 166 | $user_gedcom_setting->addForeignKeyConstraint($gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
||
| 167 | $user_gedcom_setting->addForeignKeyConstraint($user, ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
||
| 168 | |||
| 169 | $user_setting = $this->createTable($prefix . 'user_setting'); |
||
| 170 | $user_setting->addColumn('user_id', Types::INTEGER); |
||
| 171 | $user_setting->addColumn('setting_name', Types::STRING, ['length' => 32]); |
||
| 172 | $user_setting->addColumn('setting_value', Types::STRING, ['length' => 255, 'platformOptions' => self::OPTIONS]); |
||
| 173 | $user_setting->setPrimaryKey(['user_id', 'setting_name']); |
||
| 174 | $user_setting->addForeignKeyConstraint($user, ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
||
| 175 | |||
| 176 | $schema_config = new SchemaConfig(); |
||
| 177 | $schema_config->setDefaultTableOptions(['create_options' => self::OPTIONS]); |
||
| 178 | $user = $this->createTable($prefix . 'users'); |
||
| 179 | $user->addOption('charset', 'utf8mb4'); |
||
| 180 | $user->addOption('collation', 'utf8mb4_unicode_bin'); |
||
| 181 | $user->addOption('engine', 'memory'); |
||
| 182 | $user->addColumn('user_id', Types::INTEGER, ['autoincrement' => true]); |
||
| 183 | $user->addColumn('user_name', Types::STRING, ['length' => 32]); |
||
| 184 | $user->addColumn('real_name', Types::STRING, ['length' => 64]); |
||
| 185 | $user->addColumn('email', Types::STRING, ['length' => 64]); |
||
| 186 | $user->addColumn('password', Types::STRING, ['length' => 128]); |
||
| 187 | $user->setPrimaryKey(['user_id']); |
||
| 188 | $user->addUniqueIndex(['user_name']); |
||
| 189 | $user->addUniqueIndex(['email']); |
||
| 190 | } |
||
| 218 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.