Skip to content

Multi line use statements are fixed wrong by ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName #1581

@klausi

Description

@klausi

Use statements can be grouped and span multiple lines, example:

<?php

/**
 * @file
 * Example.
 */

use Test\MultiLine as MultiLineAlias,
    Test\MultiLineSecond;

$a = new MultiLineAlias();
$b = new MultiLineSecond();

Reported error: Constant Test\MultiLineSecond should not be referenced via a fully qualified name, but via a use statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName)

That is misleading, no constant is defined here.

Furthermore the file is fixed wrong and results in broken code:

<?php

/**
 * @file
 * Example.
 */

$a = new MultiLineAlias();
$b = new \MultiLineSecond();

The use statement is completely deleted.

I saw that there was some discussion that Slevomat does not support multiline use statements in #1547 and #1554, but then the fixer should at least ignore those and not generate broken PHP files.

Background: trying to replace Drupal Coder's custom use statement sniff with your upstream code to avoid maintaining it in pfrenssen/coder#199

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions