Find the best Rector rule to solve your problem. Searching through 840 rules.
Found 10 rules:
Add @var array property docblock from its getter @return
class SomeClass
{
+ /**
+ * @var int[]
+ */
private array $items;
/**
* @return int[]
*/
public function getItems(): array
{
return $this->items;
}
}
Add @param array docblock to a class method based on local call types
class SomeClass
{
public function go()
{
$this->run(['item1', 'item2']);
}
+ /**
+ * @param string[] $items
+ */
private function run(array $items)
{
}
}
Add @var array property docblock from dim fetches on property fetch assignment
final class SomeClass
{
+ /**
+ * @var array<array<string, string>>
+ */
private array $items = [];
public function run()
{
$this->items[] = [
'name' => 'John',
];
}
}
Add @return array return from data provider param type
use PHPUnit\Framework\TestCase;
final class SomeClass extends TestCase
{
/**
* @dataProvider provideNames()
*/
public function test(string $name)
{
}
+ /**
+ * @return string[]
+ */
public function provideNames(): array
{
return ['John', 'Jane'];
}
}
Add @var array docblock to a property based on @param of constructor assign
class SomeClass
{
+ /**
+ * @var string[]
+ */
private array $items;
/**
* @param string[] $items
*/
public function __construct(array $items)
{
$this->items = $items;
}
}
Add @var array docblock to array property based on iterable default value
class SomeClass
{
+ /**
+ * @var int[]
+ */
private array $items = [1, 2, 3];
}
Add @return array docblock to array provider method
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
/**
* @dataProvider provideItems()
*/
public function testSomething(array $items)
{
}
+ /**
+ * @return array<array<string>>
+ */
public function provideItems()
{
return [
[['item1', 'item2']],
[['item3', 'item4']],
];
}
}
Add @return docblock based on detailed type of method call docblock
final class SomeController
{
+ /**
+ * @return SomeEntity[]
+ */
public function getAll(): array
{
return $this->repository->findAll();
}
}
final class Repository
{
/**
* @return SomeEntity[]
*/
public function findAll(): array
{
// ...
}
-}
}
Add @return docblock array of objects, that are dim assigned to returned variable
final class ItemProvider
{
+ /**
+ * @return Item[]
+ */
public function provide(array $input): array
{
$items = [];
foreach ($input as $value) {
$items[] = new Item($value);
}
return $items;
}
}
Add @return docblock for methods returning array from dim fetch of assigned arrays
final class SomeClass
{
- public function toArray(): array
+ /**
+ * @return array<string, string>
+ */
+ public function toArray()
{
$items = [];
if (mt_rand(0, 1)) {
$items['key'] = 'value';
}
if (mt_rand(0, 1)) {
$items['another_key'] = 'another_value';
}
return $items;
}
}