/** * Check for unused code. * * Dead code after a return or a throw TOKEN. * * @param String $endToken * The name of the end token (RETURN or THROW) */ private function _checkUnusedCode($endToken) { if ($this->_isActive('checkUnusedCode')) { // The check is done only when we are at the root level of a function if ($this->statementStack->getCurrentStackItem()->type == 'FUNCTION') { // Find the end of the return statement $pos = $this->tokenizer->findNextStringPosition(';'); // Find the next valid token after the return statement $nextValidToken = $this->tokenizer->peekNextValidToken($pos + 1); // Find the end of the function or bloc of code $posClose = $this->tokenizer->findNextStringPosition('}'); // If the end of bloc if not right after the return statement, we have dead code if ($nextValidToken != null && $posClose > $nextValidToken->position) { $msg = $this->_getMessage('UNUSED_CODE', $this->statementStack->getCurrentStackItem()->name, $endToken); $this->_writeError('checkUnusedCode', $msg); } } } }