Skip to content

PSR12.Operators.OperatorSpacing false positive #3098

@morozov

Description

@morozov

Describe the bug
The sniff doesn't recognize unary minus applied to a number used with theexit language construct.

Code sample

<?php

function test()
{
    exit -1;
}

Custom ruleset
None.

To reproduce
Steps to reproduce the behavior:

  1. Run phpcs -s --standard=PSR12 --sniffs=PSR12.Operators.OperatorSpacing test.php
FILE: /home/morozov/Projects/phpcs-playground/test.php
------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------
 5 | ERROR | [x] Expected at least 1 space after "-"; 0 found
   |       |     (PSR12.Operators.OperatorSpacing.NoSpaceAfter)
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------

Time: 33ms; Memory: 6MB
  1. Run phpcbf --standard=PSR12 --sniffs=PSR12.Operators.OperatorSpacing test.php
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
/home/morozov/Projects/phpcs-playground/test.php      1      0
----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------

Time: 37ms; Memory: 6MB

The resulting file contents are:

<?php

function test()
{
    exit - 1;
}

Expected behavior
No error is reported.

Versions (please complete the following information):

  • OS: Linux
  • PHP: 7.4.9
  • PHPCS: 3.5.6
  • Standard: PSR-12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions