Skip to content
Closed
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
5 changes: 0 additions & 5 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,4 @@ jobs:
# composer install cache - https://github.com/ramsey/composer-install
- uses: "ramsey/composer-install@v3"

# Override code from symplify/coding-standard shipped with ECS
- run: |
rm -rf vendor/symplify/easy-coding-standard/vendor/symplify/coding-standard/src
ln -s $PWD/src vendor/symplify/easy-coding-standard/vendor/symplify/coding-standard/

- run: ${{ matrix.actions.run }}
37 changes: 37 additions & 0 deletions src/Fixer/Commenting/FixTagTypoFixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Symplify\CodingStandard\Fixer\Commenting;

use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use Symplify\CodingStandard\Utils\Regex;

/**
* Fixes a plural typo in a doc block tag, e.g. "@returns" → "@return", "@params" → "@param", "@vars" → "@var".
*
* @see \Symplify\CodingStandard\Tests\Fixer\Commenting\FixTagTypoFixer\FixTagTypoFixerTest
*/
final class FixTagTypoFixer extends AbstractDocBlockFixer
{
/**
* @see https://regex101.com/r/8tFqJp/1
*/
private const string PLURAL_TAG_REGEX = '#@((?:psalm-|phpstan-)?(?:param|return|var))s\b#';

public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition('Fix a plural typo in a doc block tag, e.g. "@returns" to "@return"', []);
}

/**
* @param Tokens<Token> $tokens
*/
protected function processDocContent(string $docContent, Tokens $tokens, int $position): string
{
return Regex::replace($docContent, self::PLURAL_TAG_REGEX, '@$1');
}
}
28 changes: 28 additions & 0 deletions tests/Fixer/Commenting/FixTagTypoFixer/FixTagTypoFixerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\FixTagTypoFixer;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Symplify\EasyCodingStandard\Testing\PHPUnit\AbstractCheckerTestCase;

final class FixTagTypoFixerTest extends AbstractCheckerTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFiles(__DIR__ . '/Fixture');
}

public function provideConfig(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
25 changes: 25 additions & 0 deletions tests/Fixer/Commenting/FixTagTypoFixer/Fixture/plural_tags.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @params string $one
* @params string $two
* @returns string
*/
function someFunction(string $one, string $two)
{
}

?>
-----
<?php

/**
* @param string $one
* @param string $two
* @return string
*/
function someFunction(string $one, string $two)
{
}

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

/**
* @param string $one
* @param string $two
* @return string
*/
function correctFunction(string $one, string $two)
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

/**
* @throws \RuntimeException
* @property-read int $id
* @method string getName()
*/
class SomeEntity
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

/**
* This method returns a value and accepts params from the caller.
*
* @param string $name
*/
function describedFunction(string $name)
{
}
23 changes: 23 additions & 0 deletions tests/Fixer/Commenting/FixTagTypoFixer/Fixture/var_tag.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class SomeClass
{
/**
* @vars int
*/
private $count;
}

?>
-----
<?php

class SomeClass
{
/**
* @var int
*/
private $count;
}

?>
10 changes: 10 additions & 0 deletions tests/Fixer/Commenting/FixTagTypoFixer/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

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

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->rule(FixTagTypoFixer::class);
};
Loading