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
27 changes: 14 additions & 13 deletions config/set/php84.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules(
[
ExplicitNullableParamTypeRector::class,
RoundingModeEnumRector::class,
AddEscapeArgumentRector::class,
NewMethodCallWithoutParenthesesRector::class,
DeprecatedAnnotationToDeprecatedAttributeRector::class,
ForeachToArrayFindRector::class,
ForeachToArrayFindKeyRector::class,
ForeachToArrayAllRector::class,
ForeachToArrayAnyRector::class,
]
);
$rectorConfig->rules([
ExplicitNullableParamTypeRector::class,
RoundingModeEnumRector::class,
AddEscapeArgumentRector::class,
NewMethodCallWithoutParenthesesRector::class,
DeprecatedAnnotationToDeprecatedAttributeRector::class,
ForeachToArrayFindRector::class,
ForeachToArrayFindKeyRector::class,
ForeachToArrayAllRector::class,
ForeachToArrayAnyRector::class,

// optional
// \Rector\Php84\Rector\Class_\PropertyHookRector::class,
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SkipDifferentVariable
{
private string $name;

private string $surname;

public function getName(): string
{
return $this->surname;
}

public function setName(string $name): void
{
$this->surname = ucfirst($name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SkipGetSetMagic
{
private string $name;

public function getName(): string
{
return $this->name;
}

public function setName(string $name): void
{
$this->name = ucfirst($name);
}

public function __get($name)
{
}

public function __set($name, $value)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SkipGetterAndReadonly
{
private readonly string $name;

public function __construct(string $name)
{
$this->name = $name;
}

public function getName(): string
{
return $this->name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

use Symfony\Contracts\Service\Attribute\Required;

final class SkipMethodWithAttributes
{
private string $name;

#[Required]
public function getName(): string
{
return $this->name;
}

#[Required]
public function setName(string $name): void
{
$this->name = ucfirst($name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SkipMissmatchingGetterSetterNames
{
private string $name;

public function getAnotherName(): string
{
return $this->name;
}

public function setAnotherName(string $name): void
{
$this->name = ucfirst($name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SkipMultiStmtsGetter
{
private string $name;

public function getName(): string
{
$item = 1000;

return $this->name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

class SkipNonFinalClassToAvoidChildBreak
{
private string $name;

public function getName(): string
{
return $this->name;
}

public function setName(string $name): void
{
$this->name = ucfirst($name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

use Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Source\SomeParentContractInterface;

final class SkipParentContract implements SomeParentContractInterface
{
private string $name;

public function getName(): string
{
return $this->name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final readonly class SkipReadonlyClass
{
private string $name;

public function getName(): string
{
return $this->name;
}

public function setName(string $name): void
{
$this->name = ucfirst($name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SkipReadonlyGetterAndSetter
{
private readonly string $name;

public function getName(): string
{
return $this->name;
}

public function setName(string $name): void
{
$this->name = ucfirst($name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SkipReadonlyPromotedProperty
{
public function __construct(
private readonly int $value,
)
{
}

public function getValue()
{
return $this->value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SomeFixture
{
private string $name;

public function getName(): string
{
return $this->name;
}

public function setName(string $name): void
{
$this->name = ucfirst($name);
}
}

?>
-----
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;

final class SomeFixture
{
public string $name {
get => $this->name;
set(string $name) {
$this->name = ucfirst($name);
}
}
}

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

declare(strict_types=1);

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector;

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

final class PropertyHookRectorTest 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,8 @@
<?php

namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Source;

interface SomeParentContractInterface
{
public function getName(): string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php84\Rector\Class_\PropertyHookRector;
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(PropertyHookRector::class);

$rectorConfig->phpVersion(PhpVersion::PHP_84);
};
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public function refactor(Node $node): null|CallLike
return $callLike;
}

public function provideMinPhpVersion(): int
{
return PhpVersionFeature::FIRST_CLASS_CALLABLE_SYNTAX;
}

private function shouldSkip(
ArrowFunction|Closure $node,
FuncCall|MethodCall|StaticCall $callLike,
Expand Down Expand Up @@ -240,9 +245,4 @@ private function isChainedCall(FuncCall|MethodCall|StaticCall $callLike): bool

return $callLike->var instanceof CallLike;
}

public function provideMinPhpVersion(): int
{
return PhpVersionFeature::FIRST_CLASS_CALLABLE_SYNTAX;
}
}
2 changes: 1 addition & 1 deletion rules/Php74/Rector/Double/RealToFloatTypeCastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Rector\Php74\Rector\Double;

use Rector\Renaming\Rector\Cast\RenameCastRector;
use PhpParser\Node;
use PhpParser\Node\Expr\Cast\Double;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\Renaming\Rector\Cast\RenameCastRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down
Loading