-
-
Notifications
You must be signed in to change notification settings - Fork 186
Closed
Description
SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName
is importing functions from the same namespace.
I'm testing out a new ruleset on zendframework/zend-diactoros. After fixing the code with phpcbf I noticed functions within the same namespace are imported. e.g. Zend\Diactoros\marshalHeadersFromSapi
is imported in Zend\Diactoros\ServerRequestFactory
. Doing this, PHP can't find the function anymore. The correct way would be to detect the function namespace and ignore it if it's in the same namespace.
Expected:
<?php
declare(strict_types=1);
namespace Zend\Diactoros;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use function array_key_exists;
use function is_callable;
class ServerRequestFactory implements ServerRequestFactoryInterface {}
Result after running phpcbf:
<?php
declare(strict_types=1);
namespace Zend\Diactoros;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use function array_key_exists;
use function is_callable;
// These function are in the Zend\Diactoros namespace:
use function marshalHeadersFromSapi;
use function marshalMethodFromSapi;
use function marshalProtocolVersionFromSapi;
use function marshalUriFromSapi;
use function normalizeServer;
use function normalizeUploadedFiles;
use function parseCookieHeader;
class ServerRequestFactory implements ServerRequestFactoryInterface {}
phpcs report
FILE: ~/zend-diactoros/src/functions/normalize_uploaded_files.php
----------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------------------------------
58 | ERROR | [x] Function createUploadedFile() should not be referenced via a fallback global name, but via a use
| | statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
118 | ERROR | [x] Function createUploadedFile() should not be referenced via a fallback global name, but via a use
| | statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
----------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------
FILE: ~/zend-diactoros/src/ServerRequestFactory.php
----------------------------------------------------------------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 7 LINES
----------------------------------------------------------------------------------------------------------------------------
59 | ERROR | [x] Function normalizeServer() should not be referenced via a fallback global name, but via a use
| | statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
63 | ERROR | [x] Function normalizeUploadedFiles() should not be referenced via a fallback global name, but via a use
| | statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
64 | ERROR | [x] Function marshalHeadersFromSapi() should not be referenced via a fallback global name, but via a use
| | statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
67 | ERROR | [x] Function parseCookieHeader() should not be referenced via a fallback global name, but via a use
| | statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
73 | ERROR | [x] Function marshalUriFromSapi() should not be referenced via a fallback global name, but via a use
| | statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
74 | ERROR | [x] Function marshalMethodFromSapi() should not be referenced via a fallback global name, but via a use
| | statement. (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
80 | ERROR | [x] Function marshalProtocolVersionFromSapi() should not be referenced via a fallback global name, but via a
| | use statement.
| | (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName)
----------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------
froschdesign