Misc code formatting and whitespace fixes

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7020 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-05-23 05:11:41 +00:00
parent d3f772cfb4
commit 7402680cc1
21 changed files with 163 additions and 133 deletions

View file

@ -51,19 +51,19 @@ class ErrorHandler extends Object {
*/
function __construct($method, $messages) {
App::import('Controller', 'App');
App::import('Core', 'Sanitize');
$this->controller =& new AppController();
$this->controller->_set(Router::getPaths());
$this->controller->params = Router::getParams();
$this->controller->constructClasses();
$this->controller->cacheAction = false;
$this->controller->viewPath = 'errors';
$this->controller->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
$allow = array('.', '/', '_', ' ', '-', '~');
if (substr(PHP_OS,0,3) == "WIN") {
$allow = array_merge($allow, array('\\', ':') );
if (substr(PHP_OS, 0, 3) == "WIN") {
$allow = array_merge($allow, array('\\', ':'));
}
App::import('Core', 'Sanitize');
$messages = Sanitize::paranoid($messages, $allow);
if (!isset($messages[0])) {
@ -81,6 +81,9 @@ class ErrorHandler extends Object {
if ($method == 'error') {
$this->dispatchMethod($method, $messages);
$this->stop();
} elseif (Configure::read() == 0 && (isset($code) && $code == 500)) {
$this->dispatchMethod('error500', $messages);
exit();
} elseif (Configure::read() == 0) {
$this->dispatchMethod('error404', $messages);
$this->stop();
@ -97,10 +100,12 @@ class ErrorHandler extends Object {
*/
function error($params) {
extract($params, EXTR_OVERWRITE);
$this->controller->set(array('code' => $code,
'name' => $name,
'message' => $message,
'title' => $code . ' ' . $name));
$this->controller->set(array(
'code' => $code,
'name' => $name,
'message' => $message,
'title' => $code . ' ' . $name
));
$this->__outputMessage('error404');
}
/**
@ -117,10 +122,12 @@ class ErrorHandler extends Object {
}
$url = Router::normalize($url);
header("HTTP/1.0 404 Not Found");
$this->controller->set(array('code' => '404',
'name' => __('Not Found', true),
'message' => sprintf(__("The requested address %s was not found on this server.", true), "<strong>'{$url}'</strong>"),
'base' => $this->controller->base));
$this->controller->set(array(
'code' => '404',
'name' => __('Not Found', true),
'message' => sprintf(__("The requested address %s was not found on this server.", true), "<strong>'{$url}'</strong>"),
'base' => $this->controller->base
));
$this->__outputMessage('error404');
}
/**

View file

@ -213,8 +213,8 @@ class File extends Object {
$lineBreak = "\n";
if (substr(PHP_OS,0,3) == "WIN" || $forceWindows === true) {
$lineBreak = "\r\n";
}
return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
}
return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
}
/**

View file

@ -217,7 +217,7 @@ class TranslateBehavior extends ModelBehavior {
}
}
return $results;
}
}
/**
* Callback
*/

View file

@ -492,8 +492,12 @@ class TreeBehavior extends ModelBehavior {
return false;
}
}
$previousNode = $model->find('first', array('conditions' => array($scope, $model->escapeField($right) => ($node[$left] - 1)),
'fields' => array($model->primaryKey, $left, $right), 'recursive' => $recursive));
$previousNode = $model->find('first', array(
'conditions' => array($scope, $model->escapeField($right) => ($node[$left] - 1)),
'fields' => array($model->primaryKey, $left, $right),
'recursive' => $recursive
));
if ($previousNode) {
list($previousNode) = array_values($previousNode);
} else {
@ -540,8 +544,12 @@ class TreeBehavior extends ModelBehavior {
'fields' => array($model->primaryKey, $left, $right, $parent,
'actsAs' => '')
))));
$missingParents = $model->find('list', array('recursive' => 0, 'conditions' =>
array($scope, array('NOT' => array($model->escapeField($parent) => null), $model->VerifyParent->escapeField() => null))));
$missingParents = $model->find('list', array(
'recursive' => 0,
'conditions' => array($scope, array(
'NOT' => array($model->escapeField($parent) => null), $model->VerifyParent->escapeField() => null
))
));
$model->unbindModel(array('belongsTo' => array('VerifyParent')));
if ($missingParents) {
if ($missingParentAction == 'return') {
@ -632,9 +640,13 @@ class TreeBehavior extends ModelBehavior {
extract (array_merge($id, array('id' => null)));
}
extract($this->settings[$model->alias]);
list($node) = array_values($model->find('first', array('conditions' => array($scope, $model->escapeField() => $id),
'fields' => array($model->primaryKey, $left, $right, $parent), 'recursive' => $recursive))
);
list($node) = array_values($model->find('first', array(
'conditions' => array($scope, $model->escapeField() => $id),
'fields' => array($model->primaryKey, $left, $right, $parent),
'recursive' => $recursive
)));
if ($node[$right] == $node[$left] + 1) {
if ($delete) {
$model->delete();
@ -642,12 +654,15 @@ class TreeBehavior extends ModelBehavior {
return false;
}
} elseif ($node[$parent]) {
list($parentNode) = array_values($model->find('first', array('conditions' => array($scope, $model->escapeField() => $node[$parent]),
'fields' => array($model->primaryKey, $left, $right), 'recursive' => $recursive))
);
list($parentNode) = array_values($model->find('first', array(
'conditions' => array($scope, $model->escapeField() => $node[$parent]),
'fields' => array($model->primaryKey, $left, $right),
'recursive' => $recursive
)));
} else {
$parentNode[$right]= $node[$right] + 1;
$parentNode[$right] = $node[$right] + 1;
}
$model->updateAll(array($parent => $node[$parent]), array($parent => $node[$model->primaryKey]));
$this->__sync($model, 1, '-', 'BETWEEN ' . ($node[$left] + 1) . ' AND ' . ($node[$right] - 1));
$this->__sync($model, 2, '-', '> ' . ($node[$right]));
@ -655,7 +670,11 @@ class TreeBehavior extends ModelBehavior {
if ($delete) {
$model->updateAll(
array($model->escapeField($left) => 0, $model->escapeField($right) => 0, $model->escapeField($parent) => null),
array(
$model->escapeField($left) => 0,
$model->escapeField($right) => 0,
$model->escapeField($parent) => null
),
array($model->escapeField() => $id)
);
return $model->delete($id);
@ -705,7 +724,9 @@ class TreeBehavior extends ModelBehavior {
$errors = array();
for ($i = $min; $i <= $edge; $i++) {
$count = $model->find('count', array('conditions' => array($scope, 'OR' => array($model->escapeField($left) => $i, $model->escapeField($right) => $i))));
$count = $model->find('count', array('conditions' => array(
$scope, 'OR' => array($model->escapeField($left) => $i, $model->escapeField($right) => $i)
)));
if ($count != 1) {
if ($count == 0) {
$errors[] = array('index', $i, 'missing');
@ -830,9 +851,9 @@ class TreeBehavior extends ModelBehavior {
}
}
list($edge) = array_values($model->find('first', array(
'conditions' => $scope,
'fields' => $db->calculate($model, 'max', array($right)),
'recursive' => $recursive
'conditions' => $scope,
'fields' => $db->calculate($model, 'max', array($right)),
'recursive' => $recursive
)));
return ife(empty ($edge[$right]), 0, $edge[$right]);
}

View file

@ -220,7 +220,7 @@ class DboMysql extends DboSource {
return "''";
}
if (empty($column)) {
$column = $this->introspectType($data);
$column = $this->introspectType($data);
}
switch ($column) {

View file

@ -252,7 +252,7 @@ class DboPostgres extends DboSource {
return 'NULL';
}
if (empty($column)) {
$column = $this->introspectType($data);
$column = $this->introspectType($data);
}
switch($column) {
@ -261,20 +261,19 @@ class DboPostgres extends DboSource {
case 'integer':
if ($data === '') {
return 'DEFAULT';
} else {
$data = pg_escape_string($data);
}
break;
case 'binary':
$data = pg_escape_bytea($data);
break;
case 'boolean':
default:
if ($data === true) {
return 'TRUE';
} elseif ($data === false) {
return 'FALSE';
}
return 'DEFAULT';
break;
default:
$data = pg_escape_string($data);
break;
}

View file

@ -856,7 +856,7 @@ class Model extends Overloadable {
function getColumnTypes() {
$columns = $this->schema();
if (empty($columns)) {
trigger_error(__('(Model::getColumnTypes) Unable to build model field data. If you are using a model without a database table, try implementing schema()', true), E_USER_WARNING);
trigger_error(__('(Model::getColumnTypes) Unable to build model field data. If you are using a model without a database table, try implementing schema()', true), E_USER_WARNING);
}
$cols = array();
foreach ($columns as $field => $values) {
@ -879,7 +879,7 @@ class Model extends Overloadable {
$column = str_replace(array($db->startQuote, $db->endQuote), '', $column);
if (strpos($column, '.')) {
list($model, $column) = explode('.', $column);
list($model, $column) = explode('.', $column);
}
if ($model != $this->alias && isset($this->{$model})) {
return $this->{$model}->getColumnType($column);
@ -1407,9 +1407,9 @@ class Model extends Overloadable {
}
$_options = array_merge($options, array('atomic' => false));
if ($_options['validate'] === 'first') {
$_options['validate'] = 'only';
}
if ($_options['validate'] === 'first') {
$_options['validate'] = 'only';
}
$_return = $this->{$association}->saveAll($values, $_options);
if ($_return === false || (is_array($_return) && in_array(false, $_return, true))) {
@ -1417,14 +1417,14 @@ class Model extends Overloadable {
$validates = false;
}
if (is_array($_return)) {
foreach ($_return as $val) {
if (!isset($return[$association])) {
$return[$association] = array();
} elseif (!is_array($return[$association])) {
$return[$association] = array($return[$association]);
}
$return[$association][] = $val;
}
foreach ($_return as $val) {
if (!isset($return[$association])) {
$return[$association] = array();
} elseif (!is_array($return[$association])) {
$return[$association] = array($return[$association]);
}
$return[$association][] = $val;
}
} else {
$return[$association] = $_return;
}
@ -2131,7 +2131,7 @@ class Model extends Overloadable {
if (isset($data[$this->alias])) {
$data = $data[$this->alias];
} elseif (!is_array($data)) {
$data = array();
$data = array();
}
$Validation =& Validation::getInstance();

View file

@ -129,9 +129,9 @@ class String extends Object {
* @static
*/
function tokenize($data, $separator = ',', $leftBound = '(', $rightBound = ')') {
if(empty($data) || is_array($data)) {
return $data;
}
if(empty($data) || is_array($data)) {
return $data;
}
$depth = 0;
$offset = 0;

View file

@ -610,18 +610,19 @@ class Validation extends Object {
* @return boolean Success
* @access public
*/
function money($check, $symbolPosition = 'left') {
$_this =& Validation::getInstance();
$_this->check = $check;
switch ($symbolPosition) {
case 'left':
$_this->regex = '/^(?!\x{00a2})\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$/u';
break;
case 'right':
$_this->regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?<!\x{00a2})\p{Sc}?$/u';
break;
}
return $_this->_check();
function money($check, $symbolPosition = 'left') {
$_this =& Validation::getInstance();
$_this->check = $check;
switch ($symbolPosition) {
case 'left':
$_this->regex = '/^(?!\x{00a2})\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$/u';
break;
case 'right':
$_this->regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?<!\x{00a2})\p{Sc}?$/u';
break;
}
return $_this->_check();
}
/**
* Validate a multiple select.
@ -632,7 +633,7 @@ class Validation extends Object {
* @access public
* @todo Implement
*/
function multiple($check, $type, $regex = null) {
function multiple($check, $type, $regex = null) {
//Validate a select object for a selected index past 0.
//Validate a select against a list of restriced indexes.
//Validate a multiple-select for the quantity selected.
@ -671,7 +672,7 @@ class Validation extends Object {
case 'us':
default:
$_this->regex = '/^1?[-. ]?\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/';
break;
break;
}
}
return $_this->_check();

View file

@ -490,17 +490,18 @@ class HtmlHelper extends AppHelper {
$useCount = true;
$oddTrOptions = null;
}
if ($evenTrOptions === false) {
$continueOddEven = false;
$evenTrOptions = null;
}
if ($continueOddEven) {
static $count = 0;
static $count = 0;
} else {
$count = 0;
$count = 0;
}
foreach ($data as $line) {
$count++;
$cellsOut = array();
@ -531,7 +532,7 @@ class HtmlHelper extends AppHelper {
* @param boolean $escape If true, $text will be HTML-escaped
* @return string The formatted tag element
*/
function tag($name, $text = null, $attributes = array(), $escape = false) {
function tag($name, $text = null, $attributes = array(), $escape = false) {
if ($escape) {
$text = h($text);
}
@ -661,9 +662,9 @@ class HtmlHelper extends AppHelper {
foreach ($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue);
if (!empty($value) && $optValue == $value) {
$optionsHere['checked'] = 'checked';
}
if (!empty($value) && $optValue == $value) {
$optionsHere['checked'] = 'checked';
}
$parsedOptions = $this->_parseAttributes(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
$individualTagName = $this->field() . "_{$optValue}";
$out[] = sprintf($this->tags['radio'], $this->model(), $this->field(), $individualTagName, $parsedOptions, $optTitle);

View file

@ -133,11 +133,11 @@ class SessionHelper extends CakeSession {
$flash = parent::read('Message.' . $key);
if ($flash['layout'] == 'default') {
if (!empty($flash['params']['class'])) {
$class = $flash['params']['class'];
} else {
$class = 'message';
}
if (!empty($flash['params']['class'])) {
$class = $flash['params']['class'];
} else {
$class = 'message';
}
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>';
} elseif ($flash['layout'] == '' || $flash['layout'] == null) {
$out = $flash['message'];

View file

@ -298,7 +298,7 @@ class DispatcherTest extends UnitTestCase {
array('data' => ''),
),
'Post' => array('attachment' => 'application/x-javascript'),
),
),
'tmp_name' => array(
'File' => array(
array('data' => '/private/var/tmp/phpy05Ywj'),
@ -316,8 +316,8 @@ class DispatcherTest extends UnitTestCase {
array('data' => 4)
),
'Post' => array('attachment' => 0)
),
'size' => array(
),
'size' => array(
'File' => array(
array('data' => 6271),
array('data' => 350),
@ -341,7 +341,7 @@ class DispatcherTest extends UnitTestCase {
'size' => 6271,
),
),
array('data' => array(
array('data' => array(
'name' => 'controller.diff',
'type' => '',
'tmp_name' => '/private/var/tmp/php7MBztY',

View file

@ -66,7 +66,7 @@ class CodeCoverageManagerTest extends UnitTestCase {
$contents = $folder->ls();
function remove($var) {
return ($var != basename(__FILE__));
return ($var != basename(__FILE__));
}
$contents[1] = array_filter($contents[1], "remove");

View file

@ -295,37 +295,37 @@ class AclComponentTest extends CakeTestCase {
$result = $this->Acl->_Instance->readConfigFile($iniFile);
$expected = array(
'admin' => array(
'groups' => 'administrators',
'allow' => '',
'deny' => 'ads',
),
'paul' => array(
'groups' => 'users',
'allow' =>'',
'deny' => '',
),
'jenny' => array(
'groups' => 'users',
'allow' => 'ads',
'deny' => 'images, files',
),
'groups' => 'administrators',
'allow' => '',
'deny' => 'ads',
),
'paul' => array(
'groups' => 'users',
'allow' =>'',
'deny' => '',
),
'jenny' => array(
'groups' => 'users',
'allow' => 'ads',
'deny' => 'images, files',
),
'nobody' => array(
'groups' => 'anonymous',
'allow' => '',
'deny' => '',
),
'administrators' => array(
'deny' => '',
'allow' => 'posts, comments, images, files, stats, ads',
),
'users' => array(
'allow' => 'posts, comments, images, files',
'deny' => 'stats, ads',
),
'administrators' => array(
'deny' => '',
'allow' => 'posts, comments, images, files, stats, ads',
),
'users' => array(
'allow' => 'posts, comments, images, files',
'deny' => 'stats, ads',
),
'anonymous' => array(
'allow' => '',
'deny' => 'posts, comments, images, files, stats, ads',
),
'allow' => '',
'deny' => 'posts, comments, images, files, stats, ads',
),
);
$this->assertEqual($result, $expected);
}

View file

@ -51,7 +51,7 @@ class EmailTest extends CakeTestCase {
function testBadSmtpSend() {
if (@fsockopen('localhost', 25)) {
$this->Controller->Email->smtpOptions['host'] = 'blah';
$this->Controller->Email->delivery = 'smtp';
$this->Controller->Email->delivery = 'smtp';
$this->assertFalse($this->Controller->Email->send('Should not work'));
} else {
$this->skipUnless(@fsockopen('localhost', 25), 'Must be able to connect to localhost port 25');

View file

@ -275,7 +275,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
unset($this->RequestHandler);
unset($this->Controller);
if (!headers_sent()) {
header('Content-type: text/html'); //reset content type.
header('Content-type: text/html'); //reset content type.
}
}
}

View file

@ -58,9 +58,6 @@ class ScaffoldViewTest extends CakeTestCase {
$this->Controller = new ScaffoldMockController();
}
function tearDown() {
unset($this->Controller);
}
function testGetViewFilename() {
$this->Controller->action = 'index';
$ScaffoldView =& new TestScaffoldView($this->Controller);
@ -68,10 +65,14 @@ class ScaffoldViewTest extends CakeTestCase {
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'index.ctp';
$this->assertEqual($result, $expected);
$result = $ScaffoldView->testGetFilename('error');
$expected = 'cake' . DS . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp';
$this->assertEqual($result, $expected);
}
function tearDown() {
unset($this->Controller);
}
}
?>

View file

@ -97,10 +97,10 @@ class DebuggerTest extends UnitTestCase {
set_error_handler('simpleTestErrorHandler');
}
function testTrimPath() {
$this->assertEqual(Debugger::trimPath(APP), 'APP/');
$this->assertEqual(Debugger::trimPath(CAKE_CORE_INCLUDE_PATH), 'CORE');
}
function testTrimPath() {
$this->assertEqual(Debugger::trimPath(APP), 'APP/');
$this->assertEqual(Debugger::trimPath(CAKE_CORE_INCLUDE_PATH), 'CORE');
}
function testExportVar() {
App::import('Controller');

View file

@ -65,7 +65,7 @@ class NumberTree extends CakeTestModel {
}
class FlagTree extends NumberTree {
var $name = 'FlagTree';
var $name = 'FlagTree';
}
class Campaign extends CakeTestModel {
@ -124,7 +124,7 @@ class NumberTreeCase extends CakeTestCase {
$this->assertEqual($this->FlagTree->find('count'), 11);
}
function testArrayScope() {
function testArrayScope() {
$this->FlagTree =& new FlagTree();
$this->FlagTree->__initialize(2, 3);
@ -155,7 +155,7 @@ class NumberTreeCase extends CakeTestCase {
$this->assertEqual($this->FlagTree->find('count'), 11);
}
function testDetectInvalidLeft() {
function testDetectInvalidLeft() {
$this->NumberTree =& new NumberTree();
$this->NumberTree->__initialize(2, 2);

View file

@ -195,7 +195,7 @@ class DboMysqlTest extends CakeTestCase {
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
$this->model = new CakeTestModel(array(
'name' => 'Tinyint', 'table' => $this->db->fullTableName('tinyint', false)
'name' => 'Tinyint', 'table' => $this->db->fullTableName('tinyint', false)
));
$result = $this->model->schema();
$this->assertEqual($result['bool']['type'], 'boolean');

View file

@ -42,8 +42,8 @@ if (!class_exists('RequestActionController')) {
}
class TestObject extends Object {
var $firstName = 'Joel';
var $lastName = 'Moss';
var $firstName = 'Joel';
var $lastName = 'Moss';
var $methodCalls = array();
function emptyMethod() {
@ -92,10 +92,10 @@ class ObjectTest extends UnitTestCase {
$this->object = new TestObject();
}
function testLog() {
@unlink(LOGS . 'error.log');
$this->assertTrue($this->object->log('Test warning 1'));
$this->assertTrue($this->object->log(array('Test' => 'warning 2')));
function testLog() {
@unlink(LOGS . 'error.log');
$this->assertTrue($this->object->log('Test warning 1'));
$this->assertTrue($this->object->log(array('Test' => 'warning 2')));
$result = file(LOGS . 'error.log');
$this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Test warning 1$/', $result[0]);
$this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Array$/', $result[1]);
@ -103,7 +103,7 @@ class ObjectTest extends UnitTestCase {
$this->assertPattern('/\[Test\] => warning 2$/', $result[3]);
$this->assertPattern('/^\)$/', $result[4]);
unlink(LOGS . 'error.log');
@unlink(LOGS . 'error.log');
$this->assertTrue($this->object->log('Test warning 1', LOG_WARNING));
$this->assertTrue($this->object->log(array('Test' => 'warning 2'), LOG_WARNING));