Permalink
Browse files

Fix most coding standard issues in Controller.

  • Loading branch information...
1 parent db8c6b5 commit 61aba0f0f88af9be51027e83cfcc75f800b609cc @markstory markstory committed Mar 4, 2012
View
1 lib/Cake/Controller/CakeErrorController.php
@@ -75,4 +75,5 @@ public function beforeRender() {
}
}
}
+
}
View
15 lib/Cake/Controller/Component.php
@@ -106,7 +106,8 @@ public function __get($name) {
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize
*/
- public function initialize(Controller $controller) { }
+ public function initialize(Controller $controller) {
+ }
/**
* Called after the Controller::beforeFilter() and before the controller action
@@ -115,7 +116,8 @@ public function initialize(Controller $controller) { }
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup
*/
- public function startup(Controller $controller) { }
+ public function startup(Controller $controller) {
+ }
/**
* Called after the Controller::beforeRender(), after the view class is loaded, and before the
@@ -125,7 +127,8 @@ public function startup(Controller $controller) { }
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRender
*/
- public function beforeRender(Controller $controller) { }
+ public function beforeRender(Controller $controller) {
+ }
/**
* Called after Controller::render() and before the output is printed to the browser.
@@ -134,7 +137,8 @@ public function beforeRender(Controller $controller) { }
* @return void
* @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::shutdown
*/
- public function shutdown(Controller $controller) { }
+ public function shutdown(Controller $controller) {
+ }
/**
* Called before Controller::redirect(). Allows you to replace the url that will
@@ -155,6 +159,7 @@ public function shutdown(Controller $controller) { }
* @return array|null Either an array or null.
* @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect
*/
- public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {}
+ public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {
+ }
}
View
1 lib/Cake/Controller/Component/Acl/AclInterface.php
@@ -66,4 +66,5 @@ public function inherit($aro, $aco, $action = "*");
* @param AclComponent $component
*/
public function initialize(Component $component);
+
}
View
4 lib/Cake/Controller/Component/Acl/DbAcl.php
@@ -94,7 +94,7 @@ public function check($aro, $aco, $action = "*") {
$acoIDs = Set::extract($acoPath, '{n}.' . $this->Aco->alias . '.id');
$count = count($aroPath);
- for ($i = 0 ; $i < $count; $i++) {
+ for ($i = 0; $i < $count; $i++) {
$permAlias = $this->Aro->Permission->alias;
$perms = $this->Aro->Permission->find('all', array(
@@ -289,5 +289,5 @@ protected function _getAcoKeys($keys) {
}
return $newKeys;
}
-}
+}
View
12 lib/Cake/Controller/Component/Acl/IniAcl.php
@@ -45,7 +45,6 @@ class IniAcl extends Object implements AclInterface {
* @return void
*/
public function initialize(Component $component) {
-
}
/**
@@ -57,7 +56,6 @@ public function initialize(Component $component) {
* @return boolean Success
*/
public function allow($aro, $aco, $action = "*") {
-
}
/**
@@ -69,7 +67,6 @@ public function allow($aro, $aco, $action = "*") {
* @return boolean Success
*/
public function deny($aro, $aco, $action = "*") {
-
}
/**
@@ -81,7 +78,6 @@ public function deny($aro, $aco, $action = "*") {
* @return boolean Success
*/
public function inherit($aro, $aco, $action = "*") {
-
}
/**
@@ -91,10 +87,10 @@ public function inherit($aro, $aco, $action = "*") {
*
* @param string $aro ARO
* @param string $aco ACO
- * @param string $aco_action Action
+ * @param string $action Action
* @return boolean Success
*/
- public function check($aro, $aco, $aco_action = null) {
+ public function check($aro, $aco, $action = null) {
if ($this->config == null) {
$this->config = $this->readConfigFile(APP . 'Config' . DS . 'acl.ini.php');
}
@@ -147,7 +143,8 @@ public function check($aro, $aco, $aco_action = null) {
}
/**
- * Parses an INI file and returns an array that reflects the INI file's section structure. Double-quote friendly.
+ * Parses an INI file and returns an array that reflects the
+ * INI file's section structure. Double-quote friendly.
*
* @param string $filename File
* @return array INI section structure
@@ -171,4 +168,5 @@ public function arrayTrim($array) {
array_unshift($array, "");
return $array;
}
+
}
View
93 lib/Cake/Controller/Component/Acl/PhpAcl.php
@@ -37,7 +37,6 @@ class PhpAcl extends Object implements AclInterface {
*/
public $options = array();
-
/**
* Aro Object
*
@@ -52,13 +51,18 @@ class PhpAcl extends Object implements AclInterface {
*/
public $Aco = null;
-
+/**
+ * Constructor
+ *
+ * Sets a few default settings up.
+ */
public function __construct() {
$this->options = array(
'policy' => self::DENY,
'config' => APP . 'Config' . DS . 'acl.php',
);
}
+
/**
* Initialize method
*
@@ -69,7 +73,7 @@ public function initialize(Component $Component) {
if (!empty($Component->settings['adapter'])) {
$this->options = array_merge($this->options, $Component->settings['adapter']);
}
-
+
App::uses('PhpReader', 'Configure');
$Reader = new PhpReader(dirname($this->options['config']) . DS);
$config = $Reader->read(basename($this->options['config']));
@@ -83,6 +87,7 @@ public function initialize(Component $Component) {
*
* @param array $config configuration array, see docs
* @return void
+ * @throws AclException When required keys are missing.
*/
public function build(array $config) {
if (empty($config['roles'])) {
@@ -145,19 +150,19 @@ public function inherit($aro, $aco, $action = "*") {
*
* @param string $aro ARO
* @param string $aco ACO
- * @param string $aco_action Action
+ * @param string $action Action
* @return boolean true if access is granted, false otherwise
*/
- public function check($aro, $aco, $aco_action = "*") {
+ public function check($aro, $aco, $action = "*") {
$allow = $this->options['policy'];
$prioritizedAros = $this->Aro->roles($aro);
- if ($aco_action && $aco_action != "*") {
- $aco .= '/' . $aco_action;
+ if ($action && $action != "*") {
+ $aco .= '/' . $action;
}
- $path = $this->Aco->path($aco);
-
+ $path = $this->Aco->path($aco);
+
if (empty($path)) {
return $allow;
}
@@ -176,6 +181,7 @@ public function check($aro, $aco, $aco_action = "*") {
return $allow;
}
+
}
/**
@@ -189,7 +195,7 @@ class PhpAco {
*
* @var array
*/
- protected $tree = array();
+ protected $_tree = array();
/**
* map modifiers for ACO paths to their respective PCRE pattern
@@ -219,9 +225,9 @@ public function path($aco) {
$aco = $this->resolve($aco);
$path = array();
$level = 0;
- $root = $this->tree;
+ $root = $this->_tree;
$stack = array(array($root, 0));
-
+
while (!empty($stack)) {
list($root, $level) = array_pop($stack);
@@ -230,16 +236,15 @@ public function path($aco) {
}
foreach ($root as $node => $elements) {
- $pattern = '/^'.str_replace(array_keys(self::$modifiers), array_values(self::$modifiers), $node).'$/';
-
+ $pattern = '/^' . str_replace(array_keys(self::$modifiers), array_values(self::$modifiers), $node) . '$/';
+
if ($node == $aco[$level] || preg_match($pattern, $aco[$level])) {
// merge allow/denies with $path of current level
foreach (array('allow', 'deny') as $policy) {
if (!empty($elements[$policy])) {
if (empty($path[$level][$policy])) {
$path[$level][$policy] = array();
}
-
$path[$level][$policy] = array_merge($path[$level][$policy], $elements[$policy]);
}
}
@@ -248,14 +253,13 @@ public function path($aco) {
if (!empty($elements['children']) && isset($aco[$level + 1])) {
array_push($stack, array($elements['children'], $level + 1));
}
- }
+ }
}
}
return $path;
}
-
/**
* allow/deny ARO access to ARO
*
@@ -264,7 +268,7 @@ public function path($aco) {
public function access($aro, $aco, $action, $type = 'deny') {
$aco = $this->resolve($aco);
$depth = count($aco);
- $root = $this->tree;
+ $root = $this->_tree;
$tree = &$root;
foreach ($aco as $i => $node) {
@@ -280,12 +284,12 @@ public function access($aro, $aco, $action, $type = 'deny') {
if (empty($tree[$node][$type])) {
$tree[$node][$type] = array();
}
-
+
$tree[$node][$type] = array_merge(is_array($aro) ? $aro : array($aro), $tree[$node][$type]);
}
}
- $this->tree = &$root;
+ $this->_tree = &$root;
}
/**
@@ -315,7 +319,7 @@ public function resolve($aco) {
*/
public function build(array $allow, array $deny = array()) {
$stack = array();
- $this->tree = array();
+ $this->_tree = array();
$tree = array();
$root = &$tree;
@@ -326,7 +330,7 @@ public function build(array $allow, array $deny = array()) {
$this->access($aros, $dotPath, null, 'allow');
}
-
+
foreach ($deny as $dotPath => $aros) {
if (is_string($aros)) {
$aros = array_map('trim', explode(',', $aros));
@@ -336,7 +340,6 @@ public function build(array $allow, array $deny = array()) {
}
}
-
}
/**
@@ -382,7 +385,7 @@ class PhpAro {
*
* @var array
*/
- protected $tree = array();
+ protected $_tree = array();
public function __construct(array $aro = array(), array $map = array(), array $aliases = array()) {
if (!empty($map)) {
@@ -393,7 +396,6 @@ public function __construct(array $aro = array(), array $map = array(), array $a
$this->build($aro);
}
-
/**
* From the perspective of the given ARO, walk down the tree and
* collect all inherited AROs levelwise such that AROs from different
@@ -413,7 +415,7 @@ public function roles($aro) {
list($element, $depth) = array_pop($stack);
$aros[$depth][] = $element;
- foreach ($this->tree as $node => $children) {
+ foreach ($this->_tree as $node => $children) {
if (in_array($element, $children)) {
array_push($stack, array($node, $depth + 1));
}
@@ -423,7 +425,6 @@ public function roles($aro) {
return array_reverse($aros);
}
-
/**
* resolve an ARO identifier to an internal ARO string using
* the internal mapping information.
@@ -438,7 +439,7 @@ public function resolve($aro) {
if (is_array($aro)) {
if (isset($aro['model']) && isset($aro['foreign_key']) && $aro['model'] == $aroGroup) {
- $mapped = $aroGroup . '/' . $aro['foreign_key'];
+ $mapped = $aroGroup . '/' . $aro['foreign_key'];
} elseif (isset($aro[$model][$field])) {
$mapped = $aroGroup . '/' . $aro[$model][$field];
} elseif (isset($aro[$field])) {
@@ -450,7 +451,7 @@ public function resolve($aro) {
if (strpos($aro, '/') === false) {
$mapped = $aroGroup . '/' . $aro;
} else {
- list($aroModel, $aroValue) = explode('/', $aro, 2);
+ list($aroModel, $aroValue) = explode('/', $aro, 2);
$aroModel = Inflector::camelize($aroModel);
@@ -459,22 +460,19 @@ public function resolve($aro) {
}
}
}
-
- if (isset($this->tree[$mapped])) {
+
+ if (isset($this->_tree[$mapped])) {
return $mapped;
}
-
+
// is there a matching alias defined (e.g. Role/1 => Role/admin)?
if (!empty($this->aliases[$mapped])) {
return $this->aliases[$mapped];
}
-
}
-
return self::DEFAULT_ROLE;
}
-
/**
* adds a new ARO to the tree
*
@@ -483,35 +481,35 @@ public function resolve($aro) {
*/
public function addRole(array $aro) {
foreach ($aro as $role => $inheritedRoles) {
- if (!isset($this->tree[$role])) {
- $this->tree[$role] = array();
+ if (!isset($this->_tree[$role])) {
+ $this->_tree[$role] = array();
}
if (!empty($inheritedRoles)) {
if (is_string($inheritedRoles)) {
$inheritedRoles = array_map('trim', explode(',', $inheritedRoles));
- }
-
+ }
+
foreach ($inheritedRoles as $dependency) {
// detect cycles
$roles = $this->roles($dependency);
-
+
if (in_array($role, Set::flatten($roles))) {
$path = '';
foreach ($roles as $roleDependencies) {
$path .= implode('|', (array)$roleDependencies) . ' -> ';
}
- trigger_error(__d('cake_dev', 'cycle detected when inheriting %s from %s. Path: %s', $role, $dependency, $path.$role));
+ trigger_error(__d('cake_dev', 'cycle detected when inheriting %s from %s. Path: %s', $role, $dependency, $path . $role));
continue;
}
-
- if (!isset($this->tree[$dependency])) {
- $this->tree[$dependency] = array();
+
+ if (!isset($this->_tree[$dependency])) {
+ $this->_tree[$dependency] = array();
}
-
- $this->tree[$dependency][] = $role;
+
+ $this->_tree[$dependency][] = $role;
}
}
}
@@ -534,7 +532,8 @@ public function addAlias(array $alias) {
* @return void
*/
public function build(array $aros) {
- $this->tree = array();
+ $this->_tree = array();
$this->addRole($aros);
}
+
}
View
3 lib/Cake/Controller/Component/AclComponent.php
@@ -177,6 +177,5 @@ public function revoke($aro, $aco, $action = "*") {
trigger_error(__d('cake_dev', 'AclComponent::revoke() is deprecated, use deny() instead'), E_USER_WARNING);
return $this->_Instance->deny($aro, $aco, $action);
}
-}
-
+}
View
1 lib/Cake/Controller/Component/Auth/ActionsAuthorize.php
@@ -38,4 +38,5 @@ public function authorize($user, CakeRequest $request) {
$user = array($this->settings['userModel'] => $user);
return $Acl->check($user, $this->action($request));
}
+
}
View
4 lib/Cake/Controller/Component/Auth/BaseAuthenticate.php
@@ -121,7 +121,8 @@ protected function _password($password) {
* @param array $user The user about to be logged out.
* @return void
*/
- public function logout($user) { }
+ public function logout($user) {
+ }
/**
* Get a user based on information in the request. Primarily used by stateless authentication
@@ -133,4 +134,5 @@ public function logout($user) { }
public function getUser($request) {
return false;
}
+
}
View
2 lib/Cake/Controller/Component/Auth/BaseAuthorize.php
@@ -21,6 +21,7 @@
* @see AuthComponent::$authenticate
*/
abstract class BaseAuthorize {
+
/**
* Controller for the request.
*
@@ -156,4 +157,5 @@ public function mapActions($map = array()) {
}
}
}
+
}
View
4 lib/Cake/Controller/Component/Auth/BasicAuthenticate.php
@@ -41,6 +41,7 @@
* @since 2.0
*/
class BasicAuthenticate extends BaseAuthenticate {
+
/**
* Settings for this object.
*
@@ -121,4 +122,5 @@ public function getUser($request) {
public function loginHeaders() {
return sprintf('WWW-Authenticate: Basic realm="%s"', $this->settings['realm']);
}
-}
+
+}
View
4 lib/Cake/Controller/Component/Auth/ControllerAuthorize.php
@@ -61,7 +61,7 @@ public function controller(Controller $controller = null) {
* @return boolean
*/
public function authorize($user, CakeRequest $request) {
- return (bool) $this->_Controller->isAuthorized($user);
+ return (bool)$this->_Controller->isAuthorized($user);
}
-}
+}
View
1 lib/Cake/Controller/Component/Auth/CrudAuthorize.php
@@ -98,4 +98,5 @@ public function authorize($user, CakeRequest $request) {
$this->settings['actionMap'][$request->params['action']]
);
}
+
}
View
7 lib/Cake/Controller/Component/Auth/DigestAuthenticate.php
@@ -55,6 +55,7 @@
* @since 2.0
*/
class DigestAuthenticate extends BaseAuthenticate {
+
/**
* Settings for this object.
*
@@ -65,7 +66,8 @@ class DigestAuthenticate extends BaseAuthenticate {
* - `realm` The realm authentication is for, Defaults to the servername.
* - `nonce` A nonce used for authentication. Defaults to `uniqid()`.
* - `qop` Defaults to auth, no other values are supported at this time.
- * - `opaque` A string that must be returned unchanged by clients. Defaults to `md5($settings['realm'])`
+ * - `opaque` A string that must be returned unchanged by clients.
+ * Defaults to `md5($settings['realm'])`
*
* @var array
*/
@@ -261,4 +263,5 @@ public function loginHeaders() {
}
return 'WWW-Authenticate: Digest ' . implode(',', $opts);
}
-}
+
+}
View
1 lib/Cake/Controller/Component/AuthComponent.php
@@ -718,4 +718,5 @@ public function loggedIn() {
public function flash($message) {
$this->Session->setFlash($message, $this->flash['element'], $this->flash['params'], $this->flash['key']);
}
+
}
View
3 lib/Cake/Controller/Component/CookieComponent.php
@@ -431,7 +431,7 @@ protected function _encrypt($value) {
if ($this->_encrypted === true) {
$type = $this->_type;
- $value = "Q2FrZQ==." .base64_encode(Security::$type($value, $this->key));
+ $value = "Q2FrZQ==." . base64_encode(Security::$type($value, $this->key));
}
return $value;
}
@@ -503,4 +503,5 @@ protected function _explode($string) {
}
return $array;
}
+
}
View
5 lib/Cake/Controller/Component/PaginatorComponent.php
@@ -223,7 +223,7 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
protected function _getObject($object) {
if (is_string($object)) {
$assoc = null;
- if (strpos($object, '.') !== false) {
+ if (strpos($object, '.') !== false) {
list($object, $assoc) = pluginSplit($object);
}
@@ -370,11 +370,12 @@ public function validateSort($object, $options, $whitelist = array()) {
* @return array An array of options for pagination
*/
public function checkLimit($options) {
- $options['limit'] = (int) $options['limit'];
+ $options['limit'] = (int)$options['limit'];
if (empty($options['limit']) || $options['limit'] < 1) {
$options['limit'] = 1;
}
$options['limit'] = min((int)$options['limit'], $options['maxLimit']);
return $options;
}
+
}
View
4 lib/Cake/Controller/Component/RequestHandlerComponent.php
@@ -210,9 +210,9 @@ public function convertXml($xml) {
return Xml::toArray($xml->data);
}
return Xml::toArray($xml);
- } catch (XmlException $e) {
+ } catch (XmlException $e) {
return array();
- }
+ }
}
/**
View
7 lib/Cake/Controller/Component/SecurityComponent.php
@@ -394,9 +394,9 @@ protected function _authRequired(Controller $controller) {
$tData = $this->Session->read('_Token');
if (
- !empty($tData['allowedControllers']) &&
- !in_array($this->request->params['controller'], $tData['allowedControllers']) ||
- !empty($tData['allowedActions']) &&
+ !empty($tData['allowedControllers']) &&
+ !in_array($this->request->params['controller'], $tData['allowedControllers']) ||
+ !empty($tData['allowedActions']) &&
!in_array($this->request->params['action'], $tData['allowedActions'])
) {
if (!$this->blackHole($controller, 'auth')) {
@@ -592,4 +592,5 @@ protected function _callback(Controller $controller, $method, $params = array())
return null;
}
}
+
}
View
3 lib/Cake/Controller/ComponentCollection.php
@@ -124,4 +124,5 @@ public function implementedEvents() {
'Controller.shutdown' => array('callable' => 'trigger'),
);
}
-}
+
+}
View
17 lib/Cake/Controller/Controller.php
@@ -1,9 +1,5 @@
<?php
/**
- * Base controller class.
- *
- * PHP 5
- *
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -145,7 +141,6 @@ class Controller extends Object implements CakeEventListener {
*/
public $viewVars = array();
-
/**
* The name of the view file to render. The name specified
* is the filename in /app/View/<SubFolder> without the .ctp extension.
@@ -321,7 +316,7 @@ class Controller extends Object implements CakeEventListener {
*/
public function __construct($request = null, $response = null) {
if ($this->name === null) {
- $this->name = substr(get_class($this), 0, strlen(get_class($this)) -10);
+ $this->name = substr(get_class($this), 0, strlen(get_class($this)) - 10);
}
if ($this->viewPath == null) {
@@ -476,7 +471,9 @@ public function setRequest(CakeRequest $request) {
*
* @param CakeRequest $request
* @return mixed The resulting response.
- * @throws PrivateActionException, MissingActionException
+ * @throws PrivateActionException When actions are not public or prefixed by _
+ * @throws MissingActionException When actions are not defined and scaffolding is
+ * not enabled.
*/
public function invokeAction(CakeRequest $request) {
try {
@@ -640,7 +637,7 @@ public function constructClasses() {
$this->_mergeControllerVars();
$this->Components->init($this);
if ($this->uses) {
- $this->uses = (array) $this->uses;
+ $this->uses = (array)$this->uses;
list(, $this->modelClass) = pluginSplit(current($this->uses));
}
return true;
@@ -1062,10 +1059,10 @@ public function postConditions($data = array(), $op = null, $bool = 'AND', $excl
}
$fieldOp = strtoupper(trim($fieldOp));
if ($fieldOp === 'LIKE') {
- $key = $key.' LIKE';
+ $key = $key . ' LIKE';
$value = '%' . $value . '%';
} elseif ($fieldOp && $fieldOp != '=') {
- $key = $key.' ' . $fieldOp;
+ $key = $key . ' ' . $fieldOp;
}
$cond[$key] = $value;
}
View
10 lib/Cake/Controller/Scaffold.php
@@ -125,7 +125,7 @@ public function __construct(Controller $controller, CakeRequest $request) {
$this->ScaffoldModel = $this->controller->{$this->modelClass};
$this->scaffoldTitle = Inflector::humanize(Inflector::underscore($this->viewPath));
$this->scaffoldActions = $controller->scaffold;
- $title_for_layout = __d('cake', 'Scaffold :: ') . Inflector::humanize($request->action) . ' :: ' . $this->scaffoldTitle;
+ $title = __d('cake', 'Scaffold :: ') . Inflector::humanize($request->action) . ' :: ' . $this->scaffoldTitle;
$modelClass = $this->controller->modelClass;
$primaryKey = $this->ScaffoldModel->primaryKey;
$displayField = $this->ScaffoldModel->displayField;
@@ -140,6 +140,7 @@ public function __construct(Controller $controller, CakeRequest $request) {
'title_for_layout', 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'
));
+ $this->set('title_for_layout', $title);
if ($this->controller->viewClass) {
$this->controller->viewClass = 'Scaffold';
@@ -287,7 +288,8 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
*
* @param CakeRequest $request Request for scaffolding
* @return mixed Success on delete, error if delete fails
- * @throws MethodNotAllowedException, NotFoundException
+ * @throws MethodNotAllowedException When HTTP method is not a DELETE
+ * @throws NotFoundException When id being deleted does not exist.
*/
protected function _scaffoldDelete(CakeRequest $request) {
if ($this->controller->beforeScaffold('delete')) {
@@ -350,7 +352,8 @@ protected function _scaffoldError() {
*
* @param CakeRequest $request Request object for scaffolding
* @return mixed A rendered view of scaffold action, or showing the error
- * @throws MissingActionException, MissingDatabaseException
+ * @throws MissingActionException When methods are not scaffolded.
+ * @throws MissingDatabaseException When the database connection is undefined.
*/
protected function _scaffold(CakeRequest $request) {
$db = ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
@@ -440,4 +443,5 @@ protected function _associations() {
}
return $associations;
}
+
}

0 comments on commit 61aba0f

Please sign in to comment.