2019-10-13 05:59:52 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2024-01-02 02:40:38 +00:00
|
|
|
namespace Rector\Exception;
|
2018-01-03 19:19:31 +00:00
|
|
|
|
|
|
|
use Exception;
|
2019-09-21 11:03:30 +00:00
|
|
|
use Throwable;
|
2022-06-07 08:22:29 +00:00
|
|
|
final class ShouldNotHappenException extends Exception
|
2018-01-03 19:19:31 +00:00
|
|
|
{
|
2020-11-01 15:57:12 +00:00
|
|
|
/**
|
|
|
|
* @param string $message
|
|
|
|
* @param int $code
|
|
|
|
*/
|
2022-06-07 08:22:29 +00:00
|
|
|
public function __construct($message = '', $code = 0, ?Throwable $throwable = null)
|
2019-09-21 11:03:30 +00:00
|
|
|
{
|
|
|
|
if ($message === '') {
|
|
|
|
$message = $this->createDefaultMessageWithLocation();
|
|
|
|
}
|
|
|
|
parent::__construct($message, $code, $throwable);
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
private function createDefaultMessageWithLocation() : string
|
2019-09-21 11:03:30 +00:00
|
|
|
{
|
2021-05-09 20:15:43 +00:00
|
|
|
$debugBacktrace = \debug_backtrace();
|
2022-01-15 10:33:01 +00:00
|
|
|
$class = $debugBacktrace[2]['class'] ?? null;
|
|
|
|
$function = $debugBacktrace[2]['function'];
|
|
|
|
$line = $debugBacktrace[1]['line'] ?? 0;
|
2022-01-08 00:28:55 +00:00
|
|
|
$method = $class !== null ? $class . '::' . $function : $function;
|
2022-02-05 10:39:52 +00:00
|
|
|
/** @var string $method */
|
|
|
|
/** @var int $line */
|
2021-05-09 20:15:43 +00:00
|
|
|
return \sprintf('Look at "%s()" on line %d', $method, $line);
|
2019-09-21 11:03:30 +00:00
|
|
|
}
|
2018-01-03 19:19:31 +00:00
|
|
|
}
|