public function convertErrorToException(Error $error) { switch (true) { case StringUtil::startsWith($error->getErrorMessage(), 'Undefined variable: '): return new UndefinedVariableException($error); case StringUtil::startsWith($error->getErrorMessage(), 'Undefined index: '): return new UndefinedIndexException($error); case StringUtil::startsWith($error->getErrorMessage(), 'Undefined property: '): return new UndefinedPropertyException($error); case StringUtil::endsWith($error->getErrorMessage(), ': File exists'): return new FileAlreadyExistsException($error); case StringUtil::endsWith($error->getErrorMessage(), 'failed to open stream: No such file or directory'): return new FileNotFoundException($error); case $error->getErrorMessage() == 'Division by zero': return new DivisionByZeroException($error); case StringUtil::startsWith($error->getErrorMessage(), 'Use of undefined constant '): return new UndefinedConstantException($error); case preg_match('/Argument [0-9]+ passed to .* must ((be an instance of)|implement)/', $error->getErrorMessage()) > 0: return new UnexpectedTypeException($error); } return new ErrorException($error); }
public function __construct(Error $error) { parent::__construct($error->getErrorMessage(), 0, $error->getErrorNumber(), $error->getOriginatingFile(), $error->getOriginatingFileLine()); }