From 545f391a2f8411bf495a960a7be861ff4232d495 Mon Sep 17 00:00:00 2001 From: dpi Date: Tue, 4 Jun 2024 18:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20`SlevomatCodingStandard.Contr?= =?UTF-8?q?olStructures.RequireNullSafeObjectOperator`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #76 --- PreviousNextDrupal/ruleset.xml | 3 ++ README.md | 1 + .../RequireNullSafeObjectOperatorTest.php | 29 +++++++++++++++++++ .../RequireNullSafeObjectOperatorError.php | 8 +++++ .../RequireNullSafeObjectOperatorNoError.php | 8 +++++ 5 files changed, 49 insertions(+) create mode 100644 tests/Sniffs/RequireNullSafeObjectOperatorTest.php create mode 100644 tests/Sniffs/fixtures/RequireNullSafeObjectOperatorError.php create mode 100644 tests/Sniffs/fixtures/RequireNullSafeObjectOperatorNoError.php diff --git a/PreviousNextDrupal/ruleset.xml b/PreviousNextDrupal/ruleset.xml index 3e140c8..9545d74 100644 --- a/PreviousNextDrupal/ruleset.xml +++ b/PreviousNextDrupal/ruleset.xml @@ -36,6 +36,9 @@ + + + diff --git a/README.md b/README.md index aad81d2..9924920 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ function doesAThing(array $data): int { #### SlevomatCodingStandard.Classes.ClassStructure #### SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature #### SlevomatCodingStandard.Commenting.UselessInheritDocComment +#### SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator #### SlevomatCodingStandard.Functions.RequireTrailingCommaInCall #### SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration #### SlevomatCodingStandard.Functions.StaticClosure diff --git a/tests/Sniffs/RequireNullSafeObjectOperatorTest.php b/tests/Sniffs/RequireNullSafeObjectOperatorTest.php new file mode 100644 index 0000000..a719b81 --- /dev/null +++ b/tests/Sniffs/RequireNullSafeObjectOperatorTest.php @@ -0,0 +1,29 @@ +getErrorCount()); + self::assertSniffError($report, 6, RequireNullSafeObjectOperatorSniff::CODE_REQUIRED_NULL_SAFE_OBJECT_OPERATOR); + } + + protected static function getSniffName(): string { + return 'SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator'; + } + +} diff --git a/tests/Sniffs/fixtures/RequireNullSafeObjectOperatorError.php b/tests/Sniffs/fixtures/RequireNullSafeObjectOperatorError.php new file mode 100644 index 0000000..28441be --- /dev/null +++ b/tests/Sniffs/fixtures/RequireNullSafeObjectOperatorError.php @@ -0,0 +1,8 @@ +data === NULL) { + $c = 1; +} diff --git a/tests/Sniffs/fixtures/RequireNullSafeObjectOperatorNoError.php b/tests/Sniffs/fixtures/RequireNullSafeObjectOperatorNoError.php new file mode 100644 index 0000000..0acb4e5 --- /dev/null +++ b/tests/Sniffs/fixtures/RequireNullSafeObjectOperatorNoError.php @@ -0,0 +1,8 @@ +data === NULL) { + $c = 1; +}