Skip to content

Commit 19ca952

Browse files
authored
✨ Add SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions
1 parent 7bc86ad commit 19ca952

6 files changed

+56
-8
lines changed

PreviousNextDrupal/ruleset.xml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
<!-- SlevomatCodingStandard.Namespaces -->
4949
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
50+
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions" />
5051

5152
<!-- SlevomatCodingStandard.TypeHints -->
5253
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ function doesAThing(array $data): int {
138138
#### SlevomatCodingStandard.Functions.StaticClosure
139139
#### SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure
140140
#### SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
141+
#### SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions
142+
143+
PHPStorm can be configured with Editor -> General -> Auto Import: _Function_: `Prefer FQN`
144+
141145
#### SlevomatCodingStandard.TypeHints.DeclareStrictTypes
142146
#### SlevomatCodingStandard.TypeHints.ReturnTypeHint
143147
#### SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing

composer.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
"homepage": "https://github.com/previousnext/coding-standard",
55
"keywords": ["drupal", "phpcs"],
66
"require": {
7-
"php": "^8.0",
7+
"php": "^8.1",
88
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
99
"drupal/coder": "^8.3.24",
10-
"slevomat/coding-standard": "^8.13.2",
11-
"squizlabs/php_codesniffer": "^3.7.1"
10+
"slevomat/coding-standard": "^8.15.0",
11+
"squizlabs/php_codesniffer": "^3.10.1"
1212
},
1313
"require-dev": {
14-
"phpstan/extension-installer": "^1.2",
15-
"phpstan/phpstan": "^1.9.4",
16-
"phpstan/phpstan-deprecation-rules": "^1.1.1",
17-
"phpstan/phpstan-strict-rules": "^1.4.4",
18-
"phpunit/phpunit": "^9.5.27"
14+
"phpstan/extension-installer": "^1.3.1",
15+
"phpstan/phpstan": "^1.11.3",
16+
"phpstan/phpstan-deprecation-rules": "^1.2.0",
17+
"phpstan/phpstan-strict-rules": "^1.6.0",
18+
"phpunit/phpunit": "^9.6.19"
1919
},
2020
"license": "MIT",
2121
"autoload": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PreviousNext\CodingStandard\Tests\Sniffs;
6+
7+
use SlevomatCodingStandard\Sniffs\Namespaces\FullyQualifiedGlobalFunctionsSniff;
8+
9+
/**
10+
* @covers \SlevomatCodingStandard\Sniffs\Namespaces\FullyQualifiedGlobalFunctionsSniff
11+
*/
12+
final class FullyQualifiedGlobalFunctionsTest extends Base {
13+
14+
public function testNoError(): void {
15+
$report = self::checkFile(__DIR__ . '/fixtures/FullyQualifiedGlobalFunctionsNoError.php');
16+
self::assertNoSniffErrorInFile($report);
17+
}
18+
19+
public function testError(): void {
20+
$report = self::checkFile(__DIR__ . '/fixtures/FullyQualifiedGlobalFunctionsError.php');
21+
self::assertSame(1, $report->getErrorCount());
22+
self::assertSniffError($report, 7, FullyQualifiedGlobalFunctionsSniff::CODE_NON_FULLY_QUALIFIED);
23+
}
24+
25+
protected static function getSniffName(): string {
26+
return 'SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions';
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Somewhere;
6+
7+
echo strlen('Foo bar');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Somewhere;
6+
7+
echo \strlen('Foo bar');

0 commit comments

Comments
 (0)