RemovedCallingDestructAfterConstructorExit: reduce false positives by jrfnl · Pull Request #1227 · PHPCompatibility/PHPCompatibility
Follow up on PR 1200 which introduced this sniff. > This sniff will throw an error, even when there is no destructor as a destructor may be declared in a parent class. > 👉 We could reduce the potential noise from this sniff a little further by only throwing the error when the class either contains a __destruct() method or extends a parent class. Should we ? This PR implements the above by: * Checking for a `__destruct()` method. If one is found, an error will be thrown. * If no `__destruct()` method was found, but the class either extends another class or `use`s a trait, it will throw a _warning_ instead as a `__destruct()` method may still be declared in the parent class or the trait. * If no `__destruct()` method is found and the class does not extend another, nor use `trait`s, the sniff will stay silent. Includes implementing protection against false positives for calls to `exit()` found in nested closed constructs within a `__construct()` method. Includes efficiency tweaks to in case of large `__construct()` methods with high code complexity.