Skip to content

Generic InlineControlStructureSniff does not support alternative SWITCH syntax #497

Closed
@pmamat

Description

@pmamat

test.phtml: (it's a Zend view script / template)

<?php 
switch ($this->error):
    case Shop_Customer :: ERROR_INVALID_GENDER: ?>
        Ung&uuml;ltiges Geschlecht!
    <?php break;
    case Shop_Customer :: ERROR_EMAIL_IN_USE: ?>
        Die eingetragene E-Mail-Adresse ist bereits registriert.
    <?php break;
endswitch;
?>

phpcs.xml:

<?xml version="1.0"?>
<ruleset>
    <description>Test coding standard</description>

    <file>test.phtml</file>

    <arg name="extensions" value="php,phtml" />

    <arg name="tab-width" value="4"/>
    <arg name="encoding" value="utf-8"/>


    <arg name="report" value="full"/>

    <arg value="np"/>

    <rule ref="Generic.ControlStructures.InlineControlStructure" />

</ruleset>

Output:

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 2 | ERROR | [x] Inline control structures are not allowed
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

The BIG problem is that after running phpcbf the code is broken:
test.phtml: (after repair attempt)

<?php 
switch ($this->error) { :
    case Shop_Customer :: ERROR_INVALID_GENDER: ?>
        Ung&uuml;ltiges Geschlecht!
    <?php break };
    case Shop_Customer :: ERROR_EMAIL_IN_USE: ?>
        Die eingetragene E-Mail-Adresse ist bereits registriert.
    <?php break;
endswitch;
?>

Now there are wrong brackets:

Parse error: syntax error, unexpected ':', expecting case (T_CASE) or default (T_DEFAULT) or '}' in test.phtml on line 2
Errors parsing test.phtml

Hope you can reproduce this.

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