PHP code example of raffaelecarelle / php-error-insight

1. Go to this page and download the library: Download raffaelecarelle/php-error-insight library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raffaelecarelle / php-error-insight example snippets


use PhpErrorInsight\Config;

$config = Config::fromEnvAndArray([
    'projectRoot' => __DIR__,
    'editorUrl' => 'vscode://file/%file:%line',
]);

use PhpErrorInsight\Config;
use PhpErrorInsight\ErrorExplainer;

/ none | local | api
    'model' => 'llama3:instruct',
    'language'=> 'en',
    'verbose' => true,
]);

ErrorExplainer::register($config); // sets up error and exception handlers

// Generate an error to see the output
strpos();

// tests/bootstrap.php

use PhpErrorInsight\Config;
use PhpErrorInsight\ErrorExplainer;

se 'text' for console output
    'verbose' => false,
    'editorUrl' => 'phpstorm://open?file=%file&line=%line',
    'projectRoot' => dirname(__DIR__),
]);

ErrorExplainer::register($config);

function login(string $username, #[SensitiveParameter] string $password) {
    // If an error occurs here, $password will be masked as ***REDACTED***
    // in all error outputs (HTML, CLI, JSON) and AI prompts
}

use PhpErrorInsight\Internal\Util\SensitiveParameterSanitizer;

$sanitizer = new SensitiveParameterSanitizer('[HIDDEN]');

use PhpErrorInsight\Config;

$config = Config::fromEnvAndArray([
    'consoleColors' => [
        'severity' => [ 'error' => 'magenta', 'warning' => 'yellow', 'info' => 'blue' ],
        'styles' => [ 'title' => ['white', null, ['bold']], 'suggestion' => ['cyan', null, []] ],
        'tokens' => [ 'keyword' => ['magenta', null, ['bold']], 'string' => ['green', null, []] ],
    ],
]);
bash
composer 
bash
export PHP_ERROR_INSIGHT_BACKEND=local export PHP_ERROR_INSIGHT_MODEL=llama3:instruct export PHP_ERROR_INSIGHT_API_URL=[http://localhost:11434](http://localhost:11434)
bash
export PHP_ERROR_INSIGHT_BACKEND=api
export PHP_ERROR_INSIGHT_MODEL=gpt-4o-mini
export PHP_ERROR_INSIGHT_API_KEY=sk-...
export PHP_ERROR_INSIGHT_API_URL=https://api.openai.com/v1/chat/completions
bash
export PHP_ERROR_INSIGHT_BACKEND=anthropic
export PHP_ERROR_INSIGHT_MODEL=claude-3-5-sonnet-20240620
export PHP_ERROR_INSIGHT_API_KEY=api-key
# optional override
# export PHP_ERROR_INSIGHT_API_URL=https://api.anthropic.com/v1/messages
bash
export PHP_ERROR_INSIGHT_BACKEND=google
export PHP_ERROR_INSIGHT_MODEL=gemini-1.5-flash
export PHP_ERROR_INSIGHT_API_KEY=api-key
# optional override
# export PHP_ERROR_INSIGHT_API_URL=https://generativelanguage.googleapis.com/v1/models
bash
export PHP_ERROR_INSIGHT_ROOT=/path/to/your/project
export PHP_ERROR_INSIGHT_EDITOR="vscode://file/%file:%line"
bash
export PHP_ERROR_INSIGHT_ROOT=/path/to/your/project
export PHP_ERROR_INSIGHT_EDITOR="phpstorm://open?file=%file&line=%line"
bash
# inside container, your app root is mounted from /Users/you/project
export PHP_ERROR_INSIGHT_ROOT=/var/www/app
export PHP_ERROR_INSIGHT_HOST_ROOT=/Users/you/project
export PHP_ERROR_INSIGHT_EDITOR="vscode://file/%file:%line"
bash
export PHP_ERROR_INSIGHT_ROOT=/var/www/app
export PHP_ERROR_INSIGHT_HOST_ROOT=/Users/you/project
export PHP_ERROR_INSIGHT_EDITOR="phpstorm://open?file=%file&line=%line"
xml
<!-- phpunit.xml.dist -->
<phpunit bootstrap="tests/bootstrap.php"
         colors="true">
    ...
</phpunit>
bash
export PHP_ERROR_INSIGHT_CONSOLE_COLORS='{
  "severity": {"error":"magenta","warning":"yellow","info":"cyan"},
  "styles": {"title":["white",null,["bold"]],"suggestion":["cyan",null,[]]},
  "tokens": {"keyword":["magenta",null,["bold"]],"string":["green",null,[]]}
}'