core/Group/Console/Command/SqlMigrateCommand.php
<?php namespace Group\Console\Command; use Group\Console\Command as Command;use Group\Common\ArrayToolkit; class SqlMigrateCommand extends Command{ protected $versions = []; protected $dao; public function init()Whitespace found at end of line { Missing class import via use statement (line '16', column '26'). $this->dao = new \Dao(); $this->doSql($this->getInitSql(), false); $versions = $this->doSql($this->getMigrations(), false)->fetchAll(); $this->versions = array_values(ArrayToolkit::column($versions, "version")); $this->ListSql(__ROOT__."app/sql/"); } Function `ListSql` has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Method name "SqlMigrateCommand::ListSql" is not in camel caps format
The method ListSql is not named in camelCase. private function ListSql($sqlDir)Whitespace found at end of line { $files = []; if (is_dir($sqlDir)) { $dir = opendir($sqlDir); while (($file = readdir($dir)) !== false) { $file = explode(".", $file); $fileName = $file[0]; if ($fileName && isset($file[1]) && $file[1] == "php") { $files[substr($fileName, 3)] = $fileName; } } closedir($dir); } sort($files); foreach ($files as $name) { $this->filterLockFile($name); } } private function filterLockFile($file) { $versions = $this->versions; Inline control structures are not allowed if (in_array($file, $versions)) return; $migrateClass = "\\app\\sql\\".$file; $sqlMigrate = new $migrateClass; $sqlMigrate->run(); $sqlArr = $sqlMigrate->getSqlArr(); $this->startMigrate($sqlArr); $this->doSql($this->insertVersion($file), false); } private function startMigrate($sqlArr) { foreach ($sqlArr as $sql) { $this->doSql($sql); } } The method doSql has a boolean flag argument $needOutput, which is a certain sign of a Single Responsibility Principle violation. private function doSql($sql, $needOutput = true)Whitespace found at end of line { Inline control structures are not allowed if ($needOutput) $this->outPut($sql); return $this->dao->querySql($sql, 'default'); } private function getInitSql() {Line exceeds 120 characters; contains 169 characters return "CREATE TABLE IF NOT EXISTS `migration_versions`( `version` VARCHAR(50) NOT NULL COMMENT '版本号' , UNIQUE `version-un` (`version`)) ENGINE = InnoDB;"; } private function insertVersion($version) { return "INSERT INTO `migration_versions` (`version`) VALUES ('{$version}')"; } private function getMigrations() { return "SELECT * FROM `migration_versions`"; }}