Skip to content

Commit

Permalink
Add test case for multi line function declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi committed May 5, 2024
1 parent 3706812 commit b734484
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ public function process(File $phpcsFile, $stackPtr)
break;
}

if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']
if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
// Only allow empty classes and methods.
&& $tokens[$lastContent]['code'] !== T_OPEN_CURLY_BRACKET
) {
if ($tokens[$lastContent]['code'] === T_OPEN_CURLY_BRACKET) {
return;
}

$error = 'Closing brace must be on a line by itself';
$fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Line');
if ($fix === true) {
Expand Down
38 changes: 38 additions & 0 deletions tests/Drupal/WhiteSpace/ScopeClosingBraceUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,41 @@ function test2() {
*/
function test3() {
return 7; }

/**
* Defines an archiver attribute object.
*
* Plugin Namespace: Plugin\Archiver.
*
* For a working example, see \Drupal\system\Plugin\Archiver\Zip
*
* @see \Drupal\Core\Archiver\ArchiverManager
* @see \Drupal\Core\Archiver\ArchiverInterface
* @see plugin_api
* @see hook_archiver_info_alter()
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class Archiver extends Plugin {

/**
* Constructs an archiver plugin attribute object.
*
* @param string $id
* The archiver plugin ID.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $title
* The human-readable name of the archiver plugin.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
* The description of the archiver plugin.
* @param array $extensions
* An array of valid extensions for this archiver.
* @param class-string|null $deriver
* (optional) The deriver class.
*/
public function __construct(
public readonly string $id,
public readonly ?TranslatableMarkup $title = NULL,
public readonly ?TranslatableMarkup $description = NULL,
public readonly array $extensions = [],
public readonly ?string $deriver = NULL) {}

}
39 changes: 39 additions & 0 deletions tests/Drupal/WhiteSpace/ScopeClosingBraceUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,42 @@ function test2() {
function test3() {
return 7;
}

/**
* Defines an archiver attribute object.
*
* Plugin Namespace: Plugin\Archiver.
*
* For a working example, see \Drupal\system\Plugin\Archiver\Zip
*
* @see \Drupal\Core\Archiver\ArchiverManager
* @see \Drupal\Core\Archiver\ArchiverInterface
* @see plugin_api
* @see hook_archiver_info_alter()
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class Archiver extends Plugin {

/**
* Constructs an archiver plugin attribute object.
*
* @param string $id
* The archiver plugin ID.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $title
* The human-readable name of the archiver plugin.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
* The description of the archiver plugin.
* @param array $extensions
* An array of valid extensions for this archiver.
* @param class-string|null $deriver
* (optional) The deriver class.
*/
public function __construct(
public readonly string $id,
public readonly ?TranslatableMarkup $title = NULL,
public readonly ?TranslatableMarkup $description = NULL,
public readonly array $extensions = [],
public readonly ?string $deriver = NULL,
) {}

}

0 comments on commit b734484

Please sign in to comment.