aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/Debug
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2023-09-02 14:42:51 +0200
committerGitHub <noreply@github.com>2023-09-02 14:42:51 +0200
commit5ff5424d8c81c7123d8656a787af2ff85b3dec21 (patch)
tree322929ee01d892bb3c927e7fe1238369c647f820 /inc/Debug
parent0613df3287b82a98b1e97cf86ed9d4c8fbd16f1c (diff)
parent91560755291852b8302767d454183a7662666f7e (diff)
downloaddokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.tar.gz
dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.zip
Merge pull request #4045 from dokuwiki/autofix
Use Rector to autofix code smell
Diffstat (limited to 'inc/Debug')
-rw-r--r--inc/Debug/DebugHelper.php49
-rw-r--r--inc/Debug/PropertyDeprecationHelper.php7
2 files changed, 29 insertions, 27 deletions
diff --git a/inc/Debug/DebugHelper.php b/inc/Debug/DebugHelper.php
index f78b88193..4fc8bf9da 100644
--- a/inc/Debug/DebugHelper.php
+++ b/inc/Debug/DebugHelper.php
@@ -1,15 +1,14 @@
<?php
-
namespace dokuwiki\Debug;
-use Doku_Event;
+use dokuwiki\Extension\Event;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Logger;
class DebugHelper
{
- const INFO_DEPRECATION_LOG_EVENT = 'INFO_DEPRECATION_LOG';
+ protected const INFO_DEPRECATION_LOG_EVENT = 'INFO_DEPRECATION_LOG';
/**
* Check if deprecation messages shall be handled
@@ -24,7 +23,7 @@ class DebugHelper
global $EVENT_HANDLER;
if (
!Logger::getInstance(Logger::LOG_DEPRECATED)->isLogging() &&
- ($EVENT_HANDLER === null || !$EVENT_HANDLER->hasHandlerForEvent('INFO_DEPRECATION_LOG'))
+ (!$EVENT_HANDLER instanceof EventHandler || !$EVENT_HANDLER->hasHandlerForEvent('INFO_DEPRECATION_LOG'))
) {
// avoid any work if no one cares
return false;
@@ -45,31 +44,38 @@ class DebugHelper
if (!self::isEnabled()) return;
$backtrace = debug_backtrace();
- for ($i = 0; $i < $callerOffset; $i += 1) {
- if(count($backtrace) > 1) array_shift($backtrace);
+ for ($i = 0; $i < $callerOffset; ++$i) {
+ if (count($backtrace) > 1) array_shift($backtrace);
}
- list($self, $call) = $backtrace;
-
- if (!$thing) {
- $thing = trim(
- (!empty($self['class']) ? ($self['class'] . '::') : '') .
- $self['function'] . '()', ':');
- }
+ [$self, $call] = $backtrace;
self::triggerDeprecationEvent(
$backtrace,
$alternative,
- $thing,
- trim(
- (!empty($call['class']) ? ($call['class'] . '::') : '') .
- $call['function'] . '()', ':'),
+ self::formatCall($self),
+ self::formatCall($call),
$self['file'] ?? $call['file'] ?? '',
$self['line'] ?? $call['line'] ?? 0
);
}
/**
+ * Format the given backtrace info into a proper function/method call string
+ * @param array $call
+ * @return string
+ */
+ protected static function formatCall($call)
+ {
+ $thing = '';
+ if (!empty($call['class'])) {
+ $thing .= $call['class'] . '::';
+ }
+ $thing .= $call['function'] . '()';
+ return trim($thing, ':');
+ }
+
+ /**
* This marks logs a deprecation warning for a property that should no longer be used
*
* This is usually called withing a magic getter or setter.
@@ -119,8 +125,7 @@ class DebugHelper
$file,
$line,
$callerOffset = 1
- )
- {
+ ) {
if (!self::isEnabled()) return;
$backtrace = array_slice(debug_backtrace(), $callerOffset);
@@ -133,7 +138,6 @@ class DebugHelper
$file,
$line
);
-
}
/**
@@ -151,8 +155,7 @@ class DebugHelper
$caller,
$file,
$line
- )
- {
+ ) {
$data = [
'trace' => $backtrace,
'alternative' => $alternative,
@@ -161,7 +164,7 @@ class DebugHelper
'file' => $file,
'line' => $line,
];
- $event = new Doku_Event(self::INFO_DEPRECATION_LOG_EVENT, $data);
+ $event = new Event(self::INFO_DEPRECATION_LOG_EVENT, $data);
if ($event->advise_before()) {
$msg = $event->data['called'] . ' is deprecated. It was called from ';
$msg .= $event->data['caller'] . ' in ' . $event->data['file'] . ':' . $event->data['line'];
diff --git a/inc/Debug/PropertyDeprecationHelper.php b/inc/Debug/PropertyDeprecationHelper.php
index 6289d5ba8..ed6a2dcba 100644
--- a/inc/Debug/PropertyDeprecationHelper.php
+++ b/inc/Debug/PropertyDeprecationHelper.php
@@ -1,4 +1,5 @@
<?php
+
/**
* Trait for issuing warnings on deprecated access.
*
@@ -6,7 +7,6 @@
*
*/
-
namespace dokuwiki\Debug;
/**
@@ -32,7 +32,6 @@ namespace dokuwiki\Debug;
*/
trait PropertyDeprecationHelper
{
-
/**
* List of deprecated properties, in <property name> => <class> format
* where <class> is the the name of the class defining the property
@@ -108,7 +107,7 @@ trait PropertyDeprecationHelper
// The class name is not necessarily correct here but getting the correct class
// name would be expensive, this will work most of the time and getting it
// wrong is not a big deal.
- return __CLASS__;
+ return self::class;
}
// property_exists() returns false when the property does exist but is private (and not
// defined by the current class, for some value of "current" that differs slightly
@@ -124,7 +123,7 @@ trait PropertyDeprecationHelper
$classname = substr($obfuscatedProp, 1, -strlen($obfuscatedPropTail));
if ($classname === '*') {
// sanity; this shouldn't be possible as protected properties were handled earlier
- $classname = __CLASS__;
+ $classname = self::class;
}
return $classname;
}