From 77dc0dde40540547fa0ccb206f9aca8ccc631b2d Mon Sep 17 00:00:00 2001 From: jgauthi Date: Tue, 15 Aug 2023 16:34:24 +0200 Subject: [PATCH] Upgrade to php8.2, fix #1 --- composer.json | 4 ++-- readme.md | 8 +++++--- src/DebugHandler.php | 6 ++---- src/Timer.php | 6 ++---- src/VarDumperServer.php | 7 ++----- src/VarExport.php | 23 +++++------------------ src/VarExportWordpress.php | 18 +++++------------- 7 files changed, 23 insertions(+), 49 deletions(-) diff --git a/composer.json b/composer.json index e783013..fd0383c 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "homepage": "https://github.com/jgauthi/component_debug", "require": { - "php": ">=7.4", + "php": ">=8.2", "ext-mbstring": "*", "jdorn/sql-formatter": "^1.2" }, @@ -19,4 +19,4 @@ "authors": [ { "name": "jgauthi", "homepage": "https://github.com/jgauthi" } ] -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index ff37411..fe0dc6a 100644 --- a/readme.md +++ b/readme.md @@ -8,8 +8,7 @@ Debug tools like: varExport* functions, timer, server dump, debug handler, SQL B ## Prerequisite - -* PHP 4 (v1.0), PHP 5.4+ (v1.1), PHP 5.6 (v1.2+) or PHP 7.4 (v2) +* PHP 8.2 (v2.1), old version: 7.4 (v2), 5.6 (v1.2+), 5.4+ (v1.1), 4 (v1.0) ## Install Edit your [composer.json](https://getcomposer.org) (launch `composer update` after edit): @@ -26,7 +25,10 @@ Edit your [composer.json](https://getcomposer.org) (launch `composer update` aft Define the constant for dump exported variable on the folder (require write permissions): ```php -define('DEBUG_EXPORT_PATH', 'tmp/'); +define('DEBUG_EXPORT_PATH', sys_get_temp_dir()); + +// Or, set manually +define('DEBUG_EXPORT_PATH', __DIR__.'/tmp'); ``` For use VarExport*_wp functions (wordpress), you can include the [VarExportWordpress.php](src/VarExportWordpress.php) file on `wp-config.php` or `theme init`: diff --git a/src/DebugHandler.php b/src/DebugHandler.php index cbe2a14..9e662c5 100644 --- a/src/DebugHandler.php +++ b/src/DebugHandler.php @@ -62,10 +62,9 @@ static private function activeDebug($debugMode): void } /** - * @param string|bool $debugMode * @throws \ReflectionException */ - static public function rapportFooter($debugMode = true): void + static public function rapportFooter(string|bool $debugMode = true): void { // Mettre fin au timer $duration = ceil((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000); @@ -102,10 +101,9 @@ static public function rapportFooter($debugMode = true): void /** * Variables à exporter - * @param string|bool $debugMode * @throws \ReflectionException */ - static protected function dumpValues($debugMode): void + static protected function dumpValues(string|bool $debugMode): void { $dumpFunction = 'var_dump'; if (function_exists('dump')) { diff --git a/src/Timer.php b/src/Timer.php index 4d94cfa..3a08982 100644 --- a/src/Timer.php +++ b/src/Timer.php @@ -3,7 +3,7 @@ * @name: Timer * @note: Stopwatch in milliseconds script time+ the various steps in the code * @author: Jgauthi, created at [28mars2007], url: - * @version: 2.0.2 + * @version: 2.1 *******************************************************************************/ @@ -17,15 +17,13 @@ class Timer protected float $startTime; protected array $time = []; protected array $chapterTimes = []; - private bool $sendHeaderHttp; protected string $result; protected string $step; protected string $chapter; - public function __construct(bool $header = false) + public function __construct(private bool $sendHeaderHttp = false) { $this->startTime = microtime(true); - $this->sendHeaderHttp = $header; } static public function init(bool $header = false, string $format = self::EXPORT_FORMAT_HTML): self diff --git a/src/VarDumperServer.php b/src/VarDumperServer.php index b663cd3..406a76f 100644 --- a/src/VarDumperServer.php +++ b/src/VarDumperServer.php @@ -19,10 +19,7 @@ class VarDumperServer { - /** - * @param string $host The server host - */ - static public function init(string $host = 'tcp://127.0.0.1:9912'): void + static public function init(string $serverHost = 'tcp://127.0.0.1:9912'): void { if (!class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) { die('var-dumper not installed.'); @@ -30,7 +27,7 @@ static public function init(string $host = 'tcp://127.0.0.1:9912'): void $cloner = new VarCloner; $fallbackDumper = in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliDumper : new HtmlDumper; - $dumper = new ServerDumper($host, $fallbackDumper, [ + $dumper = new ServerDumper($serverHost, $fallbackDumper, [ 'cli' => new CliContextProvider, 'source' => new SourceContextProvider, ]); diff --git a/src/VarExport.php b/src/VarExport.php index 5dfb843..89adf9c 100644 --- a/src/VarExport.php +++ b/src/VarExport.php @@ -7,10 +7,7 @@ //------------------------------------------------- // Debug //------------------------------------------------- -/** - * @param mixed $var - */ -function varExportReturnValue($var): string +function varExportReturnValue(mixed $var): string { if (null === $var) { $var = '# NULL #'; @@ -33,9 +30,8 @@ function varExportReturnValue($var): string /** * Utiliser dump si possible - * @param mixed ...$args */ -function varExport(... $args) +function varExport(mixed ...$args) { foreach($args as $var) { $var = varExportReturnValue($var); @@ -44,10 +40,7 @@ function varExport(... $args) echo '
'; } -/** - * @param mixed ...$args - */ -function varExportData(... $args): array +function varExportData(mixed ...$args): array { $data = []; foreach ($args as $var) { @@ -57,10 +50,7 @@ function varExportData(... $args): array return $data; } -/** - * @param mixed ...$args - */ -function varComment(... $args): void +function varComment(mixed ...$args): void { echo ''.PHP_EOL; } -/** - * @param mixed ...$args - */ -function VarExportFile(... $args): void +function VarExportFile(mixed ...$args): void { if (!defined('DEBUG_EXPORT_PATH')) { die('DEBUG_EXPORT_PATH is not defined'); diff --git a/src/VarExportWordpress.php b/src/VarExportWordpress.php index 9e67c03..e39587e 100644 --- a/src/VarExportWordpress.php +++ b/src/VarExportWordpress.php @@ -21,10 +21,7 @@ // }); // } -/** - * @param mixed ...$args - */ -function varExport_wp(... $args): void +function varExport_wp(mixed ...$args): void { if (!function_exists('is_admin') || !function_exists('add_action')) { return; @@ -99,7 +96,7 @@ function varExportFilter_wp(?string $regexp = null): void return ($a['order'] < $b['order']) ? -1 : 1; }); } ?> -
+