Skip to content

Commit 0c6ba2c

Browse files
authored
feat(MultiLineFunctionDeclaration): Enable multi-line function declaration checking (#3440075)
1 parent 24bad88 commit 0c6ba2c

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

coder_sniffer/Drupal/ruleset.xml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,23 +255,18 @@
255255
<severity>0</severity>
256256
</rule>
257257

258-
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration" />
258+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration">
259+
<properties>
260+
<property name="indent" value="2"/>
261+
</properties>
262+
</rule>
263+
<!-- Disable some errors that are already coverd by other sniffs. -->
259264
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
260265
<severity>0</severity>
261266
</rule>
262267
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace">
263268
<severity>0</severity>
264269
</rule>
265-
<!-- Standard yet to be finalized on this (https://www.drupal.org/node/1539712). -->
266-
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing">
267-
<severity>0</severity>
268-
</rule>
269-
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.Indent">
270-
<severity>0</severity>
271-
</rule>
272-
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine">
273-
<severity>0</severity>
274-
</rule>
275270

276271
<rule ref="Squiz.PHP.LowercasePHPFunctions" />
277272
<rule ref="Squiz.PHP.NonExecutableCode" />

tests/Drupal/bad/BadUnitTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ protected function getErrorList(string $testFile): array
382382
836 => 1,
383383
838 => 1,
384384
849 => 2,
385-
855 => 2,
385+
860 => 1,
386+
864 => 2,
386387
];
387388
}//end switch
388389

tests/Drupal/bad/bad.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,4 +852,13 @@ public static function test() {
852852

853853
}
854854

855+
/**
856+
* Multi-line function declaration brace should be on a new line.
857+
*/
858+
function test29(
859+
int $a,
860+
string $b) {
861+
echo "Hello";
862+
}
863+
855864
?>

tests/Drupal/bad/bad.php.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,3 +905,13 @@ class ScopeKeyword {
905905
}
906906

907907
}
908+
909+
/**
910+
* Multi-line function declaration brace should be on a new line.
911+
*/
912+
function test29(
913+
int $a,
914+
string $b
915+
) {
916+
echo "Hello";
917+
}

tests/Drupal/good/good.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,16 @@ function test17($arg) {
14681468
}
14691469

14701470
/**
1471-
* Ignore indentation of multi-line function declarations.
1471+
* Indentation of multi-line function declarations is standardized.
14721472
*/
1473-
function test18(ConfigFactoryInterface $config_factory,
1474-
EntityTypeManagerInterface $entity_type_manager,
1475-
CacheTagsInvalidatorInterface $cache_invalidator,
1476-
ModuleHandlerInterface $module_handler,
1477-
EntityFieldManagerInterface $entity_field_manager,
1478-
EntityTypeBundleInfoInterface $entity_type_bundle_info) {
1473+
function test18(
1474+
ConfigFactoryInterface $config_factory,
1475+
EntityTypeManagerInterface $entity_type_manager,
1476+
CacheTagsInvalidatorInterface $cache_invalidator,
1477+
ModuleHandlerInterface $module_handler,
1478+
EntityFieldManagerInterface $entity_field_manager,
1479+
EntityTypeBundleInfoInterface $entity_type_bundle_info
1480+
) {
14791481
return 0;
14801482
}
14811483

0 commit comments

Comments
 (0)