Skip to content

False-positive in SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator #1835

@rosasurfer

Description

@rosasurfer

Given the following sniff configuration:

<rule ref="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator">
  <properties>
    <property name="lineLengthLimit" value="100"/>
  </properties>
</rule>

and the following test file/code:

<?php
declare(strict_types=1);

class PHPTest {

    public static function testPhpCs(): void {
        $config = isset($_GET['config']);
        ?>
        <a href="?">
           <?=$config ? 'Hide' : 'Show'?> Configuration
        </a>
        <?php
        echo '';
    }
}

Expected result: no error

Actual result:

Image

The false-positive shows up depending on the terminating semicolon after the ternary. Without it, PHPCS scan until the next ; in the code which commonly exceeds the configured line limit.

However, in PHP the closing tag has the same function as a semicolon (statement terminator).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions