Skip to content

Commit

Permalink
Updating code to follow kohana coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
BRMatt committed Jan 31, 2011
1 parent e525631 commit 8fc8ea4
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 81 deletions.
16 changes: 8 additions & 8 deletions classes/controller/minion.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Controller for interacting with minion on the cli
*
* @author Matt Button <matthew@sigswitch.com>
**/
*/
class Controller_Minion extends Controller
{
/**
Expand All @@ -18,7 +18,7 @@ class Controller_Minion extends Controller
*/
public function before()
{
if( ! Kohana::$is_cli)
if ( ! Kohana::$is_cli)
{
throw new Kohana_Exception("Minion can only be ran from the cli");
}
Expand All @@ -27,12 +27,12 @@ public function before()

$options = CLI::options('help', 'task');

if(array_key_exists('help', $options))
if (array_key_exists('help', $options))
{
$this->request->action = 'help';
}

if( ! empty($options['task']))
if ( ! empty($options['task']))
{
$this->_task = $options['task'];
}
Expand All @@ -49,7 +49,7 @@ public function action_help()
$tasks = Minion_Util::compile_task_list(Kohana::list_files('classes/minion/task'));
$view = NULL;

if(empty($this->_task))
if (empty($this->_task))
{
$view = new View('minion/help/list');

Expand All @@ -59,7 +59,7 @@ public function action_help()
{
$class = Minion_Util::convert_task_to_class_name($this->_task);

if( ! class_exists($class))
if ( ! class_exists($class))
{
echo View::factory('minion/help/error')
->set('error', 'Task "'.$task.'" does not exist');
Expand Down Expand Up @@ -88,7 +88,7 @@ public function action_help()
*/
public function action_execute()
{
if(empty($this->_task))
if (empty($this->_task))
{
return $this->action_help();
}
Expand All @@ -108,7 +108,7 @@ public function action_execute()
$config = array();
$options = (array) $task->get_config_options();

if( ! empty($options))
if ( ! empty($options))
{
$options = $task->get_config_options();
$config = call_user_func_array(array('CLI', 'options'), $options);
Expand Down
2 changes: 1 addition & 1 deletion classes/minion/migration/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function get_database_connection()
$config = Kohana::config('minion/migration');
$location = $this->_info['location'];

if(isset($config->location_connection[$location]))
if (isset($config->location_connection[$location]))
{
return $config->location_connection[$location];
}
Expand Down
4 changes: 2 additions & 2 deletions classes/minion/migration/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Minion_Migration_Database extends Database_MySQL {
*/
public static function faux_instance($db_group = NULL, array $config = NULL)
{
if($config === NULL)
if ($config === NULL)
{
if($db_group === NULL)
if ($db_group === NULL)
{
$db_group = Database::$default;
}
Expand Down
24 changes: 12 additions & 12 deletions classes/minion/migration/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* that need to be executed in order to reach a target version
*
* @author Matt Button <matthew@sigswitch.com>
**/
*/
class Minion_Migration_Manager {

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ class Minion_Migration_Manager {
*/
public function __construct(Kohana_Database $db, Model_Minion_Migration $model = NULL)
{
if($model === NULL)
if ($model === NULL)
{
$model = new Model_Minion_Migration($db);
}
Expand Down Expand Up @@ -154,15 +154,15 @@ public function run_migration(array $locations = array(), $versions = array(), $
{
$migrations = $this->_model->fetch_required_migrations($locations, $versions, $default_direction);

foreach($migrations as $path => $location)
foreach ($migrations as $path => $location)
{
$method = $location['direction'] ? 'up' : 'down';

foreach($location['migrations'] as $migration)
foreach ($location['migrations'] as $migration)
{
$filename = Minion_Migration_Util::get_filename_from_migration($migration);

if( ! ($file = Kohana::find_file('migrations', $filename, FALSE)))
if ( ! ($file = Kohana::find_file('migrations', $filename, FALSE)))
{
throw new Kohana_Exception(
'Cannot load migration :migration (:file)',
Expand Down Expand Up @@ -192,7 +192,7 @@ public function run_migration(array $locations = array(), $versions = array(), $
}


if($this->_dry_run)
if ($this->_dry_run)
{
$this->_dry_run_sql[$path][$migration['timestamp']] = $db->reset_query_stack();
}
Expand Down Expand Up @@ -221,26 +221,26 @@ public function sync_migration_files()

$all_migrations = array_merge(array_keys($installed), array_keys($available));

foreach($all_migrations as $migration)
foreach ($all_migrations as $migration)
{
// If this migration has since been deleted
if(isset($installed[$migration]) AND ! isset($available[$migration]))
if (isset($installed[$migration]) AND ! isset($available[$migration]))
{
// We should only delete a record of this migration if it does
// not exist in the "real world"
if($installed[$migration]['applied'] === '0')
if ($installed[$migration]['applied'] === '0')
{
$this->_model->delete_migration($installed[$migration]);
}
}
// If the migration has not yet been installed :D
elseif( ! isset($installed[$migration]) AND isset($available[$migration]))
elseif ( ! isset($installed[$migration]) AND isset($available[$migration]))
{
$this->_model->add_migration($available[$migration]);
}
// Somebody changed the description of the migration, make sure we
// update it in the db as we use this to build the filename!
elseif($installed[$migration]['description'] !== $available[$migration]['description'])
elseif ($installed[$migration]['description'] !== $available[$migration]['description'])
{
$this->_model->update_migration($installed[$migration], $available[$migration]);
}
Expand All @@ -259,7 +259,7 @@ public function sync_migration_files()
protected function _get_db_instance($db_group)
{
// If this isn't a dry run then just use a normal database connection
if( ! $this->_dry_run)
if ( ! $this->_dry_run)
return Database::instance($db_group);

return Minion_Migration_Database::faux_instance($db_group);
Expand Down
10 changes: 5 additions & 5 deletions classes/minion/migration/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Provides a set of utility functions for managing migrations
*
* @author Matt Button <matthew@sigswitch.com>
**/
*/
class Minion_Migration_Util {

/**
Expand All @@ -19,10 +19,10 @@ public static function compile_migrations_from_files(array $files)
{
$migrations = array();

foreach($files as $file => $path)
foreach ($files as $file => $path)
{
// If this is a directory we're dealing with
if(is_array($path))
if (is_array($path))
{
$migrations += Minion_Migration_Util::compile_migrations_from_files($path);
}
Expand Down Expand Up @@ -81,7 +81,7 @@ public static function get_filename_from_migration(array $migration)
$location = $migration['location'];
$migration = $migration['timestamp'].'_'.$migration['description'];

$location = ! empty($location) ? rtrim($location, '/').'/' : '';
$location = ( ! empty($location)) ? (rtrim($location, '/').'/') : '';

return $location.$migration.EXT;
}
Expand All @@ -95,7 +95,7 @@ public static function get_filename_from_migration(array $migration)
*/
public static function get_class_from_migration($migration)
{
if(is_string($migration))
if (is_string($migration))
{
$migration = str_replace(array(':', '/'), ' ', $migration);
}
Expand Down
7 changes: 3 additions & 4 deletions classes/minion/task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* Interface that all minion tasks must implement
*
*/
abstract class Minion_Task {

Expand All @@ -15,14 +14,14 @@ abstract class Minion_Task {
*/
public static function factory($task)
{
if(is_string($task))
if (is_string($task))
{
$class = Minion_Util::convert_task_to_class_name($task);

$task = new $class;
}

if( ! $task instanceof Minion_Task)
if ( ! $task instanceof Minion_Task)
{
throw new Kohana_Exception(
"Task ':task' is not a valid minion task",
Expand All @@ -47,7 +46,7 @@ public function __toString()
{
static $task_name = NULL;

if($task_name === NULL)
if ($task_name === NULL)
{
$task_name = Minion_Util::convert_class_to_task($this);
}
Expand Down
4 changes: 2 additions & 2 deletions classes/minion/task/cache/purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Minion_Task_Cache_Purge extends Minion_Task
*/
public function execute(array $config)
{
if(empty($config['cache']))
if (empty($config['cache']))
{
return 'Please specify a set of cache configs.';
}
Expand All @@ -37,7 +37,7 @@ public function execute(array $config)

$caches = explode(',', $config['cache']);

foreach($caches as $cache)
foreach ($caches as $cache)
{
Cache::instance($cache)
->delete_all();
Expand Down
4 changes: 2 additions & 2 deletions classes/minion/task/db/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Minion_Task_Db_Generate extends Minion_Task
*/
public function execute(array $config)
{
if(empty($config['location']) OR empty($config['description']))
if (empty($config['location']) OR empty($config['description']))
{
return 'Please provide --location and --description'.PHP_EOL.
'See help for more info'.PHP_EOL;
Expand Down Expand Up @@ -86,7 +86,7 @@ protected function _generate_classname($location, $time)

// If location is empty then we want to avoid double underscore in the
// class name
if( ! empty($class))
if ( ! empty($class))
{
$class .= '_';
}
Expand Down
22 changes: 11 additions & 11 deletions classes/minion/task/db/migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,20 @@ public function execute(array $config)
*/
protected function _parse_locations($location)
{
if(is_array($location))
if (is_array($location))
return $location;

$location = trim($location);

if(empty($location))
if (empty($location))
return array();

$locations = array();
$location = explode(',', trim($location, ','));

if( ! empty($location))
if ( ! empty($location))
{
foreach($location as $a_location)
foreach ($location as $a_location)
{
$locations[] = trim($a_location, '/');
}
Expand All @@ -163,21 +163,21 @@ protected function _parse_locations($location)
*/
protected function _parse_target_versions($versions)
{
if(empty($versions))
if (empty($versions))
return array();

$targets = array();

if( ! is_array($versions))
if ( ! is_array($versions))
{
$versions = explode(',', trim($versions));
}

foreach($versions as $version)
foreach ($versions as $version)
{
$target = $this->_parse_version($version);

if(is_array($target))
if (is_array($target))
{
list($location, $version) = $target;

Expand All @@ -200,13 +200,13 @@ protected function _parse_target_versions($versions)
*/
protected function _parse_version($version)
{
if(is_bool($version))
if (is_bool($version))
return $version;

if($version === 'TRUE' OR $version == 'FALSE')
if ($version === 'TRUE' OR $version == 'FALSE')
return $version === 'TRUE';

if(strpos($version, ':') !== FALSE)
if (strpos($version, ':') !== FALSE)
return explode(':', $version);

throw new Kohana_Exception('Invalid target version :version', array(':version' => $version));
Expand Down
Loading

0 comments on commit 8fc8ea4

Please sign in to comment.