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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\ConvertMultilineDocblockToSingleLineRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

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

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

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\Node\ConvertMultilineDocblockToSingleLineRector\Fixture;

/**
* @see Example
*/
class SingleStatements
{
/**
* @var string
*/
private $value;

/**
* @return string
*/
public function getValue(): string
{
return $this->value;
}

/**
* @param string $value
*/
public function setValue(string $value): void
{
$this->value = $value;
}

/**
* @throws \Exception
*/
public function dangerous(): void
{
throw new \Exception();
}

public function testFunction()
{
/**
* @var Foo $foo
*/
$foo = resolve(Foo::class);

/**
* @phpstan-ignore variable.undefined
*/
echo $bar;

/**
* @var string
*/
$name = 'test';

/**
* @param int $i
*/
Copy link

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param annotation is incorrectly placed on an if statement. The @param tag should only be used in function/method docblocks to document parameters, not in inline variable annotations within method bodies.

Suggested change
*/

Copilot uses AI. Check for mistakes.
if ($i > 0) {
/**
* @var array $data
*/
$data = [];
}

/**
* @var int $number
*/
foreach ($items as $number) {
// do something
}

/**
* @return string
*/
return $name;
}
}

?>
-----
<?php

namespace Rector\Tests\CodingStyle\Rector\Node\ConvertMultilineDocblockToSingleLineRector\Fixture;

/** @see Example */
class SingleStatements
{
/** @var string */
private $value;

/** @return string */
public function getValue(): string
{
return $this->value;
}

/** @param string $value */
public function setValue(string $value): void
{
$this->value = $value;
}

/** @throws \Exception */
public function dangerous(): void
{
throw new \Exception();
}

public function testFunction()
{
/** @var Foo $foo */
$foo = resolve(Foo::class);

/** @phpstan-ignore variable.undefined */
echo $bar;

/** @var string */
$name = 'test';

/** @param int $i */
if ($i > 0) {
/** @var array $data */
$data = [];
}

/** @var int $number */
foreach ($items as $number) {
// do something
}

/** @return string */
return $name;
}
}

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

namespace Rector\Tests\CodingStyle\Rector\Node\ConvertMultilineDocblockToSingleLineRector\Fixture;

class SkipMultipleStatements
{
/**
* Some function description.
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @param string $value
* @return void
*/
public function setValue(string $value): void
{
$this->value = $value;
}

/**
* @var string
* @see SomeClass
*/
private $name;

/**
* This method does something dangerous.
*
* Please be careful when using it.
*
* @throws \Exception
*/
public function dangerous(): void
{
throw new \Exception();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\Node\ConvertMultilineDocblockToSingleLineRector\Fixture;

class SkipAlreadySingleLine
{
/** @return string */
public function getTitle(): string
{
return $this->title;
}

/** @param string $value */
public function setValue(string $value): void
{
$this->value = $value;
}

/** @var string */
private $name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\FunctionLike\ConvertMultilineDocblockToSingleLineRector;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withRules([ConvertMultilineDocblockToSingleLineRector::class]);
Loading
Loading