New Features 🥳
- [DeadCode] Add
RemoveReturnTagIncompatibleWithNativeTypeRector(#8172)
final class SomeClass
{
- /**
- * @return SomeObject
- */
public function getName(): string
{
return $this->someObject->getName();
}
}- [TypeDeclarationDocblocks] Add
MergePhpstanDocTagIntoNativeRectorto merge@phpstan-*doc tags into native tags (#8171)
final class SomeClass
{
/**
- * @var Collection
- *
- * @phpstan-var Collection<int, string>
+ * @var Collection<int, string>
*/
private $items;
}Bugfixes 🐛
- [Php81] Skip array dim fetch args in
NullToStrictStringFuncCallArgRector(#8164) - Fix scoper to clean up prefix under
getRuleDefinition()method, parts 1–5 (#8165, #8166, #8167, #8168, #8169) - Bump
phpstan/phpdoc-parserto^2.3.3(#8174)
PHPUnit 🧪
New rules and changes from rector-phpunit.
New Rules
- [CodeQuality] Add
AssertClassToThisAssertRector(#707)
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
final class SomeClass extends TestCase
{
public function run()
{
- Assert::assertEquals('expected', $result);
+ $this->assertEquals('expected', $result);
}
}- [CodeQuality] Add
BareCreateMockAssignToDirectUseRector— inline a single-usecreateMock()assignment (#708)
final class SomeTest extends TestCase
{
public function test()
{
- $someObject = $this->createMock(SomeClass::class);
- $this->process($someObject);
+ $this->process($this->createMock(SomeClass::class));
}
private function process(SomeClass $someObject): void
{
}
}- [CodeQuality] Add
WillReturnCallbackFallbackToThrowRector— throw on an unexpected extra consecutive call (#710)
$this->someServiceMock->expects($matcher)
->method('run')
->willReturnCallback(function () use ($matcher) {
if ($matcher->numberOfInvocations() === 1) {
return 1;
}
+
+ throw new \PHPUnit\Framework\Exception(sprintf('Method should not be called for the %dth time', $matcher->numberOfInvocations()));
});- [CodeQuality] Add
RemoveReturnFromVoidMethodMockCallbackRector— type a void mock callback and drop its value return (#711)
$this->createMock(SomeClass::class)
->method('run')
- ->willReturnCallback(function ($arg) {
+ ->willReturnCallback(function ($arg): void {
echo $arg;
-
- return true;
});(SomeClass::run() returns void.)
- [CodeQuality] Add
CallbackSingleAssertToSimplerRector— collapse awith()callback with a soleassertSame()toequalTo()(#714)
$builder->expects($this->exactly(2))
->method('add')
- ->with($this->callback(function ($type): bool {
- $this->assertSame(TextType::class, $type);
-
- return true;
- }));
+ ->with($this->equalTo(TextType::class));