Skip to content
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

[PHP] Auto formatting does not handle use ordering #6717

Open
terax6669 opened this issue Nov 17, 2023 · 0 comments
Open

[PHP] Auto formatting does not handle use ordering #6717

terax6669 opened this issue Nov 17, 2023 · 0 comments
Labels
kind:bug Bug report or fix needs:triage Requires attention from one of the committers PHP [ci] enable extra PHP tests (php/php.editor)

Comments

@terax6669
Copy link

Apache NetBeans version

Apache NetBeans 20 release candidate

What happened

https://www.php-fig.org/per/coding-style/#3-declare-statements-namespace-and-import-statements

The header of a PHP file may consist of a number of different blocks. If present, each of the blocks below MUST be separated by a single blank line, and MUST NOT contain a blank line. Each block MUST be in the order listed below, although blocks that are not relevant may be omitted.

  • Opening <?php tag.
  • File-level docblock.
  • One or more declare statements.
  • The namespace declaration of the file.
  • One or more class-based use import statements.
  • One or more function-based use import statements.
  • One or more constant-based use import statements.
  • The remainder of the code in the file.

When using Source > Format (alt+shift+F) NetBeans correctly detect the blocks and separates them, but the order is not enforced. Only Source > Fix Imports (ctrl+shift+I) fixes the order.

<?php

declare(strict_types=1);

namespace Vendor\Package;

use const PHP_EOL;

use Aws\ControlTower\ControlTowerClient;

use function array_merge;

use TCG\Voyager\Http\Controllers\Controller;

Uses placed after a class are breaking things even further.

declare(strict_types=1);

namespace Vendor\Package;

use const PHP_EOL;

use Aws\ControlTower\ControlTowerClient;

use function array_merge;

class Point
{
	
}

use TCG\Voyager\Http\Controllers\Controller;

ctrl+shift+I

<?php

declare(strict_types=1);

namespace Vendor\Package;

class Point
{
	
}

use Aws\ControlTower\ControlTowerClient;
use TCG\Voyager\Http\Controllers\Controller;

use function array_merge;

use const PHP_EOL;

This additionally breaks the "singe new-line at the end of file" rule, leaving 2 new lines.

How to reproduce

No response

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 11

JDK

21.0.1

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

@terax6669 terax6669 added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Nov 17, 2023
@junichi11 junichi11 added the PHP [ci] enable extra PHP tests (php/php.editor) label Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix needs:triage Requires attention from one of the committers PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

No branches or pull requests

2 participants