for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace BestIt\CodeSniffer\Helper;
use BestIt\CodeSniffer\CodeError;
use BestIt\CodeSniffer\CodeWarning;
use PHP_CodeSniffer\Files\File;
/**
* Registers the exception as an error or warning on the file.
*
* @author blange <[email protected]>
* @package BestIt\CodeSniffer
*/
class ExceptionHelper
{
* The sniffed file.
* @var File
private $file;
* ExceptionHelper constructor.
* @param File $file The sniffed file.
public function __construct(File $file)
$this->file = $file;
}
* @param CodeWarning $exception The error which should be handled.
* @return bool Should this error be fixed?
public function handleException(CodeWarning $exception): bool
$isError = $exception instanceof CodeError;
$isFixable = $exception->isFixable();
$method = 'add';
if ($isFixable) {
$method .= 'Fixable';
$method .= $isError ? 'Error' : 'Warning';
return $this->file->$method(
$exception->getMessage(),
$exception->getStackPosition(),
$exception->getCode(),
$exception->getPayload()
);