Skip to content

Commit

Permalink
Fix instantiation check for Cloack
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 26, 2023
1 parent b77ac48 commit 9a84d41
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Error/Cloak.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Closure;
use ErrorException;

use ValueError;
use function error_reporting;
use function restore_error_handler;
use function set_error_handler;
Expand All @@ -18,14 +19,22 @@ class Cloak
public const THROW = 2;

protected static bool $useException = false;

protected CloakedErrors $errors;
protected readonly ErrorLevel $errorLevel;

/**
* @throws ValueError
*/
public function __construct(
protected readonly Closure $closure,
protected readonly int $onError = self::FOLLOW_ENV,
ErrorLevel|string|int|null $errorLevel = null
) {
if (!in_array($this->onError, [self::SILENT, self::THROW, self::FOLLOW_ENV], true)) {
throw new ValueError('The `onError` value is invalid; expect one of the `' . self::class . '` constants.');
}

$this->errorLevel = match (true) {
$errorLevel instanceof ErrorLevel => $errorLevel,
is_string($errorLevel) => ErrorLevel::fromName($errorLevel),
Expand Down

0 comments on commit 9a84d41

Please sign in to comment.