Skip to content

Commit

Permalink
feat(MultiLineFunctionDeclaration): Enable multi-line function declar…
Browse files Browse the repository at this point in the history
…ation checking
  • Loading branch information
klausi committed Apr 13, 2024
1 parent 24bad88 commit 45fb2f9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
17 changes: 6 additions & 11 deletions coder_sniffer/Drupal/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,18 @@
<severity>0</severity>
</rule>

<rule ref="Squiz.Functions.MultiLineFunctionDeclaration" />
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<!-- Disable some errors that are already coverd by other sniffs. -->
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace">
<severity>0</severity>
</rule>
<!-- Standard yet to be finalized on this (https://www.drupal.org/node/1539712). -->
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.Indent">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine">
<severity>0</severity>
</rule>

<rule ref="Squiz.PHP.LowercasePHPFunctions" />
<rule ref="Squiz.PHP.NonExecutableCode" />
Expand Down
3 changes: 2 additions & 1 deletion tests/Drupal/bad/BadUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ protected function getErrorList(string $testFile): array
836 => 1,
838 => 1,
849 => 2,
855 => 2,
860 => 1,
864 => 2,
];
}//end switch

Expand Down
9 changes: 9 additions & 0 deletions tests/Drupal/bad/bad.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,4 +852,13 @@ public static function test() {

}

/**
* Multi-line function declaration brace should be on a new line.
*/
function test29(
int $a,
string $b) {
echo "Hello";
}

?>
10 changes: 10 additions & 0 deletions tests/Drupal/bad/bad.php.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,13 @@ class ScopeKeyword {
}

}

/**
* Multi-line function declaration brace should be on a new line.
*/
function test29(
int $a,
string $b
) {
echo "Hello";
}
16 changes: 9 additions & 7 deletions tests/Drupal/good/good.php
Original file line number Diff line number Diff line change
Expand Up @@ -1468,14 +1468,16 @@ function test17($arg) {
}

/**
* Ignore indentation of multi-line function declarations.
* Indentation of multi-line function declarations is standardized.
*/
function test18(ConfigFactoryInterface $config_factory,
EntityTypeManagerInterface $entity_type_manager,
CacheTagsInvalidatorInterface $cache_invalidator,
ModuleHandlerInterface $module_handler,
EntityFieldManagerInterface $entity_field_manager,
EntityTypeBundleInfoInterface $entity_type_bundle_info) {
function test18(
ConfigFactoryInterface $config_factory,
EntityTypeManagerInterface $entity_type_manager,
CacheTagsInvalidatorInterface $cache_invalidator,
ModuleHandlerInterface $module_handler,
EntityFieldManagerInterface $entity_field_manager,
EntityTypeBundleInfoInterface $entity_type_bundle_info
) {
return 0;
}

Expand Down

0 comments on commit 45fb2f9

Please sign in to comment.