Skip to content

Commit

Permalink
Fixed PHP 8.4 implicit nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
solital committed Sep 12, 2024
1 parent d94949f commit 1c2b140
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 111 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Released Notes

## v3.3.5 - (2024-09-12)

### Fixed

- Fixed PHP 8.4 implicit nullable

--------------------------------------------------------------------------

## v3.3.4 - (2024-09-05)

### Fixed
Expand Down
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brenno-duarte/modern-php-exception",
"description": "PHP errors in a modern way",
"description": "Display PHP errors and exceptions in a modern and intuitive way",
"license": "MIT",
"keywords": [
"exception",
Expand Down Expand Up @@ -29,10 +29,5 @@
"psr-4": {
"Test\\": "tests/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
42 changes: 10 additions & 32 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ function var_dump_debug(...$values): void
CliDump::set('string', ['0000FF', 'light_blue']);
new CliDump($value);

if (!CliMessage::colorIsSupported() || !CliMessage::are256ColorsSupported()) {
if (!CliMessage::colorIsSupported() || !CliMessage::are256ColorsSupported())
CliDump::safe($value);
}
} else {
$dump = new BrowserDump();
echo $dump->dump($value);
Expand Down Expand Up @@ -106,15 +105,11 @@ function closure_dump(\Closure $c): string
$s .= getClass($p)->name . ' ';
}

if ($p->isPassedByReference()) {
$s .= '&';
}

if ($p->isPassedByReference()) $s .= '&';
$s .= '$' . $p->name;

if ($p->isOptional()) {
if ($p->isOptional())
$s .= ' = ' . var_export($p->getDefaultValue(), TRUE);
}

$params[] = $s;
}
Expand All @@ -140,43 +135,26 @@ function closure_dump(\Closure $c): string
function getClass(\ReflectionParameter $parameter): ?\ReflectionClass
{
$type = $parameter->getType();

if (!$type || $type->isBuiltin()) {
return null;
}
if (!$type || $type->isBuiltin()) return null;

// This line triggers autoloader!
if (!class_exists($type->getName())) {
return null;
}

if (!class_exists($type->getName())) return null;
return new \ReflectionClass($type->getName());
}
}

if (!function_exists('isCli')) {
function isCli(): bool
{
if (defined('STDIN')) {
return true;
}

if (php_sapi_name() === "cli") {
return true;
}

if (PHP_SAPI === 'cli') {
return true;
}

if (stristr(PHP_SAPI, 'cgi') and getenv('TERM')) {
return true;
}
if (defined('STDIN')) return true;
if (php_sapi_name() === "cli") return true;
if (PHP_SAPI === 'cli') return true;
if (stristr(PHP_SAPI, 'cgi') and getenv('TERM')) return true;

if (
empty($_SERVER['REMOTE_ADDR']) and
!isset($_SERVER['HTTP_USER_AGENT']) and
count($_SERVER['argv']) > 0
count ((array)$_SERVER["argv"])
) {
return true;
}
Expand Down
7 changes: 3 additions & 4 deletions index-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
//$config = "";
$exc = new ModernPHPException($config);
//$exc->enableOccurrences();
$exc->ignoreErrors([E_USER_DEPRECATED, E_WARNING]);
//$exc->ignoreErrors([E_USER_DEPRECATED, E_WARNING]);
$exc->start();

#http_response_code(404);
#echo '<pre>';

//throw new Exception("<script>alert('test from JS')</script>");

trigger_error("Test trigger", E_USER_DEPRECATED);
echo "After trigger function";
/* trigger_error("Test trigger", E_USER_DEPRECATED);
echo "After trigger function"; */

//UserTest::staticCall();

Expand All @@ -37,7 +37,6 @@
//echo $e->getMessage();
} */


/* $a = (new UserTest())->secondCall();
var_dump_debug($a, true); */

Expand Down
22 changes: 9 additions & 13 deletions src/Bench.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function start(): void
public function end(): void
{
if (!$this->hasStarted()) throw new LogicException("You must call start()");

$this->end_time = microtime(true);
$this->memory_usage = memory_get_usage(true);
}
Expand All @@ -49,12 +48,12 @@ public function end(): void
* Returns the elapsed time, readable or not
*
* @param bool $raw
* @param string $format The format to display (printf format)
* @param null|string $format The format to display (printf format)
*
* @return mixed
* @throws LogicException
*/
public function getTime(bool $raw = false, string $format = null): mixed
public function getTime(bool $raw = false, ?string $format = null): mixed
{
if (!$this->hasStarted()) throw new LogicException("You must call start()");
if (!$this->hasEnded()) throw new LogicException("You must call end()");
Expand All @@ -66,21 +65,21 @@ public function getTime(bool $raw = false, string $format = null): mixed
/**
* Returns the memory usage at the end checkpoint
*
* @param bool $readable Whether the result must be human readable
* @param string $format The format to display (printf format)
* @param bool $readable Whether the result must be human readable
* @param null|string $format The format to display (printf format)
*
* @return mixed
*/
public function getMemoryUsage(bool $raw = false, string $format = null): mixed
public function getMemoryUsage(bool $raw = false, ?string $format = null): mixed
{
return $raw ? $this->memory_usage : self::readableSize($this->memory_usage, $format);
}

/**
* Returns the memory peak, readable or not
*
* @param bool $readable Whether the result must be human readable
* @param string $format The format to display (printf format)
* @param bool $readable Whether the result must be human readable
* @param null|string $format The format to display (printf format)
*
* @return mixed
*/
Expand All @@ -104,19 +103,17 @@ public function run(callable $callable): mixed
{
$arguments = func_get_args();
array_shift($arguments);

$this->start();
$result = call_user_func_array($callable, $arguments);
$this->end();

return $result;
}

/**
* Returns a human readable memory size
*
* @param int $size
* @param string $format The format to display (printf format)
* @param null|string $format The format to display (printf format)
* @param int $round
*
* @return string
Expand All @@ -139,7 +136,7 @@ public static function readableSize(int $size, ?string $format = null, int $roun
* Returns a human readable elapsed time
*
* @param float $microtime
* @param string $format The format to display (printf format)
* @param null|string $format The format to display (printf format)
* @param int $round
*
* @return string
Expand All @@ -154,7 +151,6 @@ public static function readableElapsedTime(float $microtime, ?string $format = n
} else {
$unit = 'ms';
$time = round($microtime * 1000);

$format = preg_replace('/(%.[\d]+f)/', '%d', $format);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ModernPHPException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ModernPHPException
{
use HelpersTrait, HandlerAssetsTrait, RenderTrait;

public const VERSION = "3.3.4";
public const VERSION = "3.3.5";

/**
* @var Bench
Expand Down
Loading

0 comments on commit 1c2b140

Please sign in to comment.