Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .tools/phpstan/baseline/missingType.iterableValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,6 @@
declare(strict_types=1);

$ignoreErrors = [];
$ignoreErrors[] = [
'rawMessage' => 'Method rex_debug::getTrace() return type has no value type specified in iterable type array.',
'count' => 1,
'path' => __DIR__ . '/../../../addons/debug/lib/debug.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Method rex_extension_debug::getExtensionPoints() return type has no value type specified in iterable type array.',
'count' => 1,
'path' => __DIR__ . '/../../../addons/debug/lib/extensions/extension_debug.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Method rex_extension_debug::getExtensions() return type has no value type specified in iterable type array.',
'count' => 1,
'path' => __DIR__ . '/../../../addons/debug/lib/extensions/extension_debug.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Property rex_extension_debug::$extensionPoints type has no value type specified in iterable type array.',
'count' => 1,
'path' => __DIR__ . '/../../../addons/debug/lib/extensions/extension_debug.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Property rex_extension_debug::$extensions type has no value type specified in iterable type array.',
'count' => 1,
'path' => __DIR__ . '/../../../addons/debug/lib/extensions/extension_debug.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Property rex_extension_debug::$listeners type has no value type specified in iterable type array.',
'count' => 1,
'path' => __DIR__ . '/../../../addons/debug/lib/extensions/extension_debug.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Method Redaxo\\Core\\Content\\ArticleHandler::addArticle() has parameter $data with no value type specified in iterable type array.',
'count' => 1,
Expand Down
125 changes: 0 additions & 125 deletions .tools/psalm/baseline.xml
Original file line number Diff line number Diff line change
@@ -1,130 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac">
<file src="addons/debug/boot.php">
<MixedArgument>
<code><![CDATA[$query['query']]]></code>
<code><![CDATA[rex_debug_clockwork::getInstance()->getRequest()->id]]></code>
</MixedArgument>
<MixedArrayAccess>
<code><![CDATA[$query['duration']]]></code>
<code><![CDATA[$query['query']]]></code>
</MixedArrayAccess>
<MixedAssignment>
<code><![CDATA[$ep]]></code>
<code><![CDATA[$query]]></code>
<code><![CDATA[$req]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[counters]]></code>
<code><![CDATA[event]]></code>
<code><![CDATA[finalize]]></code>
<code><![CDATA[storeRequest]]></code>
<code><![CDATA[storeRequest]]></code>
<code><![CDATA[table]]></code>
<code><![CDATA[table]]></code>
<code><![CDATA[title]]></code>
<code><![CDATA[userData]]></code>
</MixedMethodCall>
<MixedOperand>
<code><![CDATA[$req->databaseDeletes]]></code>
<code><![CDATA[$req->databaseInserts]]></code>
<code><![CDATA[$req->databaseOthers]]></code>
<code><![CDATA[$req->databaseSelects]]></code>
<code><![CDATA[$req->databaseSlowQueries]]></code>
<code><![CDATA[$req->databaseUpdates]]></code>
</MixedOperand>
<MixedPropertyAssignment>
<code><![CDATA[$req]]></code>
<code><![CDATA[$req]]></code>
<code><![CDATA[$req]]></code>
<code><![CDATA[$req]]></code>
<code><![CDATA[$req]]></code>
<code><![CDATA[$req]]></code>
<code><![CDATA[$req]]></code>
<code><![CDATA[$req]]></code>
</MixedPropertyAssignment>
<MixedPropertyFetch>
<code><![CDATA[$clockwork->getRequest()->time]]></code>
<code><![CDATA[$req->databaseDeletes]]></code>
<code><![CDATA[$req->databaseInserts]]></code>
<code><![CDATA[$req->databaseOthers]]></code>
<code><![CDATA[$req->databaseQueries]]></code>
<code><![CDATA[$req->databaseSelects]]></code>
<code><![CDATA[$req->databaseSlowQueries]]></code>
<code><![CDATA[$req->databaseUpdates]]></code>
<code><![CDATA[rex_debug_clockwork::getInstance()->getRequest()->id]]></code>
</MixedPropertyFetch>
<PossiblyFalseArgument>
<code><![CDATA[$index]]></code>
</PossiblyFalseArgument>
<PossiblyNullArgument>
<code><![CDATA[$_SERVER['REQUEST_URI']]]></code>
</PossiblyNullArgument>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$_SERVER['REQUEST_URI']]]></code>
<code><![CDATA[$_SERVER['REQUEST_URI']]]></code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="addons/debug/install.php">
<PossiblyFalseArgument>
<code><![CDATA[$index]]></code>
</PossiblyFalseArgument>
<PossiblyNullArgument>
<code><![CDATA[$index]]></code>
</PossiblyNullArgument>
</file>
<file src="addons/debug/lib/debug.php">
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$trace[$i + 1]['class']]]></code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="addons/debug/lib/debug_clockwork.php">
<MixedMethodCall>
<code><![CDATA[addDataSource]]></code>
</MixedMethodCall>
<MixedReturnStatement>
<code><![CDATA[self::getHelper()->getClockwork()]]></code>
</MixedReturnStatement>
<PossiblyNullArgument>
<code><![CDATA[$_SERVER['REQUEST_URI']]]></code>
</PossiblyNullArgument>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$_SERVER['HTTP_HOST']]]></code>
<code><![CDATA[$_SERVER['REQUEST_URI']]]></code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="addons/debug/lib/extensions/extension_debug.php">
<MixedArrayAssignment>
<code><![CDATA[self::$listeners[$ep][]]]></code>
</MixedArrayAssignment>
<MixedAssignment>
<code><![CDATA[$data['listeners']]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$trace['file']]]></code>
<code><![CDATA[$trace['line']]]></code>
</MixedOperand>
</file>
<file src="addons/debug/lib/extensions/logger_debug.php">
<MixedArgument>
<code><![CDATA[rex_debug::getTrace()['trace']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$levelType]]></code>
<code><![CDATA[$trace]]></code>
</MixedAssignment>
</file>
<file src="addons/debug/lib/extensions/sql_debug.php">
<MixedMethodCall>
<code><![CDATA[addDatabaseQuery]]></code>
<code><![CDATA[addDatabaseQuery]]></code>
</MixedMethodCall>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$trace[$i]['line']]]></code>
<code><![CDATA[$trace[0]['file']]]></code>
<code><![CDATA[$trace[0]['line']]]></code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="boot/backend.php">
<InvalidOperand>
<code><![CDATA[strtotime($version['history_date'])]]></code>
Expand Down
58 changes: 33 additions & 25 deletions addons/debug/boot.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use Clockwork\Clockwork;
use Clockwork\Request\Timeline\Timeline;
use Clockwork\Request\UserData;
use Redaxo\Core\Addon\Addon;
use Redaxo\Core\ApiFunction\ApiFunction;
use Redaxo\Core\Backend\Controller;
Expand All @@ -16,6 +18,7 @@
use Redaxo\Core\Log\Logger;
use Redaxo\Core\Util\Editor;
use Redaxo\Core\Util\Timer;
use Redaxo\Core\Util\Type;

use function Redaxo\Core\View\escape;

Expand All @@ -24,7 +27,7 @@
}

if (Core::isBackend() && 'debug' === Request::get('page') && Core::getUser()?->admin) {
$index = file_get_contents(Addon::require('debug')->getAssetsPath('clockwork/index.html'));
$index = Type::string(file_get_contents(Addon::require('debug')->getAssetsPath('clockwork/index.html')));

$editor = Editor::factory();
$curEditor = $editor->getName();
Expand All @@ -40,7 +43,7 @@
}

// prepend backend folder
$apiUrl = dirname($_SERVER['REQUEST_URI']) . '/' . rex_debug_clockwork::getClockworkApiUrl();
$apiUrl = dirname(Type::string($_SERVER['REQUEST_URI'] ?? null)) . '/' . rex_debug_clockwork::getClockworkApiUrl();
$appearance = Core::getTheme();
if (!$appearance) {
$appearance = 'auto';
Expand Down Expand Up @@ -84,33 +87,36 @@
Logger::setFactoryClass(rex_logger_debug::class);
ApiFunction::setFactoryClass(rex_api_function_debug::class);

Response::setHeader('X-Clockwork-Id', rex_debug_clockwork::getInstance()->getRequest()->id);
Response::setHeader('X-Clockwork-Id', Type::string(rex_debug_clockwork::getRequest()->id));
Response::setHeader('X-Clockwork-Version', Clockwork::VERSION);

Response::setHeader('X-Clockwork-Path', rex_debug_clockwork::getClockworkApiUrl());

$shutdownFn = static function () {
$clockwork = rex_debug_clockwork::getInstance();
$req = rex_debug_clockwork::getRequest();

$clockwork->timeline()->finalize($clockwork->getRequest()->time);
/** @var Timeline $timeline */
$timeline = $clockwork->timeline();
$timeline->finalize($req->time);

foreach (Timer::$serverTimings as $label => $timings) {
foreach ($timings['timings'] as $timing) {
if ($timing['end'] - $timing['start'] >= 0.001) {
$clockwork->timeline()->event($label, ['start' => $timing['start'], 'end' => $timing['end']]);
$timeline->event($label, ['start' => $timing['start'], 'end' => $timing['end']]);
}
}
}

$req = $clockwork->getRequest();

if (Core::isFrontend()) {
$req->controller = 'article: ' . Article::getCurrentId() . '; clang: ' . Language::getCurrent()->code;
} elseif (!Core::getConsole()) {
$req->controller = 'page: ' . Controller::getCurrentPage();
}

/** @var array{query: string, duration: float} $query */
foreach ($req->databaseQueries as $query) {
/** @psalm-suppress MixedOperand */
match (Sql::getQueryType($query['query'])) {
'SELECT' => $req->databaseSelects++,
'INSERT' => $req->databaseInserts++,
Expand All @@ -119,19 +125,21 @@
default => $req->databaseOthers++,
};
if ($query['duration'] > 20) {
/** @psalm-suppress MixedOperand */
++$req->databaseSlowQueries;
}
}

$ep = $clockwork->getRequest()->userData('ep');
/** @var UserData $ep */
$ep = $req->userData('ep');
$ep->title('Extension Point');
$ep->counters([
'Extension Points' => count(rex_extension_debug::getExtensionPoints()),
'Registered Extensions' => count(rex_extension_debug::getExtensions()),
'Extension Points' => count(rex_extension_debug::$extensionPoints),
'Registered Extensions' => count(rex_extension_debug::$extensions),
]);

$ep->table('Executed Extension Points', rex_extension_debug::getExtensionPoints());
$ep->table('Registered Extensions', rex_extension_debug::getExtensions());
$ep->table('Executed Extension Points', rex_extension_debug::$extensionPoints);
$ep->table('Registered Extensions', rex_extension_debug::$extensions);
};

if ('cli' === PHP_SAPI) {
Expand All @@ -147,22 +155,21 @@
rex_debug_clockwork::ensureStoragePath();

$clockwork = rex_debug_clockwork::getInstance();
$clockwork
->resolveAsCommand(
$command->getName(),
$exitCode,
array_diff($input->getArguments(), $command->getDefinition()->getArgumentDefaults()),
array_diff($input->getOptions(), $command->getDefinition()->getOptionDefaults()),
$command->getDefinition()->getArgumentDefaults(),
$command->getDefinition()->getOptionDefaults(),
// $output->fetch()
)
->storeRequest();
$clockwork->resolveAsCommand(
$command->getName(),
$exitCode,
array_diff($input->getArguments(), $command->getDefinition()->getArgumentDefaults()),
array_diff($input->getOptions(), $command->getDefinition()->getOptionDefaults()),
$command->getDefinition()->getArgumentDefaults(),
$command->getDefinition()->getOptionDefaults(),
// $output->fetch()
);
$clockwork->storeRequest();
});
} else {
register_shutdown_function(static function () use ($shutdownFn) {
// don't track preflight requests
if (in_array($_SERVER['REQUEST_URI'], ['/__clockwork/latest', '/assets/addons/debug/clockwork/manifest.json'], true)) {
if (in_array($_SERVER['REQUEST_URI'] ?? null, ['/__clockwork/latest', '/assets/addons/debug/clockwork/manifest.json'], true)) {
return;
}

Expand All @@ -172,6 +179,7 @@
rex_debug_clockwork::ensureStoragePath();

$clockwork = rex_debug_clockwork::getInstance();
$clockwork->resolveRequest()->storeRequest();
$clockwork->resolveRequest();
$clockwork->storeRequest();
});
}
5 changes: 3 additions & 2 deletions addons/debug/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Redaxo\Core\Exception\UserMessageException;
use Redaxo\Core\Filesystem\Dir;
use Redaxo\Core\Translation\I18n;
use Redaxo\Core\Util\Type;

$addon = Addon::require('debug');

Expand All @@ -26,8 +27,8 @@

$indexPath = $addon->getAssetsPath('clockwork/index.html');

$index = file_get_contents($indexPath);
$index = preg_replace('/(href|src)=("?)([^>\s]+)/', '$1=$2' . $addon->getAssetsUrl('clockwork/$3'), $index);
$index = Type::string(file_get_contents($indexPath));
$index = Type::string(preg_replace('/(href|src)=("?)([^>\s]+)/', '$1=$2' . $addon->getAssetsUrl('clockwork/$3'), $index));
file_put_contents($indexPath, $index);
} else {
$message = I18n::msg('debug_error_unzip') . '<br>' . $path;
Expand Down
8 changes: 6 additions & 2 deletions addons/debug/lib/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ final class rex_debug
ErrorHandler::class,
];

/** @param list<class-string> $ignoredClasses */
/**
* @param list<class-string> $ignoredClasses
* @return array{file: string|null, line: int|null, trace: list<array{function: string, line?: int, file?: string, class?: class-string, type?: string, args?: list<mixed>, object?: object}>}
*/
public static function getTrace(array $ignoredClasses = []): array
{
$ignoredClasses = array_merge(self::$ignoreClasses, $ignoredClasses);
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

$start = 0;
for ($i = 0; $i < count($trace); ++$i) {
if (isset($trace[$i + 1]['class']) && in_array($trace[$i + 1]['class'], $ignoredClasses)) {
/** @psalm-suppress PossiblyUndefinedArrayOffset */
if (isset($trace[$i + 1]['class']) && in_array($trace[$i + 1]['class'], $ignoredClasses, true)) {
continue;
}

Expand Down
Loading