src/Tool/UnreachableCatch.php
public function run(string $file, Node $node): array
    {
        while (count($node->children) >= 2) {
            $catch = array_shift($node->children);

            // If the class specification includes `Throwable`, doesn't allow any catch expressions after that.
            if ($this->isIncludeThrowableNode($catch)) {
                foreach ($node->children as $after_catch) {
                    if (!$this->isIncludeThrowableNode($after_catch)) {
                        return [new Hint(
                            self::HINT_TYPE,
                            self::HINT_MESSAGE,
                            $file,
                            $after_catch->lineno,
                            self::HINT_LINK
                        )];
                    }
                }
            }

            // If the class specification includes `Exception`, doesn't allow catch expressions other than `Throwable` after that.
            if ($this->isIncludeExceptionNode($catch)) {
                foreach ($node->children as $after_catch) {
                    if (!$this->isIncludeExceptionNode($after_catch)
                          && !$this->isIncludeThrowableNode($after_catch)) {
                        return [new Hint(
                            self::HINT_TYPE,
                            self::HINT_MESSAGE,
                            $file,
                            $after_catch->lineno,
                            self::HINT_LINK
                        )];
                    }
                }
            }
        }

        return [];
    }
public function run(string $file, Node $node): array
    {
        while (count($node->children) >= 2) {
            $catch = array_shift($node->children);

            // If the class specification includes `Throwable`, doesn't allow any catch expressions after that.
            if ($this->isIncludeThrowableNode($catch)) {
                foreach ($node->children as $after_catch) {
                    if (!$this->isIncludeThrowableNode($after_catch)) {
                        return [new Hint(
                            self::HINT_TYPE,
                            self::HINT_MESSAGE,
                            $file,
                            $after_catch->lineno,
                            self::HINT_LINK
                        )];
                    }
                }
            }

            // If the class specification includes `Exception`, doesn't allow catch expressions other than `Throwable` after that.
            if ($this->isIncludeExceptionNode($catch)) {
                foreach ($node->children as $after_catch) {
                    if (!$this->isIncludeExceptionNode($after_catch)
                          && !$this->isIncludeThrowableNode($after_catch)) {
                        return [new Hint(
                            self::HINT_TYPE,
                            self::HINT_MESSAGE,
                            $file,
                            $after_catch->lineno,
                            self::HINT_LINK
                        )];
                    }
                }
            }
        }

        return [];
    }
public function run ( string $ file , Node $ node ) : array { while ( count ( $ node -> children ) >= 2 ) { $ catch = array_shift ( $ node -> children ) ; // If the class specification includes `Throwable`, doesn't allow any catch expressions after that. if ( $ this -> isIncludeThrowableNode ( $ catch ) ) { foreach ( $ node -> children as $ after_catch ) { if ( ! $ this -> isIncludeThrowableNode ( $ after_catch ) ) { return [ new Hint ( self :: HINT_TYPE , self :: HINT_MESSAGE , $ file , $ after_catch -> lineno , self :: HINT_LINK ) ] ; } } } // If the class specification includes `Exception`, doesn't allow catch expressions other than `Throwable` after that. if ( $ this -> isIncludeExceptionNode ( $ catch ) ) { foreach ( $ node -> children as $ after_catch ) { if ( ! $ this -> isIncludeExceptionNode ( $ after_catch ) && ! $ this -> isIncludeThrowableNode ( $ after_catch ) ) { return [ new Hint ( self :: HINT_TYPE , self :: HINT_MESSAGE , $ file , $ after_catch -> lineno , self :: HINT_LINK ) ] ; } } } } return [ ] ; }
Detect a catch expression not reachable by catch expressions of `Exception` or `Throwable`

@param string $file File name to be analyzed.
@param Node   $node AST node to be analyzed.
@return Hint[] List of hints obtained from results.
Detect a catch expression not reachable by catch expressions of Exception or Throwable