Skip to content

Commit

Permalink
Merge pull request #162 from cakephp/master-cleanup
Browse files Browse the repository at this point in the history
CS Cleanup
  • Loading branch information
HavokInspiration committed Dec 1, 2015
2 parents f4e0008 + c85fdbd commit 800d4f7
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 37 deletions.
10 changes: 5 additions & 5 deletions src/CakeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/CakeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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) {
Expand All @@ -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);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/Shell/Task/MigrationSnapshotTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Shell/Task/MigrationTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function templateData()

$action = $this->detectAction($className);

if ($action === null) {
if (empty($action)) {
return [
'plugin' => $this->plugin,
'pluginPath' => $pluginPath,
Expand Down Expand Up @@ -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];
Expand Down
10 changes: 6 additions & 4 deletions src/Shell/Task/SimpleMigrationTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Bake/config/skeleton.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -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; %>
Expand Down
14 changes: 7 additions & 7 deletions src/Util/ColumnParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function parseIndexes($arguments)
}

$indexUnique = false;
if ($indexType == 'unique') {
if ($indexType === 'unique') {
$indexUnique = true;
}

Expand Down Expand Up @@ -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';
Expand All @@ -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;
}

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/View/Helper/MigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -75,7 +75,7 @@ public function tableMethod($action)
*/
public function indexMethod($action)
{
if ($action == 'drop_field') {
if ($action === 'drop_field') {
return 'removeIndex';
}

Expand All @@ -90,7 +90,7 @@ public function indexMethod($action)
*/
public function columnMethod($action)
{
if ($action == 'drop_field') {
if ($action === 'drop_field') {
return 'removeColumn';
}

Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase/Shell/Task/MigrationTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function testAddPrimaryKeyToExistingTable()

/**
* @covers Migrations\Shell\Task\MigrationTask::detectAction
* @return void
*/
public function testDetectAction()
{
Expand Down Expand Up @@ -243,8 +244,8 @@ public function testDetectAction()
$this->Task->detectAction('AlterGroupsUsers')
);

$this->assertEquals(
null,
$this->assertSame(
[],
$this->Task->detectAction('ReaddColumnsToTable')
);
}
Expand Down

0 comments on commit 800d4f7

Please sign in to comment.