ThrowableUtils.php 865 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\ErrorHandler;
  11. use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
  12. /**
  13. * @internal
  14. */
  15. class ThrowableUtils
  16. {
  17. public static function getSeverity(SilencedErrorContext|\Throwable $throwable): int
  18. {
  19. if ($throwable instanceof \ErrorException || $throwable instanceof SilencedErrorContext) {
  20. return $throwable->getSeverity();
  21. }
  22. if ($throwable instanceof \ParseError) {
  23. return \E_PARSE;
  24. }
  25. if ($throwable instanceof \TypeError) {
  26. return \E_RECOVERABLE_ERROR;
  27. }
  28. return \E_ERROR;
  29. }
  30. }