From 2976a27ee0757fcdb0134d7682acf3dbf08a3252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gytis=20=C5=A0k=C4=97ma?= Date: Fri, 24 May 2024 11:22:57 +0300 Subject: [PATCH] fix: Catch `Throwable` when doing reflection, for fatal errors --- CHANGELOG.md | 4 ++++ src/Sniffs/CodeElement/IteratorItemTypeSniff.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa9bf14..c75262e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to `phpcs-type-sniff` will be documented in this file. Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## 81.6.2 - 2024-05-24 +### Fixed +- Catch `Throwable` when doing reflection, for fatal errors + ## 81.6.1 - 2024-05-23 ### Changed - Limit `IteratorAggregate` item type tag check to direct implementation only, exclude parents for now diff --git a/src/Sniffs/CodeElement/IteratorItemTypeSniff.php b/src/Sniffs/CodeElement/IteratorItemTypeSniff.php index 96f8f42..45e46d0 100644 --- a/src/Sniffs/CodeElement/IteratorItemTypeSniff.php +++ b/src/Sniffs/CodeElement/IteratorItemTypeSniff.php @@ -2,7 +2,6 @@ namespace Gskema\TypeSniff\Sniffs\CodeElement; -use Error; use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnElement; use Gskema\TypeSniff\Core\CodeElement\Element\ClassElement; use Gskema\TypeSniff\Core\CodeElement\Element\CodeElementInterface; @@ -11,6 +10,7 @@ use PHP_CodeSniffer\Files\File; use ReflectionClass; use ReflectionException; +use Throwable; class IteratorItemTypeSniff implements CodeElementSniffInterface { @@ -46,7 +46,7 @@ public function process(File $file, CodeElementInterface $element, CodeElementIn { try { $ref = new ReflectionClass($element->getFqcn()); - } catch (Error | ReflectionException) { + } catch (Throwable | ReflectionException) { return; // give up... }