remove unused local variables and a few improvements

This commit is contained in:
Ceeram 2012-12-20 13:47:03 +01:00
parent f25f35353d
commit 3f4d24bfc0
38 changed files with 77 additions and 95 deletions

View file

@ -293,7 +293,7 @@ class ConsoleShell extends AppShell {
if ($this->_isValidModel($modelToSave)) {
// Extract the array of data we are trying to build
list($foo, $data) = explode("->save", $command);
list(, $data) = explode("->save", $command);
$data = preg_replace('/^\(*(array)?\(*(.+?)\)*$/i', '\\2', $data);
$saveCommand = "\$this->{$modelToSave}->save(array('{$modelToSave}' => array({$data})));";
//@codingStandardsIgnoreStart

View file

@ -133,7 +133,7 @@ class ServerShell extends AppShell {
$port = ($this->_port == self::DEFAULT_PORT) ? '' : ':' . $this->_port;
$this->out(__d('cake_console', 'built-in server is running in http://%s%s/', $this->_host, $port));
$ret = system($command);
system($command);
}
/**

View file

@ -296,7 +296,7 @@ class DbConfigTask extends AppShell {
}
foreach ($oldConfigs as $key => $oldConfig) {
foreach ($configs as $k => $config) {
foreach ($configs as $config) {
if ($oldConfig['name'] == $config['name']) {
unset($oldConfigs[$key]);
}

View file

@ -232,7 +232,7 @@ class FixtureTask extends BakeTask {
if (!empty($this->params['records']) || isset($importOptions['fromTable'])) {
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
}
$out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import', 'fields'));
$out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import'));
return $out;
}
@ -402,7 +402,7 @@ class FixtureTask extends BakeTask {
'recursive' => -1,
'limit' => $recordCount
));
$db = $modelObject->getDatasource();
$schema = $modelObject->schema(true);
$out = array();
foreach ($records as $record) {

View file

@ -377,7 +377,7 @@ class ModelTask extends BakeTask {
}
sort($options);
$default = 1;
foreach ($options as $key => $option) {
foreach ($options as $option) {
if ($option{0} != '_') {
$choices[$default] = strtolower($option);
$default++;
@ -545,8 +545,8 @@ class ModelTask extends BakeTask {
* @return array $associations with belongsTo added in.
*/
public function findBelongsTo(Model $model, $associations) {
$fields = $model->schema(true);
foreach ($fields as $fieldName => $field) {
$fieldNames = array_keys($model->schema(true));
foreach ($fieldNames as $fieldName) {
$offset = strpos($fieldName, '_id');
if ($fieldName != $model->primaryKey && $fieldName != 'parent_id' && $offset !== false) {
$tmpModelName = $this->_modelNameFromKey($fieldName);
@ -577,14 +577,14 @@ class ModelTask extends BakeTask {
$foreignKey = $this->_modelKey($model->name);
foreach ($this->_tables as $otherTable) {
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
$modelFieldsTemp = $tempOtherModel->schema(true);
$tempFieldNames = array_keys($tempOtherModel->schema(true));
$pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/';
$possibleJoinTable = preg_match($pattern, $otherTable);
if ($possibleJoinTable) {
continue;
}
foreach ($modelFieldsTemp as $fieldName => $field) {
foreach ($tempFieldNames as $fieldName) {
$assoc = false;
if ($fieldName != $model->primaryKey && $fieldName == $foreignKey) {
$assoc = array(
@ -619,9 +619,6 @@ class ModelTask extends BakeTask {
public function findHasAndBelongsToMany(Model $model, $associations) {
$foreignKey = $this->_modelKey($model->name);
foreach ($this->_tables as $otherTable) {
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
$modelFieldsTemp = $tempOtherModel->schema(true);
$offset = strpos($otherTable, $model->table . '_');
$otherOffset = strpos($otherTable, '_' . $model->table);

View file

@ -127,7 +127,7 @@ class PluginTask extends AppShell {
foreach ($directories as $directory) {
$dirPath = $this->path . $plugin . DS . $directory;
$Folder->create($dirPath);
$File = new File($dirPath . DS . 'empty', true);
new File($dirPath . DS . 'empty', true);
}
foreach ($Folder->messages() as $message) {

View file

@ -452,9 +452,9 @@ class ViewTask extends BakeTask {
$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
$associations = array();
foreach ($keys as $key => $type) {
foreach ($keys as $type) {
foreach ($model->{$type} as $assocKey => $assocData) {
list($plugin, $modelClass) = pluginSplit($assocData['className']);
list(, $modelClass) = pluginSplit($assocData['className']);
$associations[$type][$assocKey]['primaryKey'] = $model->{$assocKey}->primaryKey;
$associations[$type][$assocKey]['displayField'] = $model->{$assocKey}->displayField;
$associations[$type][$assocKey]['foreignKey'] = $assocData['foreignKey'];

View file

@ -303,7 +303,7 @@ class TestShell extends Shell {
$this->out($title);
$i = 1;
$cases = array();
foreach ($testCases as $testCaseFile => $testCase) {
foreach ($testCases as $testCase) {
$case = str_replace('Test.php', '', $testCase);
$this->out("[$i] $case");
$cases[$i] = $case;

View file

@ -261,9 +261,7 @@ class Shell extends Object {
return true;
}
$this->_taskMap = TaskCollection::normalizeObjectArray((array)$this->tasks);
foreach ($this->_taskMap as $task => $properties) {
$this->taskNames[] = $task;
}
$this->taskNames = array_merge($this->taskNames, array_keys($this->_taskMap));
return true;
}

View file

@ -174,7 +174,7 @@ class PhpAcl extends Object implements AclInterface {
return $allow;
}
foreach ($path as $depth => $node) {
foreach ($path as $node) {
foreach ($prioritizedAros as $aros) {
if (!empty($node['allow'])) {
$allow = $allow || count(array_intersect($node['allow'], $aros));
@ -336,7 +336,6 @@ class PhpAco {
*/
public function build(array $allow, array $deny = array()) {
$this->_tree = array();
$tree = array();
foreach ($allow as $dotPath => $aros) {
if (is_string($aros)) {

View file

@ -75,7 +75,7 @@ abstract class BaseAuthenticate {
*/
protected function _findUser($conditions, $password = null) {
$userModel = $this->settings['userModel'];
list($plugin, $model) = pluginSplit($userModel);
list(, $model) = pluginSplit($userModel);
$fields = $this->settings['fields'];
if (!is_array($conditions)) {

View file

@ -50,7 +50,7 @@ class BlowfishAuthenticate extends FormAuthenticate {
*/
public function authenticate(CakeRequest $request, CakeResponse $response) {
$userModel = $this->settings['userModel'];
list($plugin, $model) = pluginSplit($userModel);
list(, $model) = pluginSplit($userModel);
$fields = $this->settings['fields'];
if (!$this->_checkFields($request, $model, $fields)) {

View file

@ -159,7 +159,7 @@ class DigestAuthenticate extends BaseAuthenticate {
*/
protected function _findUser($username, $password = null) {
$userModel = $this->settings['userModel'];
list($plugin, $model) = pluginSplit($userModel);
list(, $model) = pluginSplit($userModel);
$fields = $this->settings['fields'];
$conditions = array(

View file

@ -68,7 +68,7 @@ class FormAuthenticate extends BaseAuthenticate {
*/
public function authenticate(CakeRequest $request, CakeResponse $response) {
$userModel = $this->settings['userModel'];
list($plugin, $model) = pluginSplit($userModel);
list(, $model) = pluginSplit($userModel);
$fields = $this->settings['fields'];
if (!$this->_checkFields($request, $model, $fields)) {

View file

@ -137,7 +137,7 @@ class Scaffold {
$associations = $this->_associations();
$this->controller->set(compact(
'title_for_layout', 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'
));
$this->controller->set('title_for_layout', $title);
@ -422,7 +422,7 @@ class Scaffold {
$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
$associations = array();
foreach ($keys as $key => $type) {
foreach ($keys as $type) {
foreach ($this->ScaffoldModel->{$type} as $assocKey => $assocData) {
$associations[$type][$assocKey]['primaryKey'] =
$this->ScaffoldModel->{$assocKey}->primaryKey;

View file

@ -197,7 +197,6 @@ class Configure {
* @return void
*/
public static function delete($var = null) {
$keys = explode('.', $var);
self::$_values = Hash::remove(self::$_values, $var);
}

View file

@ -414,7 +414,7 @@ class L10n {
*/
protected function _autoLanguage() {
$_detectableLanguages = CakeRequest::acceptLanguage();
foreach ($_detectableLanguages as $key => $langKey) {
foreach ($_detectableLanguages as $langKey) {
if (isset($this->_l10nCatalog[$langKey])) {
$this->_setLanguage($langKey);
return true;

View file

@ -124,7 +124,7 @@ class AclNode extends Model {
$ref = array('model' => $ref->name, 'foreign_key' => $ref->id);
} elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
$name = key($ref);
list($plugin, $alias) = pluginSplit($name);
list(, $alias) = pluginSplit($name);
$model = ClassRegistry::init(array('class' => $name, 'alias' => $alias));

View file

@ -124,7 +124,7 @@ class ContainableBehavior extends ModelBehavior {
$map = $this->containmentsMap($containments);
$mandatory = array();
foreach ($containments['models'] as $name => $model) {
foreach ($containments['models'] as $model) {
$instance = $model['instance'];
$needed = $this->fieldDependencies($instance, $map, false);
if (!empty($needed)) {

View file

@ -63,7 +63,7 @@ class BehaviorCollection extends ObjectCollection implements CakeEventListener {
$this->modelName = $modelName;
if (!empty($behaviors)) {
foreach (BehaviorCollection::normalizeObjectArray($behaviors) as $behavior => $config) {
foreach (BehaviorCollection::normalizeObjectArray($behaviors) as $config) {
$this->load($config['class'], $config['settings']);
}
}
@ -183,7 +183,7 @@ class BehaviorCollection extends ObjectCollection implements CakeEventListener {
* @return void
*/
public function unload($name) {
list($plugin, $name) = pluginSplit($name);
list(, $name) = pluginSplit($name);
if (isset($this->_loaded[$name])) {
$this->_loaded[$name]->cleanup(ClassRegistry::getObject($this->modelName));
parent::unload($name);

View file

@ -279,7 +279,7 @@ class CakeSchema extends Object {
if (empty($Object->hasAndBelongsToMany)) {
continue;
}
foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) {
foreach ($Object->hasAndBelongsToMany as $assocData) {
if (isset($assocData['with'])) {
$class = $assocData['with'];
}
@ -607,7 +607,7 @@ class CakeSchema extends Object {
$db = $Obj->getDataSource();
$fields = $Obj->schema(true);
$columns = $props = array();
$columns = array();
foreach ($fields as $name => $value) {
if ($Obj->primaryKey == $name) {
$value['key'] = 'primary';

View file

@ -355,7 +355,7 @@ class DataSource extends Object {
$type = $model->getColumnType($model->primaryKey);
break;
case '{$__cakeForeignKey__$}':
foreach ($model->associations() as $id => $name) {
foreach ($model->associations() as $name) {
foreach ($model->$name as $assocName => $assoc) {
if ($assocName === $association) {
if (isset($assoc['foreignKey'])) {

View file

@ -541,21 +541,13 @@ class Mysql extends DboSource {
}
/**
* Generate a MySQL "drop table" statement for the given Schema object
* Generate a "drop table" statement for the given table
*
* @param CakeSchema $schema An instance of a subclass of CakeSchema
* @param string $table Optional. If specified only the table name given will be generated.
* Otherwise, all tables defined in the schema are generated.
* @return string
* @param type $table Name of the table to drop
* @return string Drop table SQL statement
*/
public function dropSchema(CakeSchema $schema, $table = null) {
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table === $curTable) {
$out .= 'DROP TABLE IF EXISTS ' . $this->fullTableName($curTable) . ";\n";
}
}
return $out;
protected function _dropTable($table) {
return 'DROP TABLE IF EXISTS ' . $this->fullTableName($table) . ";";
}
/**

View file

@ -334,7 +334,7 @@ class Postgres extends DboSource {
if ($this->execute('DELETE FROM ' . $this->fullTableName($table))) {
$schema = $this->config['schema'];
if (isset($this->_sequenceMap[$table]) && $reset != true) {
foreach ($this->_sequenceMap[$table] as $field => $sequence) {
foreach ($this->_sequenceMap[$table] as $sequence) {
list($schema, $sequence) = explode('.', $sequence);
$this->_execute("ALTER SEQUENCE \"{$schema}\".\"{$sequence}\" RESTART WITH 1");
}

View file

@ -550,21 +550,13 @@ class Sqlite extends DboSource {
}
/**
* Generate a "drop table" statement for the given Schema object
* Generate a "drop table" statement for the given table
*
* @param CakeSchema $schema An instance of a subclass of CakeSchema
* @param string $table Optional. If specified only the table name given will be generated.
* Otherwise, all tables defined in the schema are generated.
* @return string
* @param type $table Name of the table to drop
* @return string Drop table SQL statement
*/
public function dropSchema(CakeSchema $schema, $table = null) {
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table == $curTable) {
$out .= 'DROP TABLE IF EXISTS ' . $this->fullTableName($curTable) . ";\n";
}
}
return $out;
protected function _dropTable($table) {
return 'DROP TABLE IF EXISTS ' . $this->fullTableName($table) . ";";
}
/**

View file

@ -759,21 +759,13 @@ class Sqlserver extends DboSource {
}
/**
* Generate a "drop table" statement for the given Schema object
* Generate a "drop table" statement for the given table
*
* @param CakeSchema $schema An instance of a subclass of CakeSchema
* @param string $table Optional. If specified only the table name given will be generated.
* Otherwise, all tables defined in the schema are generated.
* @return string
* @param type $table Name of the table to drop
* @return string Drop table SQL statement
*/
public function dropSchema(CakeSchema $schema, $table = null) {
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table == $curTable) {
$out .= "IF OBJECT_ID('" . $this->fullTableName($curTable, false) . "', 'U') IS NOT NULL DROP TABLE " . $this->fullTableName($curTable) . ";\n";
}
}
return $out;
protected function _dropTable($table) {
return "IF OBJECT_ID('" . $this->fullTableName($table, false) . "', 'U') IS NOT NULL DROP TABLE " . $this->fullTableName($table) . ";";
}
/**

View file

@ -1932,7 +1932,7 @@ class DboSource extends DataSource {
foreach ($conditions as $field => $value) {
$originalField = $field;
if (strpos($field, '.') !== false) {
list($alias, $field) = explode('.', $field);
list(, $field) = explode('.', $field);
$field = ltrim($field, $this->startQuote);
$field = rtrim($field, $this->endQuote);
}
@ -2973,7 +2973,7 @@ class DboSource extends DataSource {
foreach ($schema->tables as $curTable => $columns) {
if (!$tableName || $tableName == $curTable) {
$cols = $colList = $indexes = $tableParameters = array();
$cols = $indexes = $tableParameters = array();
$primary = null;
$table = $this->fullTableName($curTable);
@ -3042,14 +3042,28 @@ class DboSource extends DataSource {
public function dropSchema(CakeSchema $schema, $table = null) {
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table == $curTable) {
$out .= 'DROP TABLE ' . $this->fullTableName($curTable) . ";\n";
if ($table && array_key_exists($table, $schema->tables)) {
return $this->_dropTable($table) . "\n";
} elseif ($table) {
return $out;
}
foreach (array_keys($schema->tables) as $curTable) {
$out .= $this->_dropTable($curTable) . "\n";
}
return $out;
}
/**
* Generate a "drop table" statement for a single table
*
* @param type $table Name of the table to drop
* @return string Drop table SQL statement
*/
protected function _dropTable($table) {
return 'DROP TABLE ' . $this->fullTableName($table) . ";";
}
/**
* Generate a database-native column schema string
*

View file

@ -1799,7 +1799,7 @@ class Model extends Object implements CakeEventListener {
if ($with = $this->hasAndBelongsToMany[$assoc]['with']) {
$withModel = is_array($with) ? key($with) : $with;
list($pluginName, $withModel) = pluginSplit($withModel);
list(, $withModel) = pluginSplit($withModel);
$dbMulti = $this->{$withModel}->getDataSource();
} else {
$dbMulti = $db;

View file

@ -716,7 +716,7 @@ class CakeRequest implements ArrayAccess {
public static function acceptLanguage($language = null) {
$raw = self::_parseAcceptWithQualifier(self::header('Accept-Language'));
$accept = array();
foreach ($raw as $qualifier => $languages) {
foreach ($raw as $languages) {
foreach ($languages as &$lang) {
if (strpos($lang, '_')) {
$lang = str_replace('_', '-', $lang);

View file

@ -1261,7 +1261,7 @@ class CakeResponse {
$httpRange = env('HTTP_RANGE');
if (isset($httpRange)) {
list($toss, $range) = explode('=', $httpRange);
list(, $range) = explode('=', $httpRange);
$size = $fileSize - 1;
$length = $fileSize - $range;

View file

@ -326,7 +326,7 @@ class Router {
if (strpos($options['routeClass'], '.') === false) {
$routeClass = $options['routeClass'];
} else {
list($plugin, $routeClass) = pluginSplit($options['routeClass'], true);
list(, $routeClass) = pluginSplit($options['routeClass'], true);
}
$routeClass = self::_validateRouteClass($routeClass);
unset($options['routeClass']);

View file

@ -110,7 +110,7 @@ class ClassRegistry {
$count = count($objects);
$availableDs = array_keys(ConnectionManager::enumConnectionObjects());
foreach ($objects as $key => $settings) {
foreach ($objects as $settings) {
if (is_numeric($settings)) {
trigger_error(__d('cake_dev', '(ClassRegistry::init() Attempted to create instance of a class with a numeric name'), E_USER_WARNING);
return false;

View file

@ -211,7 +211,7 @@ class Folder {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::find
*/
public function find($regexpPattern = '.*', $sort = false) {
list($dirs, $files) = $this->read($sort);
list(, $files) = $this->read($sort);
return array_values(preg_grep('/^' . $regexpPattern . '$/i', $files));
}

View file

@ -269,9 +269,8 @@ class HtmlHelper extends AppHelper {
} else {
$type = array();
}
} elseif ($url !== null) {
$inline = $url;
}
$options = array_merge($type, $options);
$out = null;

View file

@ -91,7 +91,7 @@ class JsHelper extends AppHelper {
$className = $settings;
}
$engineName = $className;
list($plugin, $className) = pluginSplit($className);
list(, $className) = pluginSplit($className);
$this->_engineName = $className . 'Engine';
$engineClass = $engineName . 'Engine';

View file

@ -84,7 +84,7 @@ class JsonView extends View {
if (isset($this->viewVars['_serialize'])) {
return $this->_serialize($this->viewVars['_serialize']);
}
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
if ($view !== false && $this->_getViewFileName($view)) {
return parent::render($view, false);
}
}

View file

@ -880,7 +880,7 @@ class View extends Object {
public function loadHelpers() {
$helpers = HelperCollection::normalizeObjectArray($this->helpers);
foreach ($helpers as $properties) {
list($plugin, $class) = pluginSplit($properties['class']);
list(, $class) = pluginSplit($properties['class']);
$this->{$class} = $this->Helpers->load($properties['class'], $properties['settings']);
}
$this->_helpersLoaded = true;

View file

@ -87,7 +87,7 @@ class XmlView extends View {
if (isset($this->viewVars['_serialize'])) {
return $this->_serialize($this->viewVars['_serialize']);
}
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
if ($view !== false && $this->_getViewFileName($view)) {
return parent::render($view, false);
}
}