Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix end docblock #42

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/DocBlock/UselessDocBlockCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ final class UselessDocBlockCleaner
private const CLEANING_REGEXES = [
self::TODO_COMMENT_BY_PHPSTORM_REGEX,
self::TODO_IMPLEMENT_METHOD_COMMENT_BY_PHPSTORM_REGEX,
self::COMMENT_CONSTRUCTOR_CLASS_REGEX,

// must run first
self::STANDALONE_DOCBLOCK_CLASS_REGEX,
// then this one
self::STANDALONE_COMMENT_CLASS_REGEX,
// then this one
self::INLINE_COMMENT_CLASS_REGEX,
self::COMMENT_CONSTRUCTOR_CLASS_REGEX,
];

/**
Expand All @@ -36,7 +41,13 @@ final class UselessDocBlockCleaner
* @see https://regex101.com/r/RzTdFH/4
* @var string
*/
private const STANDALONE_COMMENT_CLASS_REGEX = '#(\/\*{2}\s+?)?(\*|\/\/)\s+[cC]lass\s+[^\s]*(\s+\*\/)?$#';
private const STANDALONE_DOCBLOCK_CLASS_REGEX = '#(\/\*\*\s+)\*\s+[cC]lass\s+[^\s]*(\s+\*\/)$#';

/**
* @see https://regex101.com/r/RzTdFH/4
* @var string
*/
private const STANDALONE_COMMENT_CLASS_REGEX = '#\/\/\s+[cC]lass\s+\w+$#';

/**
* @see https://regex101.com/r/RzTdFH/4
Expand Down
1 change: 1 addition & 0 deletions src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void
}

$cleanedDocContent = $this->uselessDocBlockCleaner->clearDocTokenContent($token);

if ($cleanedDocContent === '') {
// remove token
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ class SomeClass2
{
}

/**
* class SomeClass
*/
class SomeClass3
{
}

// class SomeClass
class SomeClass4
{
}

// class SomeClass
class SomeClass5
{
}
?>
-----
<?php
Expand All @@ -48,18 +32,4 @@ class SomeClass2
{
}


class SomeClass3
{
}


class SomeClass4
{
}


class SomeClass5
{
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

/**
* @property SomeItem $item
* Class RemoveFromPropertyTest
*/
#[\AllowDynamicProperties]
final class RemoveFromBottomLine
{
}

?>
-----
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

/**
* @property SomeItem $item
*/
#[\AllowDynamicProperties]
final class RemoveFromBottomLine
{
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

// class SomeClass
class SomeClass4
{
}

// class SomeClass
class SomeClass5
{
}

?>
-----
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;


class SomeClass4
{
}


class SomeClass5
{
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

class SomeClass
final class Skip1ExtraWordClassMethodComment
{
/**
* Get special translator
*/
public function getTranslator()
{

}
/**
* Get special translator
*/
public function getTranslator()
{
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCom

class SkipInlineSet
{
public function getTranslator()
{
public function getTranslator()
{
// set value
$value = 1000;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCom
/**
* class to provide something
*/
class SomeClass5
class SkipUsefullClassComment
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

class SomeClass
class SkipUsefullClassConstructorComment
{
/**
/**
* A usefull comment.
*/
public function __construct()
{

}
public function __construct()
{
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemovePHPStormTodoImplementMethodCommentFixer\Fixture;
namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

class PackagesData
{
public function getIterator()
{
// TODO: Implement getIterator() method.
$value = 100;
}
}

?>
-----
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemovePHPStormTodoImplementMethodCommentFixer\Fixture;
namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

class PackagesData
{
public function getIterator()
{

$value = 100;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,42 @@

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

class SomeClass
final class UselessClassConstructorComment
{
/**
* SomeClass constructor.
*/
public function __construct()
{

}
}

class SomeClass
{
/**
* SomeClass Constructor.
*/
public function __construct()
{

}
/**
* SomeClass constructor.
*/
public function __construct()
{
}
}

class SomeClass
{
/**
* SomeClass Constructor
*/
public function __construct()
{

}
// SomeClass constructor
public function __construct()
{
}
}

class SomeClass
{
// SomeClass constructor
public function __construct()
{

}
}
?>
-----
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;

class SomeClass
{

public function __construct()
{

}
}

class SomeClass
final class UselessClassConstructorComment
{

public function __construct()
{

}
public function __construct()
{
}
}

class SomeClass
{

public function __construct()
{

}
public function __construct()
{
}
}

class SomeClass
{

public function __construct()
{

}
}
?>
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

declare(strict_types=1);
use PhpCsFixer\Fixer\Basic\BracesFixer;

use Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDefaultCommentFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->rule(RemoveUselessDefaultCommentFixer::class);
$ecsConfig->rules([
RemoveUselessDefaultCommentFixer::class,
BracesFixer::class,
]);
};
Loading