Skip to content

Commit

Permalink
Improve Error package
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 26, 2023
1 parent 3a99d70 commit 4fda294
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ErrorLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use function array_search;
use function error_reporting;

use const ARRAY_FILTER_USE_KEY;
use const E_ALL;
use const E_COMPILE_ERROR;
use const E_COMPILE_WARNING;
Expand Down Expand Up @@ -116,7 +117,7 @@ public function value(): int

public function contains(self|string|int ...$levels): bool
{
if ([] === $levels || 0 === $this->value) {
if ([] === $levels) {
return false;
}

Expand All @@ -130,6 +131,10 @@ public function contains(self|string|int ...$levels): bool
return true;
}

if (0 === $this->value) {
return false;
}

foreach ($levels as $level) {
if (1 > $level || $level !== ($this->value & $level)) {
return false;
Expand All @@ -138,4 +143,28 @@ public function contains(self|string|int ...$levels): bool

return true;
}

/**
* @return array<string>
*/
public function included(): array
{
return array_values(array_filter(
self::LEVELS,
fn (int $error): bool => 0 !== ($error & $this->value),
ARRAY_FILTER_USE_KEY
));
}

/**
* @return array<string>
*/
public function excluded(): array
{
return array_values(array_filter(
self::LEVELS,
fn (int $error): bool => 0 === ($error & $this->value),
ARRAY_FILTER_USE_KEY
));
}
}

0 comments on commit 4fda294

Please sign in to comment.