Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 1.14 KB

syntax-error-callback.md

File metadata and controls

31 lines (25 loc) · 1.14 KB

Syntax Error Callback

  1. Set a path to a file with custom error callback to --syntax-error-callback option.
  2. Create a class implementing PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback interface. File with the class must have the same name as the class inside.
  3. Modify error before it is printed to the output.

Example configuration

File MyCustomErrorHandler.php will be passed as an argument like ./parallel-lint --syntax-error-callback ./path/to/MyCustomErrorHandler.php ..
The content should look like:

use PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback;
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;

class MyCustomErrorHandler implements SyntaxErrorCallback {
    /**
     * @param SyntaxError $error
     * @return SyntaxError
     */
    public function errorFound(SyntaxError $error){
        // Return new SyntaxError with custom modification to FilePath or Message
        // Or return custom implementation of SyntaxError extending the original one...
        return new SyntaxError(
            $error->getFilePath(),
            $error->getMessage()
        );
    }
}