Skip to content

PSR12.Files.FileHeader misidentifies file header in mixed content file #1330

@okainov

Description

@okainov

Describe the bug

I'm getting 2 | ERROR | The file header must be the first content in the file (PSR12.Files.FileHeader.HeaderPosition) when <?php is in the middle of a mixed file when followed by docstring-like comment.

Code sample

<div></div>
<?php

/*** Comment - this is important, only comment in such format triggers the issue ***/

$b = 3;

Custom ruleset

N/A

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs -s --standard=PSR12 test.php
  3. See error message displayed
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------
 2 | ERROR | The file header must be the first content in the file (PSR12.Files.FileHeader.HeaderPosition)

Expected behavior

No error expected in this case

Versions (please complete the following information)

Operating System Windows, Docker
PHP version 7.4
PHP_CodeSniffer version PHP_CodeSniffer version 3.13.2 (stable) , 4.0.1 (stable)
Standard PSR12
Install type Composer in docker container

Additional context

Add any other context about the problem here.

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the 4.x branch of PHP_CodeSniffer.

See also squizlabs/PHP_CodeSniffer#2732

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions