Skip to content

Commit

Permalink
Upgrade to php8.2, fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauthi committed Aug 15, 2023
1 parent 305e85f commit 77dc0dd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 49 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -19,4 +19,4 @@
"authors": [
{ "name": "jgauthi", "homepage": "https://github.com/jgauthi" }
]
}
}
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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`:
Expand Down
6 changes: 2 additions & 4 deletions src/DebugHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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')) {
Expand Down
6 changes: 2 additions & 4 deletions src/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @name: Timer
* @note: Stopwatch in milliseconds script time+ the various steps in the code
* @author: Jgauthi, created at [28mars2007], url: <https://github.com/jgauthi/component_debug>
* @version: 2.0.2
* @version: 2.1
*******************************************************************************/

Expand All @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/VarDumperServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@

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.');
}

$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,
]);
Expand Down
23 changes: 5 additions & 18 deletions src/VarExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
//-------------------------------------------------
// Debug
//-------------------------------------------------
/**
* @param mixed $var
*/
function varExportReturnValue($var): string
function varExportReturnValue(mixed $var): string
{
if (null === $var) {
$var = '# NULL #';
Expand All @@ -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);
Expand All @@ -44,10 +40,7 @@ function varExport(... $args)
echo '<hr style="color: red;"/>';
}

/**
* @param mixed ...$args
*/
function varExportData(... $args): array
function varExportData(mixed ...$args): array
{
$data = [];
foreach ($args as $var) {
Expand All @@ -57,10 +50,7 @@ function varExportData(... $args): array
return $data;
}

/**
* @param mixed ...$args
*/
function varComment(... $args): void
function varComment(mixed ...$args): void
{
echo '<!-- DEBUG:'.PHP_EOL;
foreach ($args as $var) {
Expand All @@ -70,10 +60,7 @@ function varComment(... $args): void
echo PHP_EOL.'-->'.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');
Expand Down
18 changes: 5 additions & 13 deletions src/VarExportWordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +96,7 @@ function varExportFilter_wp(?string $regexp = null): void
return ($a['order'] < $b['order']) ? -1 : 1;
});
} ?>
<div style="<?=$style; ?>">
<div style="<?=$style?>">
<?php varExport("Filters '$regexp'", $data); ?>
</div><br clear="all">
<?php
Expand Down Expand Up @@ -158,11 +155,7 @@ function list_hooks(bool $filter = false): void
}
}

/**
* @param mixed|null $input
* @return mixed|null
*/
function list_hook_details($input = null)
function list_hook_details(mixed $input = null): mixed
{
global $wp_filter;

Expand All @@ -185,9 +178,8 @@ function list_live_hooks(bool $hook = false): void

/**
* Comparer les postmeta de 2 posts ou plus
* @param int ...$posts_ids
*/
function varExport_wp_cmp_postmeta(... $posts_ids): void
function varExport_wp_cmp_postmeta(int ...$posts_ids): void
{
if (empty($posts_ids)) {
varExport_wp('Posts ID empties');
Expand Down Expand Up @@ -220,7 +212,7 @@ function varExport_wp_cmp_postmeta(... $posts_ids): void
* Combine multiple arrays to one.
* @param array ...$args
*/
function array_cmp(... $args): ?array
function array_cmp(mixed ...$args): ?array
{
if (empty($args)) {
return null;
Expand Down

0 comments on commit 77dc0dd

Please sign in to comment.