diff --git a/.codeclimate.yml b/.codeclimate.yml index ab1fe5dd4..32a42ef61 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -64,6 +64,8 @@ plugins: enabled: false UnusedFormalParameter: enabled: false + Design/LongClass: + enabled: false Design/TooManyFields: enabled: false Design/TooManyMethods: diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index cccb7e3b0..d8a839fb2 100755 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -97,7 +97,7 @@ class e_admin_request */ public function __construct($request_string = null, $parse = true) { - if(null === $request_string) + if($request_string === null) { $request_string = str_replace('&', '&', e_QUERY); } @@ -123,13 +123,13 @@ class e_admin_request // Set current mode if(isset($this->_request_qry[$this->_mode_key])) { - $this->_mode = preg_replace('/[^\w]/', '', $this->_request_qry[$this->_mode_key]); + $this->_mode = preg_replace('/[\W]/', '', $this->_request_qry[$this->_mode_key]); } // Set current action if(isset($this->_request_qry[$this->_action_key])) { - $this->_action = preg_replace('/[^\w]/', '', $this->_request_qry[$this->_action_key]); + $this->_action = preg_replace('/[\W]/', '', $this->_request_qry[$this->_action_key]); } // Set current id @@ -153,7 +153,7 @@ class e_admin_request */ public function getQuery($key = null, $default = null) { - if(null === $key) + if($key === null) { return $this->_request_qry; } @@ -180,10 +180,10 @@ class e_admin_request return $this; } - if(null === $value) + if($value === null) { - unset($this->_request_qry[$key]); - unset($_GET[$key]); + unset($this->_request_qry[$key], $_GET[$key]); + return $this; } @@ -202,7 +202,7 @@ class e_admin_request */ public function getPosted($key = null, $default = null) { - if(null === $key) + if($key === null) { return $this->_posted_qry; } @@ -234,7 +234,7 @@ class e_admin_request return $this; } - if(null === $value) + if($value === null) { unset($this->_posted_qry[$key]); return $this; @@ -251,7 +251,10 @@ class e_admin_request */ public function getMode() { - if(!$this->_mode) return $this->getDefaultMode(); + if(!$this->_mode) + { + return $this->getDefaultMode(); + } return $this->_mode; } @@ -281,7 +284,7 @@ class e_admin_request */ public function setMode($mode) { - $this->_mode = preg_replace('/[^\w]/', '', $mode); + $this->_mode = preg_replace('/[\W]/', '', $mode); $this->setQuery($this->_mode_key, $this->_mode); return $this; } @@ -293,7 +296,10 @@ class e_admin_request */ public function setDefaultMode($mode) { - if($mode) $this->_default_mode = $mode; + if($mode) + { + $this->_default_mode = $mode; + } return $this; } @@ -314,7 +320,10 @@ class e_admin_request */ public function getAction() { - if(!$this->_action) return $this->getDefaultAction(); + if(!$this->_action) + { + return $this->getDefaultAction(); + } return $this->_action; } @@ -344,7 +353,7 @@ class e_admin_request */ public function setAction($action) { - $this->_action = preg_replace('/[^\w]/', '', $action); + $this->_action = preg_replace('/[\W]/', '', $action); $this->setQuery($this->_action_key, $this->_action); return $this; } @@ -357,7 +366,10 @@ class e_admin_request */ public function setDefaultAction($action) { - if($action) $this->_default_action = $action; + if($action) + { + $this->_default_action = $action; + } return $this; } @@ -388,7 +400,7 @@ class e_admin_request */ public function setId($id) { - $id = intval($id); + $id = (int) $id; $this->_id = $id; $this->setQuery($this->_id_key, $id); return $this; @@ -420,7 +432,7 @@ class e_admin_request $ret = $this->getQuery(); //special case - exclude all current - if(true === $exclude_from_query) + if($exclude_from_query === true) { $exclude_from_query = array_keys($ret); } @@ -433,7 +445,10 @@ class e_admin_request { foreach ($exclude_from_query as $var) { - if($keepSpecial && $var != $this->_action_key && $var != $this->_mode_key) unset($ret[$var]); + if($keepSpecial && $var != $this->_action_key && $var != $this->_mode_key) + { + unset($ret[$var]); + } } } @@ -546,7 +561,7 @@ class e_admin_response * @param string $namespace segment namesapce * @return e_admin_response */ - function setBody($content, $namespace = 'default') + public function setBody($content, $namespace = 'default') { $this->_body[$namespace] = $content; return $this; @@ -559,7 +574,7 @@ class e_admin_response * @param string $namespace segment namesapce * @return e_admin_response */ - function appendBody($content, $namespace = 'default') + public function appendBody($content, $namespace = 'default') { if(!isset($this->_body[$namespace])) { @@ -576,7 +591,7 @@ class e_admin_response * @param string $namespace segment namespace * @return e_admin_response */ - function prependBody($content, $namespace = 'default') + public function prependBody($content, $namespace = 'default') { if(!isset($this->_body[$namespace])) { @@ -594,7 +609,7 @@ class e_admin_response * @param string|boolean $glue if false return array, else return string * @return string|array */ - function getBody($namespace = 'default', $reset = false, $glue = '') + public function getBody($namespace = 'default', $reset = false, $glue = '') { $content = vartrue($this->_body[$namespace], array()); if($reset) @@ -615,7 +630,7 @@ class e_admin_response * @param string $namespace * @return e_admin_response */ - function setTitle($title, $namespace = 'default') + public function setTitle($title, $namespace = 'default') { $this->_title[$namespace] = array($title); return $this; @@ -628,7 +643,7 @@ class e_admin_response * @param string $namespace segment namesapce * @return e_admin_response */ - function appendTitle($title, $namespace = 'default') + public function appendTitle($title, $namespace = 'default') { if(empty($title)) { @@ -649,7 +664,7 @@ class e_admin_response * @param string $namespace segment namespace * @return e_admin_response */ - function prependTitle($title, $namespace = 'default') + public function prependTitle($title, $namespace = 'default') { if(empty($title)) { @@ -671,7 +686,7 @@ class e_admin_response * @param boolean|string $glue * @return string|array */ - function getTitle($namespace = 'default', $reset = false, $glue = ' ') + public function getTitle($namespace = 'default', $reset = false, $glue = ' ') { $content = array(); @@ -701,7 +716,7 @@ class e_admin_response * @param string $namespace * @return e_admin_response */ - function setRenderMod($render_mod, $namespace = 'default') + public function setRenderMod($render_mod, $namespace = 'default') { $this->_render_mod[$namespace] = $render_mod; return $this; @@ -713,7 +728,7 @@ class e_admin_response * @param string $namespace * @return string */ - function getRenderMod($namespace = 'default') + public function getRenderMod($namespace = 'default') { return varset($this->_render_mod[$namespace], null); } @@ -725,7 +740,7 @@ class e_admin_response * @param string $content meta content * @return e_admin_response */ - function addMetaData($meta, $content) + public function addMetaData($meta, $content) { $tp = e107::getParser(); $meta = '_' . $meta; @@ -742,7 +757,7 @@ class e_admin_response * @param string $title * @return e_admin_response */ - function addMetaTitle($title) + public function addMetaTitle($title) { $this->addMetaData('e_PAGETITLE', $title); return $this; @@ -754,7 +769,7 @@ class e_admin_response * @param string $description * @return e_admin_response */ - function addMetaDescription($description) + public function addMetaDescription($description) { $this->addMetaData('META_DESCRIPTION', $description); return $this; @@ -766,7 +781,7 @@ class e_admin_response * @param string $keyword * @return e_admin_response */ - function addMetaKeywords($keyword) + public function addMetaKeywords($keyword) { $this->addMetaData('META_KEYWORDS', $keyword); return $this; @@ -777,11 +792,13 @@ class e_admin_response * * @return e_admin_response */ - function sendMeta() + public function sendMeta() { //HEADERF already included or meta content already sent if(e_AJAX_REQUEST || defined('HEADER_INIT') || defined('e_PAGETITLE')) + { return $this; + } if(!defined('e_PAGETITLE') && !empty($this->_e_PAGETITLE)) { @@ -805,7 +822,7 @@ class e_admin_response * @param string $content * @return e_admin_response */ - function addHeaderContent($content) + public function addHeaderContent($content) { $this->appendBody($content, 'header_content'); return $this; @@ -818,7 +835,7 @@ class e_admin_response * @param boolean $glue * @return string */ - function getHeaderContent($reset = true, $glue = "\n\n") + public function getHeaderContent($reset = true, $glue = "\n\n") { return $this->getBody('header_content', $reset, $glue); } @@ -829,11 +846,13 @@ class e_admin_response * * @return e_admin_response */ - function setIframeMod() + public function setIframeMod() { global $HEADER, $FOOTER, $CUSTOMHEADER, $CUSTOMFOOTER; - $HEADER = $FOOTER = ''; - $CUSTOMHEADER = $CUSTOMFOOTER = array(); + $FOOTER = ''; + $HEADER = $FOOTER; + $CUSTOMFOOTER = array(); + $CUSTOMHEADER = $CUSTOMFOOTER; //TODO generic $_GET to activate for any page of admin. // New if(!defined('e_IFRAME')) @@ -850,7 +869,7 @@ class e_admin_response * @param array $options valid keys are: messages|render|meta|return|raw|ajax * @return mixed */ - function send($name = 'default', $options = array()) + public function send($name = 'default', $options = array()) { if(is_string($options)) { @@ -933,17 +952,17 @@ class e_admin_dispatcher /** * @var e_admin_request */ - protected $_request = null; + protected $_request; /** * @var e_admin_response */ - protected $_response = null; + protected $_response; /** * @var e_admin_controller */ - protected $_current_controller = null; + protected $_current_controller; /** * Required (set by child class). @@ -1001,7 +1020,7 @@ class e_admin_dispatcher protected $adminMenu = array(); - protected $adminMenuIcon = null; + protected $adminMenuIcon; /** * Optional (set by child class). * Page titles for pages not in adminMenu (e.g. main/edit) @@ -1044,12 +1063,12 @@ class e_admin_dispatcher require_once(e_ADMIN.'boot.php'); - if(null === $request || !is_object($request)) + if($request === null || !is_object($request)) { $request = new e_admin_request($request); } - if(null === $response) + if($response === null) { $response = new e_admin_response(); } @@ -1083,7 +1102,7 @@ class e_admin_dispatcher if($auto_observe) { - $this->runObservers(true); + $this->runObservers(); } } @@ -1140,7 +1159,7 @@ class e_admin_dispatcher } // generic dispatcher admin permission (former getperms()) - if(null !== $this->perm && is_string($this->perm) && !e107::getUser()->checkAdminPerms($this->perm)) + if($this->perm !== null && is_string($this->perm) && !e107::getUser()->checkAdminPerms($this->perm)) { return false; } @@ -1152,13 +1171,13 @@ class e_admin_dispatcher { if(isset($this->access[$route]) && !e107::getUser()->checkClass($this->access[$route], false)) { - e107::getMessage()->addDebug("Userclass Permissions Failed: ".$this->access[$route]); + e107::getMessage()->addDebug('Userclass Permissions Failed: ' .$this->access[$route]); return false; } if(is_array($this->perm) && isset($this->perm[$route]) && !e107::getUser()->checkAdminPerms($this->perm[$route])) { - e107::getMessage()->addDebug("Admin Permissions Failed.".$this->perm[$route]); + e107::getMessage()->addDebug('Admin Permissions Failed.' .$this->perm[$route]); return false; } @@ -1188,8 +1207,14 @@ class e_admin_dispatcher - if(!$this->defaultMode) $this->defaultMode = $mode; - if(!$this->defaultAction) $this->defaultAction = $action; + if(!$this->defaultMode) + { + $this->defaultMode = $mode; + } + if(!$this->defaultAction) + { + $this->defaultAction = $action; + } return $this; } @@ -1417,7 +1442,7 @@ class e_admin_dispatcher */ public function getController() { - if(null === $this->_current_controller) + if($this->_current_controller === null) { $this->_initController(); } @@ -1517,7 +1542,7 @@ class e_admin_dispatcher * Generic Admin Menu Generator * @return string */ - function renderMenu() + public function renderMenu() { $tp = e107::getParser(); @@ -1541,7 +1566,10 @@ class e_admin_dispatcher } // custom 'selected' check - if(isset($val['selected']) && $val['selected']) $selected = $val['selected'] === true ? $key : $val['selected']; + if(isset($val['selected']) && $val['selected']) + { + $selected = $val['selected'] === true ? $key : $val['selected']; + } foreach ($val as $k=>$v) { @@ -1563,7 +1591,7 @@ class e_admin_dispatcher $k2 = 'link'; $v = $tp->replaceConstants($v, 'abs'); - if(!empty($v) && (e_REQUEST_URI === $v)) + if(!empty($v) && ($v === e_REQUEST_URI)) { $selected = $key; } @@ -1611,7 +1639,7 @@ class e_admin_dispatcher if(varset($val['tab'])) { - $var[$key]['link'] .= "&tab=".$val['tab']; + $var[$key]['link'] .= '&tab=' .$val['tab']; } /*$var[$key]['text'] = $val['caption']; @@ -1630,10 +1658,16 @@ class e_admin_dispatcher } - if(empty($var)) return ''; + if(empty($var)) + { + return ''; + } $request = $this->getRequest(); - if(!$selected) $selected = $request->getMode().'/'.$request->getAction(); + if(!$selected) + { + $selected = $request->getMode() . '/' . $request->getAction(); + } $selected = vartrue($this->adminMenuAliases[$selected], $selected); $icon = ''; @@ -1647,14 +1681,14 @@ class e_admin_dispatcher $icon = e107::getPlug()->load(e_CURRENT_PLUGIN)->getIcon(24); } - return e107::getNav()->admin($icon."".$this->menuTitle."", $selected, $var); + return e107::getNav()->admin($icon. '' .$this->menuTitle. '', $selected, $var); } /** * Render Help Text in