Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
117673f
chore: organize files, code, and project structure for better clarity…
wazabii8 Apr 11, 2025
8c32e26
Organize files, code, and project structure for better clarity and ma…
wazabii8 Apr 12, 2025
392003e
Update README.md
wazabii8 Apr 14, 2025
5a624bf
Improve comment blocks in ExceptionItem class
wazabii8 Apr 27, 2025
b0c52d6
Show the expected exception class name
wazabii8 Apr 30, 2025
5620c5e
Quality code improvements
wazabii8 May 1, 2025
a1713e0
Updated ansi path
wazabii8 May 3, 2025
b7640ad
Add a comment to Blunder main exception
wazabii8 May 4, 2025
5b82428
feat: Enable trace debugging by default in CLI Handler
wazabii8 May 7, 2025
84fd791
refactor: replace function null checks with strict comparisons
wazabii8 May 9, 2025
3f39cd5
bugfix: Make class::method work in trance
wazabii8 May 19, 2025
d66b578
Add a soft exception that can be used to throw notices
wazabii8 May 20, 2025
8ec606b
Correct serverty flag on CLI, text and XML handlers
wazabii8 Jun 1, 2025
d354382
Add .idea to ignore file
wazabii8 Jun 1, 2025
3c770c5
fix: Do not word wrap in CLI handler
danielRConsid Aug 10, 2025
1a0c8e0
fix: Disable or change exit code on error
danielRConsid Aug 16, 2025
8645740
Add CLI exception message template
danielRConsid Aug 28, 2025
2b1a306
refactor: clean up and organize codebase
wazabii8 Oct 26, 2025
c749d22
chore: minor adjustments
wazabii8 Oct 26, 2025
ca0bd73
Add new Exception
wazabii8 Nov 24, 2025
a1e4353
fix: change tests and test patterns
wazabii8 Nov 24, 2025
74eb5a3
feat: make it posible to modifie trace
wazabii8 Jan 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.DS_Store
.sass-cache
composer.lock
vendor
vendor
.idea/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Instead of letting PHP handle the excluded severities, you can redirect them to
```php
$run = new Run(new HtmlHandler());
$run->severity()
->excludeSeverityLevels([E_WARNING, E_USER_WARNING])
->excludeSeverityLevels([E_DEPRECATED, E_USER_DEPRECATED])
->redirectTo(function ($errNo, $errStr, $errFile, $errLine) {
error_log("Custom log: $errStr in $errFile on line $errLine");
return true; // Suppresses output for excluded severities
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "maplephp/blunder",
"type": "library",
"version": "v1.2.1",
"description": "Blunder is a well-designed PHP error handling framework.",
"keywords": [
"php",
Expand All @@ -27,12 +26,12 @@
}
],
"require": {
"php": ">=8.0",
"maplephp/http": "^1.0",
"maplephp/prompts": "^1.0"
"php": ">=8.2",
"maplephp/http": "^2.0",
"maplephp/prompts": "^1.2"
},
"require-dev": {
"maplephp/unitary": "^1.0"
"maplephp/unitary": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
50 changes: 0 additions & 50 deletions src/BlunderErrorException.php

This file was deleted.

133 changes: 133 additions & 0 deletions src/Enums/BlunderErrorType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

/**
* Enum BlunderErrorType
*
* Defines all supported PHP error types in a structured, strongly-typed way.
* Each enum case maps to a PHP error constant, including its numeric value,
* name (e.g. E_WARNING), and a user-friendly title.
*
* Provides utility methods for retrieving metadata, matching error codes to enum cases,
* and listing all known error levels for use in severity filtering and error reporting.
*
* @package MaplePHP\Blunder\Enums
* @author Daniel Ronkainen
* @license Apache-2.0 license, Copyright © Daniel Ronkainen
* Don't delete this comment, it's part of the license.
*/

namespace MaplePHP\Blunder\Enums;

enum BlunderErrorType
{
case FALLBACK;
case ERROR;
case WARNING;
case PARSE;
case NOTICE;
case CORE_ERROR;
case CORE_WARNING;
case COMPILE_ERROR;
case COMPILE_WARNING;
case USER_ERROR;
case USER_WARNING;
case USER_NOTICE;
case RECOVERABLE_ERROR;
case DEPRECATED;
case USER_DEPRECATED;

/**
* A single source of truth for constant value, constant name, and title.
*
* @var array<string, array{int, string, string}>
*/
private const MAP = [
'FALLBACK' => [0, 'E_USER_ERROR', 'Fallback error'],
'ERROR' => [E_ERROR, 'E_ERROR', 'Fatal error'],
'WARNING' => [E_WARNING, 'E_WARNING', 'Warning'],
'PARSE' => [E_PARSE, 'E_PARSE', 'Parse error'],
'NOTICE' => [E_NOTICE, 'E_NOTICE', 'Notice'],
'CORE_ERROR' => [E_CORE_ERROR, 'E_CORE_ERROR', 'Core fatal error'],
'CORE_WARNING' => [E_CORE_WARNING, 'E_CORE_WARNING', 'Core warning'],
'COMPILE_ERROR' => [E_COMPILE_ERROR, 'E_COMPILE_ERROR', 'Compile-time fatal error'],
'COMPILE_WARNING' => [E_COMPILE_WARNING, 'E_COMPILE_WARNING', 'Compile-time warning'],
'USER_ERROR' => [E_USER_ERROR, 'E_USER_ERROR', 'User fatal error'],
'USER_WARNING' => [E_USER_WARNING, 'E_USER_WARNING', 'User warning'],
'USER_NOTICE' => [E_USER_NOTICE, 'E_USER_NOTICE', 'User notice'],
'RECOVERABLE_ERROR' => [E_RECOVERABLE_ERROR, 'E_RECOVERABLE_ERROR', 'Recoverable fatal error'],
'DEPRECATED' => [E_DEPRECATED, 'E_DEPRECATED', 'Deprecated notice'],
'USER_DEPRECATED' => [E_USER_DEPRECATED, 'E_USER_DEPRECATED', 'User deprecated notice'],
'E_ALL' => [E_ALL, 'E_ALL', 'All'],
];


/**
* Retrieve all PHP constant values that are mapped, either preserving the original keys or as a flat list.
*
* @param bool $preserveKeys If true, retains the original keys. Otherwise, returns a flat indexed array.
* @return array<int> List of PHP constant values.
*/
public static function getAllErrorLevels(bool $preserveKeys = false): array
{
$items = self::MAP;
array_shift($items);
$arr = array_map(fn ($item) => $item[0], $items);
if ($preserveKeys) {
return $arr;
}
return array_values($arr);
}

/**
* Get the PHP constant value associated with this error type.
*
* @return int The constant value corresponding to the enum case.
*/
public function getErrorLevel(): int
{
return self::MAP[$this->name][0];
}


/**
* Get the PHP constant key (name) associated with this error type.
*
* @return string The constant key corresponding to the enum case.
*/
public function getErrorLevelKey(): string
{
return self::MAP[$this->name][1];
}


/**
* Get the user-friendly title for this error type.
* If the error type is `FALLBACK`, a custom fallback title is returned.
*
* @param string $fallback Custom fallback title used if the error type is `FALLBACK`. Defaults to 'Error'.
* @return string The user-friendly title associated with this error type.
*/
public function getErrorLevelTitle(string $fallback = 'Error'): string
{
return $this === self::FALLBACK ? $fallback : self::MAP[$this->name][2];
}

/**
* Get the enum instance corresponding to the specified error number.
*
* If the error number does not match any predefined case, it returns the default fallback case.
*
* @param int $errno The error number to find the corresponding enum case for.
* @return self The matching enum case, or the fallback case if no match is found.
*/
public static function fromErrorLevel(int $errno): self
{
$cases = self::cases();
foreach ($cases as $case) {
if ($case->getErrorLevel() === $errno) {
return $case;
}
}
return reset($cases);
}
}
Loading
Loading