| Conditions | 2 | 
| Paths | 2 | 
| Total Lines | 52 | 
| Code Lines | 20 | 
| 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  | 
            ||
| 40 | public function getCommands(): array  | 
            ||
| 41 |     { | 
            ||
| 42 |         if (!$this->isRequired()) { | 
            ||
| 43 | return [];  | 
            ||
| 44 | }  | 
            ||
| 45 | |||
| 46 | // the following is based on  | 
            ||
| 47 | // https://dba.stackexchange.com/questions/8239/how-to-easily-convert-utf8-tables-to-utf8mb4-in-mysql-5-5#answer-104866  | 
            ||
| 48 | $dbName = $this->conn->getDatabase();  | 
            ||
| 49 | $tableFilter = 'table_schema LIKE "' . $dbName . '"';  | 
            ||
| 50 | $commands = [];  | 
            ||
| 51 | |||
| 52 |         $this->conn->executeQuery('use information_schema;'); | 
            ||
| 53 | |||
| 54 | // database level  | 
            ||
| 55 |         $rows = $this->retrieveCommands(' | 
            ||
| 56 |             SELECT CONCAT("ALTER DATABASE `",table_schema,"` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;") AS _sql  | 
            ||
| 57 | FROM `TABLES`  | 
            ||
| 58 | WHERE ' . $tableFilter . '  | 
            ||
| 59 | GROUP BY table_schema;  | 
            ||
| 60 | ');  | 
            ||
| 61 | $commands = array_merge($commands, $rows);  | 
            ||
| 62 | |||
| 63 | // table level  | 
            ||
| 64 |         $rows = $this->retrieveCommands(' | 
            ||
| 65 |             SELECT CONCAT("ALTER TABLE `",table_schema,"`.`",table_name,"` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") AS _sql   | 
            ||
| 66 | FROM `TABLES`  | 
            ||
| 67 | WHERE ' . $tableFilter . '  | 
            ||
| 68 | GROUP BY table_schema, table_name;  | 
            ||
| 69 | ');  | 
            ||
| 70 | $commands = array_merge($commands, $rows);  | 
            ||
| 71 | |||
| 72 | // column level  | 
            ||
| 73 |         $rows = $this->retrieveCommands(' | 
            ||
| 74 |             SELECT CONCAT("ALTER TABLE `",table_schema,"`.`",table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type,"(",character_maximum_length,") CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci",IF(is_nullable="YES"," NULL"," NOT NULL"),";") AS _sql  | 
            ||
| 75 | FROM `COLUMNS`  | 
            ||
| 76 | WHERE ' . $tableFilter . '  | 
            ||
| 77 | AND data_type IN (\'varchar\', \'char\');  | 
            ||
| 78 | ');  | 
            ||
| 79 | $commands = array_merge($commands, $rows);  | 
            ||
| 80 | |||
| 81 |         $rows = $this->retrieveCommands(' | 
            ||
| 82 |             SELECT CONCAT("ALTER TABLE `",table_schema,"`.`",table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type," CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci",IF(is_nullable="YES"," NULL"," NOT NULL"),";") AS _sql  | 
            ||
| 83 | FROM `COLUMNS`  | 
            ||
| 84 | WHERE ' . $tableFilter . '  | 
            ||
| 85 | AND data_type IN (\'text\', \'tinytext\', \'mediumtext\', \'longtext\');  | 
            ||
| 86 | ');  | 
            ||
| 87 | $commands = array_merge($commands, $rows);  | 
            ||
| 88 | |||
| 89 |         $this->conn->executeQuery('use ' . $dbName . ';'); | 
            ||
| 90 | |||
| 91 | return $commands;  | 
            ||
| 92 | }  | 
            ||
| 105 |