Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The statement if must contain its code within a {} block is reported incorrectly #32

Open
jbrooksuk opened this issue Sep 2, 2014 · 5 comments
Labels

Comments

@jbrooksuk
Copy link
Contributor

This code:

App::error(function(Exception $exception, $code) {
    Log::error($exception);
    if (Config::get('app.debug') === FALSE && $code <> 404) {
        switch ($code) {
            case 401: $errorTitle = 'Unauthorized'; break;
            case 403: $errorTitle = 'Forbidden'; break;
            // case 404: $errorTitle = 'Not Found'; break;
            case 408: $errorTitle = 'Request Timeout'; break;
            case 500: $errorTitle = 'Internal Server Error'; break;
            case 502: $errorTitle = 'Gateway Timeout'; break;
            case 503: $errorTitle = 'Service Unavailable'; break;
            case 508: $errorTitle = 'Loop detected'; break;
            default: $errorTitle  = 'Unknown Error';
        }

        $hasView = View::exists('errors.' . $code);

        return Response::view('errors.' . ($hasView ? $code : 500), [
            'errorCode'  => $code,
            'exception'  => $exception,
            'errorTitle' => $errorTitle
        ], $code);
    }
});

Is being reported as needing the if condition to be in its own block. The problem is that it already is.

I don't think that I've broken this?

@jbrooksuk
Copy link
Contributor Author

@tchule I've narrowed down the issue to being anything which calls a function within the condition itself. See this test file I've just added.

@jbrooksuk
Copy link
Contributor Author

If you remove the App::error closure and only leave the condition, it's fine.

@jbrooksuk
Copy link
Contributor Author

The offending code is:

if (!$this->tokenizer->checkNextValidToken(T_BRACES_OPEN)) {
    $msg = $this->_getMessage('NEED_BRACES', $stmt);
    $this->_writeError('needBraces', $msg);
}

It's too strict. The code only needs to be concerned with the fact that it ends with a {.

That, or we need a way of knowing if a control statement contains a body. This is where an AST would be useful.

@tchule
Copy link
Contributor

tchule commented Feb 10, 2017

Problem occurs because the closing parenthese after debug') is considered as the end of the IF, nextValidToken is then === instead of {

Should count the opening and closing parentheses.

@tchule
Copy link
Contributor

tchule commented Feb 13, 2017

Humm, ok, we already count the opening/closing.

Problem is in "_processParenthesisClose()", this part of the code existed before we used a stack. We use flags to know if we are in a function call or a control statement. But we fail to recognize the anonymous function structure. These flags should be replaced by a proper use of the statement stack, but it impacts a lot of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants