Skip to content
Merged
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,31 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;

final class PrivateMethod
{
private function run()
{
$values = [];

return $values;
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;

final class PrivateMethod
{
private function run(): array
{
$values = [];

return $values;
}
}

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

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;

final class PrivateMethodListDoc
{
private function run()
{
$values = [];
$values[] = 'item';

return $values;
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;

final class PrivateMethodListDoc
{
/**
* @return list<'item'>
*/
private function run(): array
{
$values = [];
$values[] = 'item';

return $values;
}
}

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

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;

final class SkipProtectedMethod
{
protected function run()
{
$values = [];

return $values;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;

final class SkipPublicMethod
{
public function run()
{
$values = [];

return $values;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector;

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

final class PrivateMethodReturnTypeFromStrictNewArrayRectorTest 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,9 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector;

return RectorConfig::configure()
->withRules([PrivateMethodReturnTypeFromStrictNewArrayRector::class]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector\Fixture;

final class SkipPrivateMethod
{
private function run()
{
$values = [];

return $values;
}
}
7 changes: 2 additions & 5 deletions rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,8 @@ private function resolveFloat(bool $isNegated, Expr $expr): Identical|NotIdentic
return new NotIdentical($expr, $float);
}

private function resolveNullable(
bool $isNegated,
Expr $expr,
ObjectType $objectType
): BooleanNot|Instanceof_ {
private function resolveNullable(bool $isNegated, Expr $expr, ObjectType $objectType): BooleanNot|Instanceof_
{
$fullyQualified = new FullyQualified($objectType->getClassName());
$instanceof = new Instanceof_($expr, $fullyQualified);

Expand Down
5 changes: 4 additions & 1 deletion rules/Naming/Matcher/VariableAndCallAssignMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function match(Assign $assign, ClassMethod|Closure|Function_ $functionLik

$isVariableFoundInCallArgs = (bool) $this->betterNodeFinder->findFirst(
$call->isFirstClassCallable() ? [] : $call->getArgs(),
fn (Node $subNode): bool => $subNode instanceof Variable && $this->nodeNameResolver->isName($subNode, $variableName)
fn (Node $subNode): bool => $subNode instanceof Variable && $this->nodeNameResolver->isName(
$subNode,
$variableName
)
);

if ($isVariableFoundInCallArgs) {
Expand Down
6 changes: 2 additions & 4 deletions rules/Privatization/NodeManipulator/VisibilityManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ private function removeVisibility(ClassMethod|Property|ClassConst|Param $node):
/**
* @api
*/
private function addVisibilityFlag(
Class_|ClassMethod|Property|ClassConst|Param $node,
int $visibility
): void {
private function addVisibilityFlag(Class_|ClassMethod|Property|ClassConst|Param $node, int $visibility): void
{
$node->flags |= $visibility;
}

Expand Down
Loading
Loading