Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cd56669
feat: add TooWideReturnTypeRector
calebdw Aug 14, 2025
74322a7
chore: rename TooWideReturnTypeRector to NarrowTooWideReturnTypeRector
calebdw Aug 15, 2025
76541db
chore: review updates
calebdw Aug 15, 2025
144d9e4
chore: add min PHP version to NarrowTooWideReturnTypeRector
calebdw Aug 15, 2025
f592e94
chore: move base classes to Source
calebdw Aug 15, 2025
fd2259f
fix: add nullable edge case
calebdw Aug 15, 2025
dfd1cbc
chore: remove never/void handling from NarrowTooWideReturnTypeRector
calebdw Aug 15, 2025
df13226
chore: fix logic bug
calebdw Aug 15, 2025
1b00789
chore: early return if not class
calebdw Aug 15, 2025
7e87b26
chore: revert changes to TerminatedNodeAnalyzer
calebdw Aug 15, 2025
7558829
test: skip unknown parameter
calebdw Aug 16, 2025
6837fd4
feat: add support for phpdoc return types
calebdw Aug 16, 2025
cc5f154
fix: don't add return type to phpdoc if it doesn't exist
calebdw Aug 17, 2025
193e1d9
tests: add requested fixture
calebdw Aug 17, 2025
81468f3
tests: add test to remove unused phpdoc generic
calebdw Aug 17, 2025
c16f49a
chore: update fixtures
calebdw Aug 17, 2025
a9e401f
chore: skip function likes without parameter types
calebdw Aug 17, 2025
3e59478
chore: skip methods with native mixed return types
calebdw Aug 17, 2025
fa7452f
chore: use native types
calebdw Aug 17, 2025
b982462
chore: rector fixes
calebdw Aug 17, 2025
eca2f7a
chore: skip standalone null
calebdw Aug 17, 2025
adb422a
test: add requested fixture
calebdw Aug 17, 2025
8865b3c
feat: support ArrowFunction in BetterNodeFinder, add tests for arrow …
calebdw Aug 17, 2025
7b71fca
chore: refactor NarrowTooWideReturnTypeRector
calebdw Aug 17, 2025
259850a
clean up unnecessry yield check
samsonasik Aug 18, 2025
6ed143f
skip complex type sub type
samsonasik Aug 18, 2025
1a606ae
skip complex type sub type
samsonasik Aug 18, 2025
9189304
skip null: mostly placeholder
samsonasik Aug 18, 2025
0a00d35
skip true/false to become bool
samsonasik Aug 18, 2025
08e23ca
skip true/false to become bool
samsonasik Aug 18, 2025
adce527
re-run rector
samsonasik Aug 18, 2025
cf5ab03
run cs fix
samsonasik Aug 18, 2025
06326d3
add fixture for parent and child combine
samsonasik Aug 18, 2025
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,25 @@
<?php

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

$simple = fn($x): string|int|bool => $x > 5 ? 'high' : 10;

$ternary = fn($value): string|int|float|null =>
$value === null ? null : ($value > 0 ? 'positive' : -1);

$cast = fn($input): int|string|array => (int) $input;

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

$simple = fn($x): string|int => $x > 5 ? 'high' : 10;

$ternary = fn($value): string|int|null =>
$value === null ? null : ($value > 0 ? 'positive' : -1);

$cast = fn($input): int => (int) $input;

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

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

$callback = function(): string|int|array|null {
if (rand(0, 1)) {
return 'result';
}

if (rand(0, 1)) {
return 42;
}

return null;
};

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

$callback = function(): string|int|null {
if (rand(0, 1)) {
return 'result';
}

if (rand(0, 1)) {
return 42;
}

return null;
};

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

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

final class EdgeCases
{
public function implicitNull(): string|int|null
{
if (rand(0, 1)) {
return;
}

return 'something';
}

public function implicitReturn(): string|int|null
{
if (rand(0, 1)) {
return 'something';
}
}

public function nullableReturn(): ?string
{
return 'something';
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

final class EdgeCases
{
public function implicitNull(): ?string
{
if (rand(0, 1)) {
return;
}

return 'something';
}

public function implicitReturn(): ?string
{
if (rand(0, 1)) {
return 'something';
}
}

public function nullableReturn(): string
{
return 'something';
}
}

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

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

final class FinalClass
{
public function getData(): string|int|\DateTime
{
if (rand(0, 1)) {
return 'text';
}

if (rand(0, 1)) {
return 'text';
}

return 1000;
}

public function getInfo(): string|int|bool|null
{
if (rand(0, 1)) {
return 'info';
}

if (rand(0, 1)) {
return null;
}

return 42;
}

private function processData(): string|array|object
{
if (rand(0, 1)) {
return 'processed';
}

return ['data' => 'value'];
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

final class FinalClass
{
public function getData(): int|string
{
if (rand(0, 1)) {
return 'text';
}

if (rand(0, 1)) {
return 'text';
}

return 1000;
}

public function getInfo(): string|int|null
{
if (rand(0, 1)) {
return 'info';
}

if (rand(0, 1)) {
return null;
}

return 42;
}

private function processData(): string|array
{
if (rand(0, 1)) {
return 'processed';
}

return ['data' => 'value'];
}
}

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


namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

use Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Source\SomeInterface;
use Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Sourcet\SomeAbstractClass;

final class FinalInheritance extends SomeAbstractClass
{
public function process(): string|int|array
{
if (rand(0, 1)) {
return 'text';
}

return 42;
}
}

final class FinalInterfaceImplementation implements SomeInterface
{
public function getData(): string|int|bool
{
return 'data';
}
}

?>
-----
<?php


namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

use Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Source\SomeInterface;
use Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Sourcet\SomeAbstractClass;

final class FinalInheritance extends SomeAbstractClass
{
public function process(): string|int
{
if (rand(0, 1)) {
return 'text';
}

return 42;
}
}

final class FinalInterfaceImplementation implements SomeInterface
{
public function getData(): string
{
return 'data';
}
}

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

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

class NonFinalClassWithFinalMethods
{
public function getData(): string|int|\DateTime
{
return 'hello';
}

final public function getInfo(): string|int|bool
{
return 'info';
}

final protected function processData(): string|array|object
{
return 'processed';
}

private function helper(): string|int|float
{
return 'helper';
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

class NonFinalClassWithFinalMethods
{
public function getData(): string|int|\DateTime
{
return 'hello';
}

final public function getInfo(): string
{
return 'info';
}

final protected function processData(): string
{
return 'processed';
}

private function helper(): string
{
return 'helper';
}
}

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

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

function processValue(): string|int|float|bool
{
if (rand(0, 1)) {
return 'text';
}

if (rand(0, 1)) {
return 123;
}

return true;
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Fixture;

function processValue(): string|int|bool
{
if (rand(0, 1)) {
return 'text';
}

if (rand(0, 1)) {
return 123;
}

return true;
}

?>
Loading
Loading