From 671b3e3787e58be6b0dcf6de536b139a71f7df8c Mon Sep 17 00:00:00 2001 From: jgauthi Date: Sat, 12 Sep 2020 14:30:45 +0200 Subject: [PATCH] Upgrade to php7.4 --- composer.json | 2 +- readme.md | 2 +- src/DebugHandler.php | 18 ++---- src/DebugUtils.php | 5 +- src/Timer.php | 110 +++++++++---------------------------- src/VarDumperServer.php | 8 +-- src/VarExport.php | 39 +++++-------- src/VarExportWordpress.php | 48 ++++++---------- 8 files changed, 70 insertions(+), 162 deletions(-) diff --git a/composer.json b/composer.json index a36b0e3..e783013 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "homepage": "https://github.com/jgauthi/component_debug", "require": { - "php": ">=5.6", + "php": ">=7.4", "ext-mbstring": "*", "jdorn/sql-formatter": "^1.2" }, diff --git a/readme.md b/readme.md index 97c1c17..ff37411 100644 --- a/readme.md +++ b/readme.md @@ -19,7 +19,7 @@ Edit your [composer.json](https://getcomposer.org) (launch `composer update` aft { "type": "git", "url": "git@github.com:jgauthi/component_debug.git" } ], "require-dev": { - "jgauthi/component_debug": "1.*" + "jgauthi/component_debug": "2.*" } } ``` diff --git a/src/DebugHandler.php b/src/DebugHandler.php index 12c1a7a..cbe2a14 100644 --- a/src/DebugHandler.php +++ b/src/DebugHandler.php @@ -18,7 +18,7 @@ class DebugHandler // * valeur: interface (ajoute les interfaces init dans l'apply, peut se cumuler) // // Pour cumuler plusieurs valeurs: debug=defined|function - static public function init() + static public function init(): void { // Désactiver volontairement le debug if (isset($_GET['nodebug'])) { @@ -49,7 +49,7 @@ static public function init() /** * @param string|bool $debugMode */ - static private function activeDebug($debugMode) + static private function activeDebug($debugMode): void { if ($debugMode == 'false') { return; @@ -65,7 +65,7 @@ static private function activeDebug($debugMode) * @param string|bool $debugMode * @throws \ReflectionException */ - static public function rapportFooter($debugMode = true) + static public function rapportFooter($debugMode = true): void { // Mettre fin au timer $duration = ceil((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000); @@ -105,7 +105,7 @@ static public function rapportFooter($debugMode = true) * @param string|bool $debugMode * @throws \ReflectionException */ - static protected function dumpValues($debugMode) + static protected function dumpValues($debugMode): void { $dumpFunction = 'var_dump'; if (function_exists('dump')) { @@ -248,10 +248,7 @@ function ($className) { unset($export); } - /** - * @return string - */ - static private function getCurrentMemory() + static private function getCurrentMemory(): string { $memory = memory_get_usage(); $unit = ['o', 'ko', 'mo', 'go', 'to', 'po']; @@ -261,10 +258,7 @@ static private function getCurrentMemory() return $memory; } - /** - * @return bool - */ - static public function isWordpressProject() + static public function isWordpressProject(): bool { static $isWordpress = null; diff --git a/src/DebugUtils.php b/src/DebugUtils.php index dc8a112..6d3fd89 100644 --- a/src/DebugUtils.php +++ b/src/DebugUtils.php @@ -8,11 +8,8 @@ class DebugUtils /** * Allows you to return a well-formatted and clean SQL html from a query * @todo Improve by adding an argument $htmlFormat = true|false - * @param string $query - * @param array $arguments - * @return string */ - public static function SqlClean($query, $arguments) + static public function SqlClean(string $query, ?array $arguments): string { if (!empty($arguments)) { $query = str_replace( diff --git a/src/Timer.php b/src/Timer.php index e6749d0..83d1088 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 [2mars2007] - * @version: 1.2 + * @version: 2.0 *******************************************************************************/ @@ -11,39 +11,24 @@ class Timer { - const EXPORT_FORMAT_HTML = 'html'; - const EXPORT_FORMAT_COMMENT = 'commentaire'; - - /** @var float */ - protected $startTime; - /** @var array */ - protected $time = []; - /** @var array */ - protected $chapterTimes = []; - /** @var bool */ - private $sendHeaderHttp; - /** @var string */ - protected $result; - /** @var string */ - protected $step; - /** @var string */ - protected $chapter; - - /** - * @param bool $header - */ - public function __construct($header = false) + public const EXPORT_FORMAT_HTML = 'html'; + public const EXPORT_FORMAT_COMMENT = 'commentaire'; + + 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) { $this->startTime = microtime(true); $this->sendHeaderHttp = $header; } - /** - * @param bool $header - * @param string $format - * @return self - */ - static public function init($header = false, $format = self::EXPORT_FORMAT_HTML) + static public function init(bool $header = false, string $format = self::EXPORT_FORMAT_HTML): self { $timer = new self($header); $timer->shutdown($format); @@ -51,35 +36,22 @@ static public function init($header = false, $format = self::EXPORT_FORMAT_HTML) return $timer; } - //-- ÉTALONNER LE PARCOURS DU SCRIPT -------------- - - /** - * @param string $nom - * @return self - */ - public function step($nom) + //-- ETALONNER LE PARCOURS DU SCRIPT -------------- + public function step(string $nom): self { $this->time[] = ['nom' => $nom, 'time' => microtime(true)]; return $this; } - /** - * @param string $nom - * @return self - */ - public function chapterStart($nom) + public function chapterStart(string $nom): self { $this->chapterTimes[$nom] = ['start' => microtime(true)]; return $this; } - /** - * @param string $nom - * @return self - */ - public function chapterEnd($nom) + public function chapterEnd(string $nom): self { $this->chapterTimes[$nom]['end'] = microtime(true); @@ -88,10 +60,7 @@ public function chapterEnd($nom) //-- METTRE FIN AU COMPTEUR - /** - * @return self - */ - public function stop() + public function stop(): self { $endTime = microtime(true); @@ -137,11 +106,7 @@ public function stop() return $this; } - /** - * @param string|null $type - * @return string - */ - public function outPut($type = null) + public function outPut(?string $type = null): string { $output = ''; @@ -165,30 +130,20 @@ public function outPut($type = null) return $output; } - /** - * @param string $format - */ - public function end($format = self::EXPORT_FORMAT_HTML) + public function end(string $format = self::EXPORT_FORMAT_HTML): void { $this->stop(); echo $this->outPut($format); } - /** - * @param string $format - */ - public function shutdown($format = self::EXPORT_FORMAT_HTML) + public function shutdown(string $format = self::EXPORT_FORMAT_HTML): void { register_shutdown_function([$this, 'end'], $format); } //-- CONVERTISSEUR --------------------------------- - /** - * @param float $time - * @return string - */ - protected function _conv($time) + protected function _conv(float $time): string { return $time * 1000; // return mb_substr($time * 1000, 0, 6); @@ -198,25 +153,14 @@ protected function _conv($time) // Remplace . par , (écriture FR) } - /** - * @param float $chiffre - * @return string - */ - protected function number_format($chiffre) + protected function number_format(float $chiffre): string { return number_format($chiffre, 2, ',', ' '); } //-- Outil de test/debug ------------------------------- - /** - * @param callable $function - * @param int $nb_loop - * @param int $nb - * @param array $args - * @return self - */ - public function testLoop($function, $nb_loop = 10, $nb = 100, $args = []) + public function testLoop(callable $function, int $nb_loop = 10, int $nb = 100, array $args = []): self { $chapitre = preg_replace('#[^a-z0-9-_]#i', '', mb_substr($function, 0, 50)); @@ -234,10 +178,8 @@ public function testLoop($function, $nb_loop = 10, $nb = 100, $args = []) /** * Exporte un chapitre au format CSV. - * @param string $filename - * @param string $delimiter */ - public function exportChapter($filename, $delimiter = ';') + public function exportChapter(string $filename, string $delimiter = ';'): void { // Analyse des chapitres if (empty($this->chapterTimes)) { diff --git a/src/VarDumperServer.php b/src/VarDumperServer.php index 21c0691..b663cd3 100644 --- a/src/VarDumperServer.php +++ b/src/VarDumperServer.php @@ -13,10 +13,8 @@ use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\CliDumper; -use Symfony\Component\VarDumper\Dumper\ContextProvider\CliContextProvider; -use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider; -use Symfony\Component\VarDumper\Dumper\HtmlDumper; -use Symfony\Component\VarDumper\Dumper\ServerDumper; +use Symfony\Component\VarDumper\Dumper\ContextProvider\{CliContextProvider, SourceContextProvider}; +use Symfony\Component\VarDumper\Dumper\{HtmlDumper, ServerDumper}; use Symfony\Component\VarDumper\VarDumper; class VarDumperServer @@ -24,7 +22,7 @@ class VarDumperServer /** * @param string $host The server host */ - public static function init($host = 'tcp://127.0.0.1:9912') + static public function init(string $host = 'tcp://127.0.0.1:9912'): void { if (!class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) { die('var-dumper not installed.'); diff --git a/src/VarExport.php b/src/VarExport.php index a49c6a0..a89a697 100644 --- a/src/VarExport.php +++ b/src/VarExport.php @@ -9,9 +9,8 @@ //------------------------------------------------- /** * @param mixed $var - * @return string */ -function varExportReturnValue($var) +function varExportReturnValue($var): string { if (null === $var) { $var = '# NULL #'; @@ -32,10 +31,12 @@ function varExportReturnValue($var) return $var; } -// Utiliser dump si possible -function varExport() +/** + * Utiliser dump si possible + * @param mixed ...$args + */ +function varExport(... $args) { - $args = func_get_args(); foreach($args as $var) { $var = varExportReturnValue($var); echo '
'. htmlentities($var, ENT_QUOTES, 'UTF-8') .'

'; @@ -45,11 +46,9 @@ function varExport() /** * @param mixed ...$args - * @return array */ -function varExportData() +function varExportData(... $args): array { - $args = func_get_args(); $data = []; foreach ($args as $var) { $data[] = varExportReturnValue($var); @@ -58,10 +57,11 @@ function varExportData() return $data; } -function varComment() +/** + * @param mixed ...$args + */ +function varComment(... $args): void { - $args = func_get_args(); - echo "