Skip to content

Commit

Permalink
Modernise code formating
Browse files Browse the repository at this point in the history
  • Loading branch information
jokkedk committed Oct 7, 2019
1 parent bf31482 commit 2f3538b
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 252 deletions.
124 changes: 61 additions & 63 deletions library/ZFDebug/Controller/Plugin/Debug.php

Large diffs are not rendered by default.

41 changes: 17 additions & 24 deletions library/ZFDebug/Controller/Plugin/Debug/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class ZFDebug_Controller_Plugin_Debug_Plugin
{
protected $_closingBracket = null;
protected $closingBracket = null;

public function getLinebreak()
{
Expand All @@ -33,18 +33,18 @@ public function getIconData()

public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
if (!$this->closingBracket) {
if ($this->isXhtml()) {
$this->closingBracket = ' />';
} else {
$this->_closingBracket = '>';
$this->closingBracket = '>';
}
}

return $this->_closingBracket;
return $this->closingBracket;
}

protected function _isXhtml()
protected function isXhtml()
{
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$doctype = $view->doctype();
Expand All @@ -57,36 +57,29 @@ protected function _isXhtml()
* @param array $values
* @return string
*/
protected function _cleanData($values)
protected function cleanData($values)
{
$linebreak = $this->getLinebreak();

if (is_array($values)) {
ksort($values);
}
$retVal = '<div class="pre">';
foreach ($values as $key => $value)
{
foreach ($values as $key => $value) {
$key = htmlspecialchars($key);
if (is_numeric($value)) {
$retVal .= $key.' => '.$value.$linebreak;
}
else if (is_string($value)) {
} elseif (is_string($value)) {
$retVal .= $key.' => \''.htmlspecialchars($value).'\''.$linebreak;
}
else if (is_array($value))
{
$retVal .= $key.' => '.self::_cleanData($value);
}
else if (is_object($value))
{
$retVal .= $key.' => '.get_class($value).' Object()'.$linebreak;
}
else if (is_null($value))
{
} elseif (is_array($value)) {
$retVal .= $key.' => '.self::cleanData($value);
} elseif (is_object($value)) {
$retVal .= $key.' => '.get_class($value).' Object()';
$retVal .= $linebreak;
} elseif (is_null($value)) {
$retVal .= $key.' => NULL'.$linebreak;
}
}
return $retVal.'</div>';
}
}
}
28 changes: 14 additions & 14 deletions library/ZFDebug/Controller/Plugin/Debug/Plugin/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ class ZFDebug_Controller_Plugin_Debug_Plugin_Auth implements ZFDebug_Controller_
*
* @var string
*/
protected $_identifier = 'auth';
protected $identifier = 'auth';

/**
* Contains Zend_Auth object
*
* @var Zend_Auth
*/
protected $_auth;
protected $auth;

/**
* Contains "column name" for the username
*
* @var string
*/
protected $_user = 'user';
protected $user = 'user';

/**
* Contains "column name" for the role
*
* @var string
*/
protected $_role = 'role';
protected $role = 'role';

/**
* Contains Acls for this application
Expand All @@ -63,12 +63,12 @@ class ZFDebug_Controller_Plugin_Debug_Plugin_Auth implements ZFDebug_Controller_
*/
public function __construct(array $options = array())
{
$this->_auth = Zend_Auth::getInstance();
$this->auth = Zend_Auth::getInstance();
if (isset($options['user'])) {
$this->_user = $options['user'];
$this->user = $options['user'];
}
if (isset($options['role'])) {
$this->_role = $options['role'];
$this->role = $options['role'];
}
}

Expand All @@ -79,7 +79,7 @@ public function __construct(array $options = array())
*/
public function getIdentifier()
{
return $this->_identifier;
return $this->identifier;
}

/**
Expand All @@ -102,15 +102,15 @@ public function getTab()
$username = 'Not Authed';
$role = 'Unknown Role';

if (!$this->_auth->hasIdentity()) {
if (!$this->auth->hasIdentity()) {
return 'Not authorized';
}
$identity = $this->_auth->getIdentity();
$identity = $this->auth->getIdentity();
if (is_object($identity)) {
$username = $this->_auth->getIdentity()->{$this->_user};
$role = $this->_auth->getIdentity()->{$this->_role};
$username = $this->auth->getIdentity()->{$this->user};
$role = $this->auth->getIdentity()->{$this->role};
} else {
$username = $this->_auth->getIdentity();
$username = $this->auth->getIdentity();
$role = '';
}
return $username . ' (' . $role . ')';
Expand All @@ -125,4 +125,4 @@ public function getPanel()
{
return '';
}
}
}
18 changes: 8 additions & 10 deletions library/ZFDebug/Controller/Plugin/Debug/Plugin/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Cache
extends ZFDebug_Controller_Plugin_Debug_Plugin
implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
class ZFDebug_Controller_Plugin_Debug_Plugin_Cache extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'cache';
protected $identifier = 'cache';

/**
* @var Zend_Cache_Backend_ExtendedInterface
*/
protected $_cacheBackends = array();
protected $cacheBackends = array();

/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Cache
Expand All @@ -46,8 +44,8 @@ public function __construct(array $options = array())
}
is_array($options['backend']) || $options['backend'] = array($options['backend']);
foreach ($options['backend'] as $name => $backend) {
if ($backend instanceof Zend_Cache_Backend_ExtendedInterface ) {
$this->_cacheBackends[$name] = $backend;
if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) {
$this->cacheBackends[$name] = $backend;
}
}
}
Expand All @@ -59,7 +57,7 @@ public function __construct(array $options = array())
*/
public function getIdentifier()
{
return $this->_identifier;
return $this->identifier;
}

/**
Expand Down Expand Up @@ -113,7 +111,7 @@ public function getPanel()
. $cache['expunges'] . ' Expunges (cache full count)';
}
}

if (function_exists('opcache_get_configuration')) {
$opconfig = opcache_get_configuration();
if ($opconfig['directives']['opcache.enable']) {
Expand All @@ -129,7 +127,7 @@ public function getPanel()
}
}

foreach ($this->_cacheBackends as $name => $backend) {
foreach ($this->cacheBackends as $name => $backend) {
$fillingPercentage = $backend->getFillingPercentage();
$ids = $backend->getIds();

Expand Down
56 changes: 27 additions & 29 deletions library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,23 @@
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Database
extends ZFDebug_Controller_Plugin_Debug_Plugin
implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
class ZFDebug_Controller_Plugin_Debug_Plugin_Database extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{

/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'database';
protected $identifier = 'database';

/**
* @var array
*/
protected $_db = array();
protected $db = array();

protected $_explain = false;
protected $_backtrace = false;
protected $explain = false;
protected $backtrace = false;

/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Variables
Expand All @@ -52,28 +50,28 @@ public function __construct(array $options = array())
{
if (!isset($options['adapter']) || !count($options['adapter'])) {
if (Zend_Db_Table_Abstract::getDefaultAdapter()) {
$this->_db[0] = Zend_Db_Table_Abstract::getDefaultAdapter();
$this->db[0] = Zend_Db_Table_Abstract::getDefaultAdapter();
if (isset($options['backtrace']) && $options['backtrace']) {
$this->_backtrace = true;
$this->_db[0]->setProfiler(new ZFDebug_Db_Profiler(true));
$this->backtrace = true;
$this->db[0]->setProfiler(new ZFDebug_Db_Profiler(true));
} else {
$this->_db[0]->getProfiler()->setEnabled(true);
$this->db[0]->getProfiler()->setEnabled(true);
}
}
} else if ($options['adapter'] instanceof Zend_Db_Adapter_Abstract ) {
$this->_db[0] = $options['adapter'];
$this->_db[0]->getProfiler()->setEnabled(true);
} elseif ($options['adapter'] instanceof Zend_Db_Adapter_Abstract) {
$this->db[0] = $options['adapter'];
$this->db[0]->getProfiler()->setEnabled(true);
} else {
foreach ($options['adapter'] as $name => $adapter) {
if ($adapter instanceof Zend_Db_Adapter_Abstract) {
$adapter->getProfiler()->setEnabled(true);
$this->_db[$name] = $adapter;
$this->db[$name] = $adapter;
}
}
}

if (isset($options['explain'])) {
$this->_explain = (bool)$options['explain'];
$this->explain = (bool)$options['explain'];
}
}

Expand All @@ -84,7 +82,7 @@ public function __construct(array $options = array())
*/
public function getIdentifier()
{
return $this->_identifier;
return $this->identifier;
}

/**
Expand All @@ -104,10 +102,10 @@ public function getIconData()
*/
public function getTab()
{
if (!$this->_db)
if (!$this->db) {
return 'No adapter';

foreach ($this->_db as $adapter) {
}
foreach ($this->db as $adapter) {
$profiler = $adapter->getProfiler();
$adapterInfo[] = $profiler->getTotalNumQueries() . ' in '
. round($profiler->getTotalElapsedSecs()*1000, 2) . ' ms';
Expand All @@ -124,9 +122,9 @@ public function getTab()
*/
public function getPanel()
{
if (!$this->_db)
if (!$this->db) {
return '';

}
$html = '<h4>Database queries';

// @TODO: This is always on?
Expand All @@ -143,10 +141,10 @@ public function getPanel()
public function getProfile()
{
$queries = '';
foreach ($this->_db as $name => $adapter) {
foreach ($this->db as $name => $adapter) {
if ($profiles = $adapter->getProfiler()->getQueryProfiles()) {
$adapter->getProfiler()->setEnabled(false);
if (1 < count($this->_db)) {
if (1 < count($this->db)) {
$queries .= '<h4>Adapter '.$name.'</h4>';
}
$queries .='<table cellspacing="0" cellpadding="0" width="100%">';
Expand All @@ -155,7 +153,7 @@ public function getProfile()
. sprintf('%0.2f', $profile->getElapsedSecs()*1000)
. "ms</td>\n<td>";
$params = $profile->getQueryParams();
array_walk($params, array($this, '_addQuotes'));
array_walk($params, array($this, 'addQuotes'));
$paramCount = count($params);
if ($paramCount) {
$queries .= htmlspecialchars(preg_replace(array_fill(0, $paramCount, '/\?/'), $params, $profile->getQuery(), 1));
Expand All @@ -167,7 +165,7 @@ public function getProfile()
$adapter instanceof Zend_Db_Adapter_Pdo_Mysql);

# Run explain if enabled, supported adapter and SELECT query
if ($this->_explain && $supportedAdapter) {
if ($this->explain && $supportedAdapter) {
$queries .= "</td><td style='color:#7F7F7F;padding-left:2em;' nowrap>";

foreach ($adapter->fetchAll('EXPLAIN '.$profile->getQuery()) as $explain) {
Expand All @@ -192,7 +190,7 @@ public function getProfile()
}

$queries .= "</td>\n</tr>\n";
if ($this->_backtrace) {
if ($this->backtrace) {
$trace = $profile->getTrace();
array_walk(
$trace,
Expand All @@ -210,8 +208,8 @@ function (&$v, $k) {
}

// For adding quotes to query params
protected function _addQuotes(&$value, $key)
protected function addQuotes(&$value, $key)
{
$value = "'" . $value . "'";
}
}
}
Loading

0 comments on commit 2f3538b

Please sign in to comment.