Skip to content

Commit

Permalink
enhanceObjects.js - reduce complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdotcom committed Jul 4, 2024
1 parent 608c481 commit 2b8aacd
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 67 deletions.
11 changes: 8 additions & 3 deletions src/Debug/Framework/Yii1_1/LogRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,11 @@ protected function processLogEntry(array $logEntry)
{
$logEntry = $this->normalizeMessage($logEntry);
$logEntry = $this->meta->messageMeta($logEntry);
$handled = false;
if (\strpos((string) $logEntry['category'], 'system.caching') === 0 && \preg_match('/^(Saving|Serving) "yii:dbquery/', $logEntry['message'])) {
$this->processSqlCachingLogEntry($logEntry);
$handled = $this->processSqlCachingLogEntry($logEntry);
}
if ($handled) {
return;
}
$method = 'processLogEntry' . \ucfirst($logEntry['level']);
Expand All @@ -278,7 +281,7 @@ protected function processLogEntry(array $logEntry)
*
* @param array $logEntry our key/value'd log entry
*
* @return void
* @return bool
*/
private function processSqlCachingLogEntry(array $logEntry)
{
Expand All @@ -289,7 +292,7 @@ private function processSqlCachingLogEntry(array $logEntry)
$returnValue = 'saved to cache';

if (\strpos($logEntry['message'], 'Serving') === 0) {
$regEx = '/^Serving "yii:dbquery:\S+:\S*:\S+:(.*?)(?::(a:\d+:\{.+\}))?" from cache$/s';
$regEx = '/^Serving "yii:dbquery:\S+:\S*:\S+:(.*?)(?::(a:\d+:\{.*\}))?" from cache$/s';
\preg_match($regEx, $logEntry['message'], $matches);
$statementInfo = new StatementInfo($matches[1], $matches[2] ? \unserialize($matches[2]) : array());
$statementInfo->appendLog($debug, array(
Expand All @@ -311,6 +314,8 @@ private function processSqlCachingLogEntry(array $logEntry)
'level' => 'info',
)
));

return true;
}

/**
Expand Down
75 changes: 43 additions & 32 deletions src/Debug/js/Debug.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,14 @@
if ($obj.is('.enhanced')) {
return
}
$inner.find('> dd > ul > li > .interface, > dd > ul > li > .interface + ul .interface').each(function () {
var iface = $(this).text();
if (findInterfaceMethods($obj, iface).length === 0) {
return
}
$(this)
.addClass('toggle-on')
.prop('title', 'toggle interface methods')
.attr('data-toggle', 'interface')
.attr('data-interface', iface);
}).filter('.toggle-off').removeClass('toggle-off').each(function () {
// element may have toggle-off to begin with...
toggleInterface(this);
});
$inner.find('> .private, > .protected')
.filter('.magic, .magic-read, .magic-write')
.removeClass('private protected');
if (accessible === 'public') {
$inner.find('.private, .protected').hide();
callPostToggle = 'allDesc';
}
enhanceInterfaces($obj);
visToggles($inner, accessible);
addIcons($inner);
$inner.find('> .property.forceShow').show().find('> .t_array').debugEnhance('expand');
Expand All @@ -198,6 +185,26 @@
$obj.addClass('enhanced');
}

function enhanceInterfaces ($obj) {
var $inner = $obj.find('> .object-inner');
$inner.find('> dd > ul > li > .interface, > dd > ul > li > .interface + ul .interface')
.each(function () {
var iface = $(this).text();
if (findInterfaceMethods($obj, iface).length === 0) {
return
}
$(this)
.addClass('toggle-on')
.prop('title', 'toggle interface methods')
.attr('data-toggle', 'interface')
.attr('data-interface', iface);
})
.filter('.toggle-off').removeClass('toggle-off').each(function () {
// element may have toggle-off to begin with...
toggleInterface(this);
});
}

/**
* Add toggles for protected, private excluded inherited
*/
Expand All @@ -208,30 +215,34 @@
hasExcluded: $inner.children('.debuginfo-excluded').hide().length > 0,
hasInherited: $inner.children('dd[data-inherited-from]').length > 0
};
var $visToggles = visTogglesGet(flags, accessible);
if ($inner.find('> dd[class*=t_modifier_]').length) {
$inner.find('> dd[class*=t_modifier_]').last().after($visToggles);
return
}
$inner.prepend($visToggles);
}

function visTogglesGet (flags, accessible) {
var $visToggles = $('<div class="vis-toggles"></div>');
var toggleClass = accessible === 'public'
? 'toggle-off'
: 'toggle-on';
var toggleVerb = accessible === 'public'
? 'show'
: 'hide';
var $visToggles = $('<div class="vis-toggles"></div>');
if (flags.hasProtected) {
$visToggles.append('<span class="' + toggleClass + '" data-toggle="vis" data-vis="protected">' + toggleVerb + ' protected</span>');
}
if (flags.hasPrivate) {
$visToggles.append('<span class="' + toggleClass + '" data-toggle="vis" data-vis="private">' + toggleVerb + ' private</span>');
}
if (flags.hasExcluded) {
$visToggles.append('<span class="toggle-off" data-toggle="vis" data-vis="debuginfo-excluded">show excluded</span>');
}
if (flags.hasInherited) {
$visToggles.append('<span class="toggle-on" data-toggle="vis" data-vis="inherited">hide inherited</span>');
}
if ($inner.find('> dd[class*=t_modifier_]').length) {
$inner.find('> dd[class*=t_modifier_]').last().after($visToggles);
return
}
$inner.prepend($visToggles);
var toggles = {
hasProtected: '<span class="' + toggleClass + '" data-toggle="vis" data-vis="protected">' + toggleVerb + ' protected</span>',
hasPrivate: '<span class="' + toggleClass + '" data-toggle="vis" data-vis="private">' + toggleVerb + ' private</span>',
hasExcluded: '<span class="toggle-off" data-toggle="vis" data-vis="debuginfo-excluded">show excluded</span>',
hasInherited: '<span class="toggle-on" data-toggle="vis" data-vis="inherited">hide inherited</span>',
};
$.each(flags, function (name, val) {
if (val) {
$visToggles.append(toggles[name]);
}
});
return $visToggles
}

function toggleInterface (toggle) {
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/js/Debug.jquery.min.js

Large diffs are not rendered by default.

73 changes: 42 additions & 31 deletions src/Debug/js_src/enhanceObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,14 @@ export function enhanceInner ($obj) {
if ($obj.is('.enhanced')) {
return
}
$inner.find('> dd > ul > li > .interface, > dd > ul > li > .interface + ul .interface').each(function () {
var iface = $(this).text()
if (findInterfaceMethods($obj, iface).length === 0) {
return
}
$(this)
.addClass('toggle-on')
.prop('title', 'toggle interface methods')
.attr('data-toggle', 'interface')
.attr('data-interface', iface)
}).filter('.toggle-off').removeClass('toggle-off').each(function () {
// element may have toggle-off to begin with...
toggleInterface(this)
})
$inner.find('> .private, > .protected')
.filter('.magic, .magic-read, .magic-write')
.removeClass('private protected')
if (accessible === 'public') {
$inner.find('.private, .protected').hide()
callPostToggle = 'allDesc'
}
enhanceInterfaces($obj)
visToggles($inner, accessible)
addIcons($inner)
$inner.find('> .property.forceShow').show().find('> .t_array').debugEnhance('expand')
Expand All @@ -103,6 +90,26 @@ export function enhanceInner ($obj) {
$obj.addClass('enhanced')
}

function enhanceInterfaces ($obj) {
var $inner = $obj.find('> .object-inner')
$inner.find('> dd > ul > li > .interface, > dd > ul > li > .interface + ul .interface')
.each(function () {
var iface = $(this).text()
if (findInterfaceMethods($obj, iface).length === 0) {
return
}
$(this)
.addClass('toggle-on')
.prop('title', 'toggle interface methods')
.attr('data-toggle', 'interface')
.attr('data-interface', iface)
})
.filter('.toggle-off').removeClass('toggle-off').each(function () {
// element may have toggle-off to begin with...
toggleInterface(this)
})
}

/**
* Add toggles for protected, private excluded inherited
*/
Expand All @@ -113,30 +120,34 @@ function visToggles ($inner, accessible) {
hasExcluded: $inner.children('.debuginfo-excluded').hide().length > 0,
hasInherited: $inner.children('dd[data-inherited-from]').length > 0
}
var $visToggles = visTogglesGet(flags, accessible)
if ($inner.find('> dd[class*=t_modifier_]').length) {
$inner.find('> dd[class*=t_modifier_]').last().after($visToggles)
return
}
$inner.prepend($visToggles)
}

function visTogglesGet (flags, accessible) {
var $visToggles = $('<div class="vis-toggles"></div>')
var toggleClass = accessible === 'public'
? 'toggle-off'
: 'toggle-on'
var toggleVerb = accessible === 'public'
? 'show'
: 'hide'
var $visToggles = $('<div class="vis-toggles"></div>')
if (flags.hasProtected) {
$visToggles.append('<span class="' + toggleClass + '" data-toggle="vis" data-vis="protected">' + toggleVerb + ' protected</span>')
}
if (flags.hasPrivate) {
$visToggles.append('<span class="' + toggleClass + '" data-toggle="vis" data-vis="private">' + toggleVerb + ' private</span>')
}
if (flags.hasExcluded) {
$visToggles.append('<span class="toggle-off" data-toggle="vis" data-vis="debuginfo-excluded">show excluded</span>')
}
if (flags.hasInherited) {
$visToggles.append('<span class="toggle-on" data-toggle="vis" data-vis="inherited">hide inherited</span>')
var toggles = {
hasProtected: '<span class="' + toggleClass + '" data-toggle="vis" data-vis="protected">' + toggleVerb + ' protected</span>',
hasPrivate: '<span class="' + toggleClass + '" data-toggle="vis" data-vis="private">' + toggleVerb + ' private</span>',
hasExcluded: '<span class="toggle-off" data-toggle="vis" data-vis="debuginfo-excluded">show excluded</span>',
hasInherited: '<span class="toggle-on" data-toggle="vis" data-vis="inherited">hide inherited</span>',
}
if ($inner.find('> dd[class*=t_modifier_]').length) {
$inner.find('> dd[class*=t_modifier_]').last().after($visToggles)
return
}
$inner.prepend($visToggles)
$.each(flags, function (name, val) {
if (val) {
$visToggles.append(toggles[name])
}
})
return $visToggles
}

function toggleInterface (toggle) {
Expand Down

0 comments on commit 2b8aacd

Please sign in to comment.