Skip to content

Auto-fixing issue encountered with inconsistent use of braces #940

Closed
@jedi58

Description

@jedi58

The below example is taken from ADOdb/ADOdb's replicate include:

    foreach ($sql as $s)
        if (!$this->execute) echo "<pre>",$s.";\n</pre>";
        else {
            $ok = $this->connDest->Execute($s);
            if (!$ok)
                if ($this->neverAbort) $ret = false;
                else return false;
        }

In this example, what causes the issue is the lack of braces. When phpcbf encounters the for, and then the else, it is putting braces around the block it believes to be the for-statement and then around the if but then moves the else to become part of the for which will cause a fatal error in PHP. The result of running phpcbf --standard=PSR2 is:

        foreach ($sql as $s) {
            if (!$this->execute) {
                echo "<pre>",$s.";\n</pre>";
            }
        } else {
            $ok = $this->connDest->Execute($s);
            if (!$ok) {
                if ($this->neverAbort) {
                    $ret = false;
                }
            } else {
                return false;
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions