Skip to content

Generic InlineControlStructureSniff does not support alternative SWITCH syntax #497

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

Closed
pmamat opened this issue Feb 19, 2015 · 9 comments
Closed

Comments

@pmamat
Copy link

pmamat commented Feb 19, 2015

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.

@gsherwood gsherwood changed the title Problem in Generic_Sniffs_ControlStructures_InlineControlStructureSniff with alternative syntax for control structures Generic InlineControlStructureSniff does not support alternative syntax SWITCH Feb 25, 2015
@gsherwood gsherwood changed the title Generic InlineControlStructureSniff does not support alternative syntax SWITCH Generic InlineControlStructureSniff does not support alternative SWITCH syntax Feb 25, 2015
gsherwood added a commit that referenced this issue Feb 25, 2015
@gsherwood
Copy link
Member

Thanks for the report and sample code. The problem was actually with the core tokenizer not supporting the alternate syntax for SWITCH, although it did for other control structures. This is fixed now.

@aik099
Copy link
Contributor

aik099 commented Feb 25, 2015

Nice. And seeing how small changes needed are to support this syntax are even nicer.

@pmamat
Copy link
Author

pmamat commented Feb 26, 2015

@gsherwood Thanks a lot for your reply and debugging. Unfortunatly I would like you to reopen the issue, since the problem is not fixed entirely. I encountered the same problem in a different spot:

test.phtml:

<?php if ($this->allowShopping !== true): ?>
    <?php if ($this->status != Shop_Cart :: OK): ?>
        ...
        <?php switch ($this->status):
            case Shop_Cart :: NOT_FOUND: ?>
            ...
        <?php endswitch; ?>
        ...
    <?php endif; ?>
<?php else: ?>
    ...
<?php endif; ?>

Output:

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

Repair attempt:

<?php if ($this->allowShopping !== true) { } ?>
    <?php if ($this->status != Shop_Cart :: OK): ?>
        ...
        <?php switch ($this->status):
            case Shop_Cart :: NOT_FOUND: ?>
            ...
        <?php endswitch; ?>
        ...
    <?php endif; ?>
<?php else: ?>
    ...
<?php endif; ?>

edit / hint: when removing the switch block or the else command, everything works as smooth as supposed without an error.

@gsherwood
Copy link
Member

I'll take a look.

@pmamat
Copy link
Author

pmamat commented Feb 26, 2015

@gsherwood Thanks for your fast reply. Please note my edit / hint

@gsherwood
Copy link
Member

The problem is actually the lack of a breaking statement for the case. PHPCS is not correctly assigning the endswitch token to be a shared closer for both the case and the switch, as it does when you use normal braces.

The end result is a mismatch of statements in the tokenizer, which causes the sniff to see the original IF statement as having no opener and no closer.

gsherwood added a commit that referenced this issue Mar 1, 2015
…switch didnt close case statements with no break (further fix for #497)
@gsherwood
Copy link
Member

I've pushed a fix for this.

@aik099
Copy link
Contributor

aik099 commented Mar 2, 2015

Thanks. Now short control structure syntax users will be happy.

@pmamat
Copy link
Author

pmamat commented Mar 2, 2015

Thanks a lot for fixing!

rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Jul 26, 2024
This commit adds tests to safeguard against regressions related to
squizlabs/PHP_CodeSniffer#497. The commit
related to this issue (b24b96b) originally added a few tests to a
sniff test (InlineControlStructureUnitTest.php) as back then there
were no Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored in a previous commit to use different
control structure.
jrfnl pushed a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Jul 26, 2024
This commit adds tests to safeguard against regressions related to
squizlabs/PHP_CodeSniffer#497. The commit
related to this issue (b24b96b) originally added a few tests to a
sniff test (InlineControlStructureUnitTest.php) as back then there
were no Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored in a previous commit to use different
control structure.
jrfnl added a commit to jrfnl/PHP_CodeSniffer that referenced this issue Jul 29, 2024
…tion-call-argument-spacing

Generic/FunctionCallArgumentSpacing: improve code coverage
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 8, 2024
This commit adds tests to safeguard against regressions related to
b24b96b which was added to fix one of the issues in
squizlabs/PHP_CodeSniffer#497. b24b96b
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. This test was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 8, 2024
This commit adds tests to safeguard against regressions related to
fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` is missing shares the closer with
`T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
b24b96b which was added to fix one of the issues in
squizlabs/PHP_CodeSniffer#497. b24b96b
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. This test was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` is missing shares the closer with
`T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
b24b96b which was added to fix one of the issues in
squizlabs/PHP_CodeSniffer#497. b24b96b
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. This test was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` is missing shares the closer with
`T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
b24b96b which was added to fix one of the issues in
squizlabs/PHP_CodeSniffer#497. b24b96b
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. This test was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` is missing shares the closer with
`T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
b24b96b which was added to fix one of the issues in
squizlabs/PHP_CodeSniffer#497. b24b96b
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. This test was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` is missing shares the closer with
`T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` is missing shares the closer with
`T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` shares the scope closer with `T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
b24b96b which was added to fix one of the issues in
squizlabs/PHP_CodeSniffer#497. b24b96b
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. This test was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Aug 13, 2024
This commit adds tests to safeguard against regressions related to
fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
originally added a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` shares the scope closer with `T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored in a previous commit to use different
control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to the tokenizer tests. Originally,
the moved test was added in b24b96b which is part of
squizlabs/PHP_CodeSniffer#497. b24b96b
introduce a test to a sniff test (InlineControlStructureUnitTest.php)
as back then there were no Tokenizer tests. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

The commit also adds a test to unsure scope is set correctly when using
the normal switch syntax. This was not part of b24b96b, but relevant
anyway as there are no previous tokenizer test covering this part.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to tokenizer tests. Originally, the test
was added in fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` shares the scope closer with `T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to the tokenizer tests. Originally,
the moved test was added in b24b96b which is part of
squizlabs/PHP_CodeSniffer#497. b24b96b
introduce a test to a sniff test (InlineControlStructureUnitTest.php)
as back then there were no Tokenizer tests. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

The commit also adds a test to unsure scope is set correctly when using
the normal switch syntax. This was not part of b24b96b, but relevant
anyway as there are no previous tokenizer test covering this part.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to tokenizer tests. Originally, the test
was added in fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` shares the scope closer with `T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to the tokenizer tests. Originally,
the moved test was added in b24b96b which is part of
squizlabs/PHP_CodeSniffer#497. b24b96b
introduce a test to a sniff test (InlineControlStructureUnitTest.php)
as back then there were no Tokenizer tests. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

The commit also adds a test to unsure scope is set correctly when using
the normal switch syntax. This was not part of b24b96b, but relevant
anyway as there are no previous tokenizer test covering this part.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to tokenizer tests. Originally, the test
was added in fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` shares the scope closer with `T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to the tokenizer tests. Originally,
the moved test was added in b24b96b which is part of
squizlabs/PHP_CodeSniffer#497. b24b96b
introduce a test to a sniff test (InlineControlStructureUnitTest.php)
as back then there were no Tokenizer tests. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

The commit also adds a test to unsure scope is set correctly when using
the normal switch syntax. This was not part of b24b96b, but relevant
anyway as there are no previous tokenizer test covering this part.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to tokenizer tests. Originally, the test
was added in fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` shares the scope closer with `T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to the tokenizer tests. Originally,
the moved test was added in b24b96b which is part of
squizlabs/PHP_CodeSniffer#497. b24b96b
introduce a test to a sniff test (InlineControlStructureUnitTest.php)
as back then there were no Tokenizer tests. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the T_SWITCH token when handling a `switch` that uses the alternative
syntax.

The commit also adds a test to unsure scope is set correctly when using
the normal switch syntax. This was not part of b24b96b, but relevant
anyway as there are no previous tokenizer test covering this part.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in b24b96b became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit moves a sniff test to tokenizer tests. Originally, the test
was added in fddc61a which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to a sniff test
(InlineControlStructureUnitTest.php) as back then there were no
Tokenizer tests. Those tests were added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_CASE` token when it shares the closer with `T_SWITCH` and to
`T_IF` when a nested `T_CASE` shares the scope closer with `T_SWITCH`.

Now that the InlineControlStructure sniff doesn't listen for the
T_SWITCH token anymore, the original test added in fddc61a became
useless and thus was refactored to use different control structure.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit copies, with some modifications, a sniff test to the
tokenizer tests. The original test was added in b24b96b, part of
squizlabs/PHP_CodeSniffer#497. b24b96b
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_SWITCH` token when handling a `switch` that uses the alternative
syntax.

This commit also adds a test to ensure the scope is correctly set when
using the normal switch syntax. This was not part of b24b96b, but it is
relevant anyway, as no other tokenizer test covers this part.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in b24b96b became
useless and thus was refactored to use a different control structure.
The sniff test was kept as testing code that uses a control structure,
and opening and closing PHP tags is an interesting case not covered in
other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit copies, with some modifications, a sniff test to the
tokenizer tests. The original test was added in fddc61a, which is part
of squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit copies, with some non-structural modifications, a sniff
test to the tokenizer tests. The original test was added in b24b96b,
part of squizlabs/PHP_CodeSniffer#497. b24b96b
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_SWITCH` token when handling a `switch` that uses the alternative
syntax.

This commit also adds a test to ensure the scope is correctly set when
using the normal switch syntax. This was not part of b24b96b, but it is
relevant anyway, as no other tokenizer test covers this part.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in b24b96b became
useless and thus was refactored to use a different control structure.
The sniff test was kept as testing code that uses a control structure,
and opening and closing PHP tags is an interesting case not covered in
other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit copies, with some modifications, a sniff test to the
tokenizer tests. The original test was added in fddc61a, which is part
of squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit copies, with some modifications, a sniff test to the
tokenizer tests. The original test was added in fddc61a, which is part
of squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 9, 2024
This commit copies, with some non-structural modifications, a sniff test
to the tokenizer tests. Two new tokenizer tests are created as the
result of this copy. One to ensure that the scope of `T_CASE` is
correctly set when the case shares the scope closer with `T_SWITCH`
(no `T_BREAK`). And another to ensure that the scope of `T_IF` is
correctly set when there is a nested `T_SWITCH` and `T_CASE` without a
`T_BREAK`.

The original sniff test was added in fddc61a, which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 25, 2024
This commit copies, with some non-structural modifications, a sniff
test to the tokenizer tests. The original test was added in b24b96b,
part of squizlabs/PHP_CodeSniffer#497. b24b96b
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_SWITCH` token when handling a `switch` that uses the alternative
syntax.

This commit also adds a test to ensure the scope is correctly set when
using the normal switch syntax. This was not part of b24b96b, but it is
relevant anyway, as no other tokenizer test covers this part.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in b24b96b became
useless and thus was refactored to use a different control structure.
The sniff test was kept as testing code that uses a control structure,
and opening and closing PHP tags is an interesting case not covered in
other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 25, 2024
This commit copies, with some non-structural modifications, a sniff test
to the tokenizer tests. Two new tokenizer tests are created as the
result of this copy. One to ensure that the scope of `T_CASE` is
correctly set when the case shares the scope closer with `T_SWITCH`
(no `T_BREAK`). And another to ensure that the scope of `T_IF` is
correctly set when there is a nested `T_SWITCH` and `T_CASE` without a
`T_BREAK`.

The original sniff test was added in fddc61a, which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 25, 2024
This commit copies, with some non-structural modifications, a sniff
test to the tokenizer tests. The original test was added in b24b96b,
part of squizlabs/PHP_CodeSniffer#497. b24b96b
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_SWITCH` token when handling a `switch` that uses the alternative
syntax.

This commit also adds a test to ensure the scope is correctly set when
using the normal switch syntax. This was not part of b24b96b, but it is
relevant anyway, as no other tokenizer test covers this part.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in b24b96b became
useless and thus was refactored to use a different control structure.
The sniff test was kept as testing code that uses a control structure,
and opening and closing PHP tags is an interesting case not covered in
other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 25, 2024
This commit copies, with some non-structural modifications, a sniff test
to the tokenizer tests. Two new tokenizer tests are created as the
result of this copy. One to ensure that the scope of `T_CASE` is
correctly set when the case shares the scope closer with `T_SWITCH`
(no `T_BREAK`). And another to ensure that the scope of `T_IF` is
correctly set when there is a nested `T_SWITCH` and `T_CASE` without a
`T_BREAK`.

The original sniff test was added in fddc61a, which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 28, 2024
This commit copies, with some non-structural modifications, a sniff
test to the tokenizer tests. The original test was added in b24b96b,
part of squizlabs/PHP_CodeSniffer#497. b24b96b
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_SWITCH` token when handling a `switch` that uses the alternative
syntax.

This commit also adds a test to ensure the scope is correctly set when
using the normal switch syntax. This was not part of b24b96b, but it is
relevant anyway, as no other tokenizer test covers this part.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in b24b96b became
useless and thus was refactored to use a different control structure.
The sniff test was kept as testing code that uses a control structure,
and opening and closing PHP tags is an interesting case not covered in
other tests.
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Oct 28, 2024
This commit copies, with some non-structural modifications, a sniff test
to the tokenizer tests. Two new tokenizer tests are created as the
result of this copy. One to ensure that the scope of `T_CASE` is
correctly set when the case shares the scope closer with `T_SWITCH`
(no `T_BREAK`). And another to ensure that the scope of `T_IF` is
correctly set when there is a nested `T_SWITCH` and `T_CASE` without a
`T_BREAK`.

The original sniff test was added in fddc61a, which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
jrfnl pushed a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Dec 20, 2024
This commit copies, with some non-structural modifications, a sniff
test to the tokenizer tests. The original test was added in b24b96b,
part of squizlabs/PHP_CodeSniffer#497. b24b96b
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_SWITCH` token when handling a `switch` that uses the alternative
syntax.

This commit also adds a test to ensure the scope is correctly set when
using the normal switch syntax. This was not part of b24b96b, but it is
relevant anyway, as no other tokenizer test covers this part.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in b24b96b became
useless and thus was refactored to use a different control structure.
The sniff test was kept as testing code that uses a control structure,
and opening and closing PHP tags is an interesting case not covered in
other tests.
jrfnl pushed a commit to rodrigoprimo/PHP_CodeSniffer that referenced this issue Dec 20, 2024
This commit copies, with some non-structural modifications, a sniff test
to the tokenizer tests. Two new tokenizer tests are created as the
result of this copy. One to ensure that the scope of `T_CASE` is
correctly set when the case shares the scope closer with `T_SWITCH`
(no `T_BREAK`). And another to ensure that the scope of `T_IF` is
correctly set when there is a nested `T_SWITCH` and `T_CASE` without a
`T_BREAK`.

The original sniff test was added in fddc61a, which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
jrfnl pushed a commit to PHPCSStandards/PHP_CodeSniffer that referenced this issue Dec 20, 2024
This commit copies, with some non-structural modifications, a sniff
test to the tokenizer tests. The original test was added in b24b96b,
part of squizlabs/PHP_CodeSniffer#497. b24b96b
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. It was added to ensure that
Tokenizer::recurseScopeMap() would correctly add scope information to
the `T_SWITCH` token when handling a `switch` that uses the alternative
syntax.

This commit also adds a test to ensure the scope is correctly set when
using the normal switch syntax. This was not part of b24b96b, but it is
relevant anyway, as no other tokenizer test covers this part.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in b24b96b became
useless and thus was refactored to use a different control structure.
The sniff test was kept as testing code that uses a control structure,
and opening and closing PHP tags is an interesting case not covered in
other tests.
jrfnl pushed a commit to PHPCSStandards/PHP_CodeSniffer that referenced this issue Dec 20, 2024
This commit copies, with some non-structural modifications, a sniff test
to the tokenizer tests. Two new tokenizer tests are created as the
result of this copy. One to ensure that the scope of `T_CASE` is
correctly set when the case shares the scope closer with `T_SWITCH`
(no `T_BREAK`). And another to ensure that the scope of `T_IF` is
correctly set when there is a nested `T_SWITCH` and `T_CASE` without a
`T_BREAK`.

The original sniff test was added in fddc61a, which is part of
squizlabs/PHP_CodeSniffer#497. fddc61a
introduced a test to InlineControlStructureUnitTest.php as there were no
Tokenizer tests back then. The test was added to ensure that
Tokenizer::recurseScopeMap() correctly adds scope information to the
`T_CASE` token when it shares the closer with `T_SWITCH` and to `T_IF`
when a nested `T_CASE` shares the scope closer with T_SWITCH`.

Since the InlineControlStructure sniff doesn't listen for the `T_SWITCH`
token anymore (see baa4f65), the original test added in fddc61a became
useless and thus was refactored to use a different control structure.
This new version of the sniff test was kept as testing code that uses
nested alternative syntax control structures is still valid and is not
covered in other tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants