Skip to content

Commit

Permalink
Upgrade to php7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauthi committed Sep 13, 2020
1 parent 89b6159 commit 671b3e3
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 162 deletions.
2 changes: 1 addition & 1 deletion 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": ">=5.6",
"php": ">=7.4",
"ext-mbstring": "*",
"jdorn/sql-formatter": "^1.2"
},
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Edit your [composer.json](https://getcomposer.org) (launch `composer update` aft
{ "type": "git", "url": "[email protected]:jgauthi/component_debug.git" }
],
"require-dev": {
"jgauthi/component_debug": "1.*"
"jgauthi/component_debug": "2.*"
}
}
```
Expand Down
18 changes: 6 additions & 12 deletions src/DebugHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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'];
Expand All @@ -261,10 +258,7 @@ static private function getCurrentMemory()
return $memory;
}

/**
* @return bool
*/
static public function isWordpressProject()
static public function isWordpressProject(): bool
{
static $isWordpress = null;

Expand Down
5 changes: 1 addition & 4 deletions src/DebugUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
110 changes: 26 additions & 84 deletions src/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,55 @@
* @name: Timer
* @note: Stopwatch in milliseconds script time+ the various steps in the code
* @author: Jgauthi <github.com/jgauthi>, created at [2mars2007]
* @version: 1.2
* @version: 2.0
*******************************************************************************/

namespace Jgauthi\Component\Debug;

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);

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);

Expand All @@ -88,10 +60,7 @@ public function chapterEnd($nom)

//-- METTRE FIN AU COMPTEUR

/**
* @return self
*/
public function stop()
public function stop(): self
{
$endTime = microtime(true);

Expand Down Expand Up @@ -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 = '';

Expand All @@ -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);
Expand All @@ -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));

Expand All @@ -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)) {
Expand Down
8 changes: 3 additions & 5 deletions src/VarDumperServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@

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
{
/**
* @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.');
Expand Down
Loading

0 comments on commit 671b3e3

Please sign in to comment.