From 27af06cbb02923b1cebd95e3bc0db3d3fda46212 Mon Sep 17 00:00:00 2001 From: Paminger Date: Sun, 10 Apr 2016 21:43:45 +0200 Subject: [PATCH] CodeSniffer --- application/controllers/DBTools.php | 102 ++++++----- application/controllers/Migrate.php | 160 ----------------- .../controllers/organisation/Studiengang2.php | 167 ------------------ phpci.yml | 4 +- 4 files changed, 59 insertions(+), 374 deletions(-) delete mode 100644 application/controllers/Migrate.php delete mode 100644 application/controllers/organisation/Studiengang2.php diff --git a/application/controllers/DBTools.php b/application/controllers/DBTools.php index 17425380f..1ce9b55ae 100644 --- a/application/controllers/DBTools.php +++ b/application/controllers/DBTools.php @@ -1,6 +1,7 @@ input->is_cli_request()) { - $cli=true; + $cli = true; } else { @@ -45,16 +45,15 @@ class DBTools extends FHC_Controller } // can only be run in the development environment - if (ENVIRONMENT !== 'development') { + if (ENVIRONMENT !== 'development') exit('Wowsers! You don\'t want to do that!'); - } $this->load->database('system'); //Use the system-Connection for DB-Manipulation $this->load->library('migration'); // If not set, set it - //$this->_seed_path !== '' OR $this->_seed_path = APPPATH.'seeds/'; + //$this->seed_path !== '' OR $this->seed_path = APPPATH.'seeds/'; // Add trailing slash if not set - //$this->_seed_path = rtrim($this->_seed_path, '/').'/'; + //$this->seed_path = rtrim($this->seed_path, '/').'/'; // Load seed language $this->lang->load('seed'); @@ -68,43 +67,51 @@ class DBTools extends FHC_Controller log_message('info', 'DB-Tools Controller Initialized'); } - public function index() + /** + * Main function index as help + * + * @return void + */ + public function index() { $result = "The following are the available command line interface commands\n\n"; - $result .= "php index.ci.php DBTools migrate [\"version_number\"] Run all migrations. The version number is optional.\n"; + $result .= "php index.ci.php DBTools migrate [\"version_number\"] Run all migrations. " + $result .= "The version number is optional.\n"; $result .= "php index.ci.php DBTools seed \"file_name\" Run the specified seed file.\n"; - echo $result . PHP_EOL; + echo $result.PHP_EOL; } /** * Migrate to latest or current version * * @param string $version One of either "latest" or "current" + * @return void */ public function migrate($version = 'latest') { - - if ($this->cli && $this->migration->current() === FALSE) + if ($this->cli && $this->migration->current() === false) { show_error($this->migration->error_string()); } elseif ($version != 'latest' && $version != 'current') { - $this->_failed('Migration version must be either latest or current'); + $this->__failed('Migration version must be either latest or current'); } if (!$this->migration->$version()) { - $this->_failed(); + $this->__failed(); } - $this->_succeeded(); + $this->__succeeded(); } /** * Migrate to a specific version + * + * @return void */ public function version() { @@ -116,36 +123,39 @@ class DBTools extends FHC_Controller if (!$this->migrate->version($version)) { - $this->_failed(); + $this->__failed(); } - $this->_succeeded(); + $this->__succeeded(); } /** * Roll-back to the last version before current * * @param int $version The migration to rollback to, defaults to previous + * @return void */ public function rollback($version = null) { if (is_null($version)) { - $version = $this->_get_version() ?: 1; + $version = $this->__getVersion() ?: 1; $version--; } // Check it's definitely false, we could be rolling back to v0 if (false === $this->migration->version($version)) { - $this->_failed(); + $this->__failed(); } - $this->_succeeded('rolled back'); + $this->__succeeded('rolled back'); } /** * ROLLBACK ALL THE THINGS! + * + * @return void */ public function uninstall() { @@ -155,17 +165,17 @@ class DBTools extends FHC_Controller /** * Seeds DB with Testdata * - * @param string $name + * @param string $name Name of the seed file. * @return bool */ - function seed($name = null) + public function seed($name = null) { - $seeds = $this->find_seeds(); + $seeds = $this->findSeeds(); if (empty($seeds)) { $this->_error_string = $this->lang->line('seed_none_found'); - return FALSE; + return false; } $method = 'seed'; @@ -173,21 +183,21 @@ class DBTools extends FHC_Controller foreach ($seeds as $number => $file) { include_once($file); - $class = 'Seed_'.ucfirst(strtolower($this->_get_seed_name(basename($file, '.php')))); + $class = 'Seed_'.ucfirst(strtolower($this->_getSeedName(basename($file, '.php')))); // Validate the seed file structure - if ( ! class_exists($class, FALSE)) + if (! class_exists($class, false)) { $this->_error_string = sprintf($this->lang->line('seed_class_doesnt_exist'), $class); - return FALSE; + return false; } // method_exists() returns true for non-public methods, // while is_callable() can't be used without instantiating. // Only get_class_methods() satisfies both conditions. - elseif ( ! in_array($method, array_map('strtolower', get_class_methods($class)))) + elseif (! in_array($method, array_map('strtolower', get_class_methods($class)))) { $this->_error_string = sprintf($this->lang->line('seed_missing_'.$method.'_method'), $class); - return FALSE; + return false; } $pending[$number] = array($class, $method); @@ -207,19 +217,19 @@ class DBTools extends FHC_Controller * * @return array list of seed file paths sorted by version */ - public function find_seeds() + public function findSeeds() { $seeds = array(); // Load all *_*.php files in the seeds path - foreach (glob($this->_seed_path.'*_*.php') as $file) + foreach (glob($this->seed_path.'*_*.php') as $file) { $name = basename($file, '.php'); // Filter out non-seed files - if (preg_match($this->_seed_regex, $name)) + if (preg_match($this->seed_regex, $name)) { - $number = $this->_get_seed_number($name); + $number = $this->_getSeedNumber($name); // There cannot be duplicate seed numbers if (isset($seeds[$number])) @@ -239,10 +249,10 @@ class DBTools extends FHC_Controller /** * Extracts the seed number from a filename * - * @param string $seed + * @param string $seed Filename of the seed. * @return string Numeric portion of a seed filename */ - protected function _get_seed_number($seed) + protected function _getSeedNumber($seed) { return sscanf($seed, '%[0-9]+', $number) ? $number : '0'; @@ -250,10 +260,10 @@ class DBTools extends FHC_Controller /** * Extracts the seed class name from a filename * - * @param string $seed + * @param string $seed Filename of the seed. * @return string text portion of a migration filename */ - protected function _get_seed_name($seed) + protected function _getSeedName($seed) { $parts = explode('_', $seed); array_shift($parts); @@ -264,10 +274,11 @@ class DBTools extends FHC_Controller * Yay, it worked! Tell the user. * * @param string $task What did we just do? We... + * @return void */ - private function _succeeded($task = 'migrated') + private function __succeeded($task = 'migrated') { - $version = $this->_get_version(); + $version = $this->__getVersion(); exit('Successfully '.$task.' to version '.$version); } @@ -275,19 +286,20 @@ class DBTools extends FHC_Controller * Output an error message when it all goes tits up * * @param string $message Error to output (default to CI's migration error) + * @return void */ - private function _failed($message = null) + private function __failed($message = null) { $message = $message ?: $this->migration->error_string(); show_error($message); } /** - * Carbon copy of parent::_get_version, but that's protected. + * Carbon copy of parent::__getVersion, but that's protected. * * @return int Currently installed migration number */ - private function _get_version() + private function __getVersion() { $row = $this->db->get('ci_migrations')->row(); return $row ? $row->version : 0; diff --git a/application/controllers/Migrate.php b/application/controllers/Migrate.php deleted file mode 100644 index fb7021fec..000000000 --- a/application/controllers/Migrate.php +++ /dev/null @@ -1,160 +0,0 @@ -input->is_cli_request()) - { - $cli=true; - } - else - { - //$this->output->set_status_header(403, 'Migrations must be run from the CLI'); - //exit; - } - $this->load->database('system'); //Use the system-Connection for DB-Manipulation - $this->load->library('migration'); - $this->load->library('FHC_Seed'); - } - - - public function help() { - $result = "The following are the available command line interface commands\n\n"; - $result .= "php index.ci.php db migrate [\"version_number\"] Run all migrations. The version number is optional.\n"; - $result .= "php index.ci.php db seed \"file_name\" Run the specified seed file. Filename is optional.\n"; - - echo $result . PHP_EOL; - } - - /** - * Migrate to latest or current version - * - * @param string $version One of either "latest" or "current" - */ - public function migrate($version = 'latest') - { - - if ($this->cli && $this->migration->current() === FALSE) - { - show_error($this->migration->error_string()); - } - elseif ($version != 'latest' && $version != 'current') - { - $this->_failed('Migration version must be either latest or current'); - } - - if (!$this->migration->version()) - { - $this->_failed(); - } - - $this->_succeeded(); - } - - - /** - * Migrate to a specific version - */ - public function version() - { - if ($version == 'latest' || $version == 'current') - { - $this->index($version); - exit; - } - - if (!$this->migrate->version($version)) - { - $this->_failed(); - } - - $this->_succeeded(); - } - - /** - * Roll-back to the last version before current - * - * @param int $version The migration to rollback to, defaults to previous - */ - public function rollback($version = null) - { - if (is_null($version)) - { - $version = $this->_get_version() ?: 1; - $version--; - } - - // Check it's definitely false, we could be rolling back to v0 - if (false === $this->migration->version($version)) - { - $this->_failed(); - } - - $this->_succeeded('rolled back'); - } - - /** - * ROLLBACK ALL THE THINGS! - */ - public function uninstall() - { - $this->rollback(0); - } - - /** - * Seed DB with TestData - * - * @param string $name Name of the SeedFile - */ - - public function seed($name = null) - { - $this->fhc_seed->seed($name); - } - - /** - * Yay, it worked! Tell the user. - * - * @param string $task What did we just do? We... - */ - private function _succeeded($task = 'migrated') - { - $version = $this->_get_version(); - exit('Successfully '.$task.' to version '.$version); - } - - /** - * Output an error message when it all goes tits up - * - * @param string $message Error to output (default to CI's migration error) - */ - private function _failed($message = null) - { - $message = $message ?: $this->migration->error_string(); - show_error($message); - } - - /** - * Carbon copy of parent::_get_version, but that's protected. - * - * @return int Currently installed migration number - */ - private function _get_version() - { - $row = $this->db->get('ci_migrations')->row(); - return $row ? $row->version : 0; - } - - public function about() - { - echo "CI-Migrate_CLI v".$this->class_version; - echo "\nCheck http://github.com/dshoreman/ci-migrate_cli/ for updates"; - exit; - } -} diff --git a/application/controllers/organisation/Studiengang2.php b/application/controllers/organisation/Studiengang2.php deleted file mode 100644 index 600a1d17b..000000000 --- a/application/controllers/organisation/Studiengang2.php +++ /dev/null @@ -1,167 +0,0 @@ -load->model('organisation/studiengang_model'); - $this->load->library('form_validation'); - } - - public function index() - { - $keyword = ''; - $this->load->library('pagination'); - - $config['base_url'] = base_url() . 'studiengang/index/'; - $config['total_rows'] = $this->studiengang_model->total_rows(); - $config['per_page'] = 10; - $config['uri_segment'] = 3; - $config['suffix'] = '.html'; - $config['first_url'] = base_url() . 'studiengang.html'; - $this->pagination->initialize($config); - - $start = $this->uri->segment(3, 0); - $studiengang = $this->studiengang_model->index_limit($config['per_page'], $start); - - $data = array( - 'studiengang_data' => $studiengang, - 'keyword' => $keyword, - 'pagination' => $this->pagination->create_links(), - 'total_rows' => $config['total_rows'], - 'start' => $start, - ); - - $this->load->view('tbl_studiengang_list', $data); - } - - public function search() - { - $keyword = $this->uri->segment(3, $this->input->post('keyword', TRUE)); - $this->load->library('pagination'); - - if ($this->uri->segment(2)=='search') { - $config['base_url'] = base_url() . 'studiengang/search/' . $keyword; - } else { - $config['base_url'] = base_url() . 'studiengang/index/'; - } - - $config['total_rows'] = $this->studiengang_model->search_total_rows($keyword); - $config['per_page'] = 10; - $config['uri_segment'] = 4; - $config['suffix'] = '.html'; - $config['first_url'] = base_url() . 'studiengang/search/'.$keyword.'.html'; - $this->pagination->initialize($config); - - $start = $this->uri->segment(4, 0); - $studiengang = $this->studiengang_model->search_index_limit($config['per_page'], $start, $keyword); - - $data = array( - 'studiengang_data' => $studiengang, - 'keyword' => $keyword, - 'pagination' => $this->pagination->create_links(), - 'total_rows' => $config['total_rows'], - 'start' => $start, - ); - $this->load->view('tbl_studiengang_list', $data); - } - - public function read($id) - { - $row = $this->studiengang_model->get_by_id($id); - if ($row) { - $data = array( - ); - $this->load->view('tbl_studiengang_read', $data); - } else { - $this->session->set_flashdata('message', 'Record Not Found'); - redirect(site_url('studiengang')); - } - } - - public function create() - { - $data = array( - 'button' => 'Create', - 'action' => site_url('studiengang/create_action'), - ); - $this->load->view('tbl_studiengang_form', $data); - } - - public function create_action() - { - $this->_rules(); - - if ($this->form_validation->run() == FALSE) { - $this->create(); - } else { - $data = array( - ); - - $this->studiengang_model->insert($data); - $this->session->set_flashdata('message', 'Create Record Success'); - redirect(site_url('studiengang')); - } - } - - public function update($id) - { - $row = $this->studiengang_model->get_by_id($id); - - if ($row) { - $data = array( - 'button' => 'Update', - 'action' => site_url('studiengang/update_action'), - ); - $this->load->view('tbl_studiengang_form', $data); - } else { - $this->session->set_flashdata('message', 'Record Not Found'); - redirect(site_url('studiengang')); - } - } - - public function update_action() - { - $this->_rules(); - - if ($this->form_validation->run() == FALSE) { - $this->update($this->input->post('', TRUE)); - } else { - $data = array( - ); - - $this->studiengang_model->update($this->input->post('', TRUE), $data); - $this->session->set_flashdata('message', 'Update Record Success'); - redirect(site_url('studiengang')); - } - } - - public function delete($id) - { - $row = $this->studiengang_model->get_by_id($id); - - if ($row) { - $this->studiengang_model->delete($id); - $this->session->set_flashdata('message', 'Delete Record Success'); - redirect(site_url('studiengang')); - } else { - $this->session->set_flashdata('message', 'Record Not Found'); - redirect(site_url('studiengang')); - } - } - - public function _rules() - { - - $this->form_validation->set_rules('', '', 'trim'); - $this->form_validation->set_error_delimiters('', ''); - } - -}; - -/* End of file Studiengang.php */ -/* Location: ./application/controllers/Studiengang.php */ diff --git a/phpci.yml b/phpci.yml index a0c96f62a..29d859b1c 100644 --- a/phpci.yml +++ b/phpci.yml @@ -37,8 +37,8 @@ test: standard: "tests/codesniffer/FHComplete" allowed_errors: 100 allowed_warnings: 200 -# codeception: -# config: "tests/codeception/" + codeception: + config: "tests/" # php_unit: # directory: "tests/phpunit/"