From c85fdbd33f33185d13220c841228d66df322d7cb Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 30 Nov 2015 22:11:31 +0100 Subject: [PATCH] CS Cleanup --- src/CakeAdapter.php | 10 +++++----- src/CakeManager.php | 7 ++++--- src/Shell/Task/MigrationSnapshotTask.php | 18 +++++++++--------- src/Shell/Task/MigrationTask.php | 4 ++-- src/Shell/Task/SimpleMigrationTask.php | 10 ++++++---- src/Template/Bake/config/skeleton.ctp | 2 +- src/Util/ColumnParser.php | 14 +++++++------- src/View/Helper/MigrationHelper.php | 8 ++++---- .../TestCase/Shell/Task/MigrationTaskTest.php | 5 +++-- 9 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/CakeAdapter.php b/src/CakeAdapter.php index 294369c3..56f9c173 100644 --- a/src/CakeAdapter.php +++ b/src/CakeAdapter.php @@ -352,7 +352,7 @@ public function fetchAll($sql) */ public function insert(Table $table, $row) { - return $this->adapter->insert($table, $row); + $this->adapter->insert($table, $row); } /** @@ -516,7 +516,7 @@ public function hasIndex($tableName, $columns) */ public function hasIndexByName($tableName, $indexName) { - return $this->adapter->hasIndexByName($tableName, $columns); + return $this->adapter->hasIndexByName($tableName, $indexName); } /** @@ -558,9 +558,9 @@ public function dropIndexByName($tableName, $indexName) /** * Checks to see if a foreign key exists. * - * @param string $tableName - * @param string[] $columns Column(s) - * @param string $constraint Constraint name + * @param string $tableName + * @param string[] $columns Column(s) + * @param string|null $constraint Constraint name * @return bool */ public function hasForeignKey($tableName, $columns, $constraint = null) diff --git a/src/CakeManager.php b/src/CakeManager.php index 16e5bae9..502a8648 100644 --- a/src/CakeManager.php +++ b/src/CakeManager.php @@ -95,7 +95,7 @@ public function migrateToDateTime($environment, \DateTime $dateTime) $this->getOutput()->writeln( 'Migrating to version ' . $versionToMigrate ); - return $this->migrate($environment, $versionToMigrate); + $this->migrate($environment, $versionToMigrate); } /** @@ -116,7 +116,8 @@ public function rollbackToDateTime($environment, \DateTime $dateTime) if ($dateString < end($versions)) { $this->getOutput()->writeln('Rolling back all migrations'); - return $this->rollback($environment, 0); + $this->rollback($environment, 0); + return; } foreach ($versions as $index => $version) { @@ -128,7 +129,7 @@ public function rollbackToDateTime($environment, \DateTime $dateTime) $versionToRollback = $versions[$index]; $this->getOutput()->writeln('Rolling back to version ' . $versionToRollback); - return $this->rollback($environment, $versionToRollback); + $this->rollback($environment, $versionToRollback); } /** diff --git a/src/Shell/Task/MigrationSnapshotTask.php b/src/Shell/Task/MigrationSnapshotTask.php index a9cc2f34..86d39690 100644 --- a/src/Shell/Task/MigrationSnapshotTask.php +++ b/src/Shell/Task/MigrationSnapshotTask.php @@ -176,12 +176,12 @@ public function getCollection($connection) * To check if a Table Model is to be added in the migration file * * @param string $tableName Table name in underscore case. - * @param string $pluginName Plugin name if exists. - * @return bool true if the model is to be added. + * @param string|null $pluginName Plugin name if exists. + * @return bool True if the model is to be added. */ public function tableToAdd($tableName, $pluginName = null) { - if (is_null($pluginName)) { + if ($pluginName === null) { return true; } @@ -196,13 +196,13 @@ public function tableToAdd($tableName, $pluginName = null) /** * Gets list Tables Names * - * @param string $pluginName Plugin name if exists. + * @param string|null $pluginName Plugin name if exists. * @return array */ public function getTableNames($pluginName = null) { - if (!is_null($pluginName) && !Plugin::loaded($pluginName)) { - return false; + if ($pluginName !== null && !Plugin::loaded($pluginName)) { + return []; } $list = []; $tables = $this->findTables($pluginName); @@ -241,14 +241,14 @@ public function findTables($pluginName = null) * fetch TableName From Table Object * * @param string $className Name of Table Class. - * @param string $pluginName Plugin name if exists. - * @return string + * @param string|null $pluginName Plugin name if exists. + * @return array */ public function fetchTableName($className, $pluginName = null) { $tables = []; $className = str_replace('Table.php', '', $className); - if (!is_null($pluginName)) { + if ($pluginName !== null) { $className = $pluginName . '.' . $className; } diff --git a/src/Shell/Task/MigrationTask.php b/src/Shell/Task/MigrationTask.php index 5dcb793d..d677e50e 100644 --- a/src/Shell/Task/MigrationTask.php +++ b/src/Shell/Task/MigrationTask.php @@ -60,7 +60,7 @@ public function templateData() $action = $this->detectAction($className); - if ($action === null) { + if (empty($action)) { return [ 'plugin' => $this->plugin, 'pluginPath' => $pluginPath, @@ -119,7 +119,7 @@ public function detectAction($name) $action = 'alter_table'; $table = Inflector::tableize(Inflector::pluralize($matches[2])); } else { - return null; + return []; } return [$action, $table]; diff --git a/src/Shell/Task/SimpleMigrationTask.php b/src/Shell/Task/SimpleMigrationTask.php index 97caf3f3..ac2b63ea 100644 --- a/src/Shell/Task/SimpleMigrationTask.php +++ b/src/Shell/Task/SimpleMigrationTask.php @@ -74,20 +74,22 @@ public function bake($name) * * If the name is invalid, the task will exit * - * @param string $name Name for the generated migration - * @return string name of the migration file + * @param string|null $name Name for the generated migration + * @return string|null Name of the migration file or null if empty */ protected function getMigrationName($name = null) { if (empty($name)) { - return $this->error('Choose a migration name to bake in CamelCase format'); + $this->error('Choose a migration name to bake in CamelCase format'); + return null; } $name = $this->_getName($name); $name = Inflector::camelize($name); if (!preg_match('/^[A-Z]{1}[a-zA-Z0-9]+$/', $name)) { - return $this->error('The className is not correct. The className can only contain "A-Z" and "0-9".'); + $this->error('The className is not correct. The className can only contain "A-Z" and "0-9".'); + return null; } return $name; diff --git a/src/Template/Bake/config/skeleton.ctp b/src/Template/Bake/config/skeleton.ctp index b197a1c7..f00d047c 100644 --- a/src/Template/Bake/config/skeleton.ctp +++ b/src/Template/Bake/config/skeleton.ctp @@ -40,7 +40,7 @@ class <%= $name %> extends AbstractMigration <% foreach ($tables as $table): %> $table = $this->table('<%= $table%>'); <% if ($tableMethod !== 'drop') : %> -<% if ($columnMethod == 'removeColumn'): %> +<% if ($columnMethod === 'removeColumn'): %> <% foreach ($columns['fields'] as $column => $config): %> <%= "\$table->$columnMethod('" . $column . "');"; %> <% endforeach; %> diff --git a/src/Util/ColumnParser.php b/src/Util/ColumnParser.php index ef928a67..405da063 100644 --- a/src/Util/ColumnParser.php +++ b/src/Util/ColumnParser.php @@ -96,7 +96,7 @@ public function parseIndexes($arguments) } $indexUnique = false; - if ($indexType == 'unique') { + if ($indexType === 'unique') { $indexUnique = true; } @@ -197,9 +197,9 @@ public function getType($field, $type) $fieldType = $type; if ($type === null || !in_array($type, $validTypes)) { - if ($type == 'primary') { + if ($type === 'primary') { $fieldType = 'integer'; - } elseif ($field == 'id') { + } elseif ($field === 'id') { $fieldType = 'integer'; } elseif (in_array($field, ['created', 'modified', 'updated'])) { $fieldType = 'datetime'; @@ -220,11 +220,11 @@ public function getType($field, $type) public function getLength($type) { $length = null; - if ($type == 'string') { + if ($type === 'string') { $length = 255; - } elseif ($type == 'integer') { + } elseif ($type === 'integer') { $length = 11; - } elseif ($type == 'biginteger') { + } elseif ($type === 'biginteger') { $length = 20; } @@ -244,7 +244,7 @@ public function getIndexName($field, $indexType, $indexName, $indexUnique) { if (empty($indexName)) { $indexName = strtoupper('BY_' . $field); - if ($indexType == 'primary') { + if ($indexType === 'primary') { $indexName = 'PRIMARY'; } elseif ($indexUnique) { $indexName = strtoupper('UNIQUE_' . $field); diff --git a/src/View/Helper/MigrationHelper.php b/src/View/Helper/MigrationHelper.php index a6f34adb..4664d64d 100644 --- a/src/View/Helper/MigrationHelper.php +++ b/src/View/Helper/MigrationHelper.php @@ -56,11 +56,11 @@ public function __construct(View $View, array $config = []) */ public function tableMethod($action) { - if ($action == 'drop_table') { + if ($action === 'drop_table') { return 'drop'; } - if ($action == 'create_table') { + if ($action === 'create_table') { return 'create'; } @@ -75,7 +75,7 @@ public function tableMethod($action) */ public function indexMethod($action) { - if ($action == 'drop_field') { + if ($action === 'drop_field') { return 'removeIndex'; } @@ -90,7 +90,7 @@ public function indexMethod($action) */ public function columnMethod($action) { - if ($action == 'drop_field') { + if ($action === 'drop_field') { return 'removeColumn'; } diff --git a/tests/TestCase/Shell/Task/MigrationTaskTest.php b/tests/TestCase/Shell/Task/MigrationTaskTest.php index 23fcff1a..329ba278 100644 --- a/tests/TestCase/Shell/Task/MigrationTaskTest.php +++ b/tests/TestCase/Shell/Task/MigrationTaskTest.php @@ -135,6 +135,7 @@ public function testAddPrimaryKeyToExistingTable() /** * @covers Migrations\Shell\Task\MigrationTask::detectAction + * @return void */ public function testDetectAction() { @@ -243,8 +244,8 @@ public function testDetectAction() $this->Task->detectAction('AlterGroupsUsers') ); - $this->assertEquals( - null, + $this->assertSame( + [], $this->Task->detectAction('ReaddColumnsToTable') ); }