Skip to content

Commit

Permalink
[Php80] Make configurable INLINE_PUBLIC on ClassPropertyAssignToConst…
Browse files Browse the repository at this point in the history
…ructorPromotionRector (#3126)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Nov 29, 2022
1 parent 2b35d2e commit 3f2a16a
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 89 deletions.
98 changes: 81 additions & 17 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 406 Rules Overview
# 409 Rules Overview

<br>

Expand Down Expand Up @@ -64,7 +64,7 @@

- [Transform](#transform) (34)

- [TypeDeclaration](#typedeclaration) (34)
- [TypeDeclaration](#typedeclaration) (37)

- [Visibility](#visibility) (3)

Expand Down Expand Up @@ -5659,23 +5659,8 @@ Add null default to properties with PHP 7.4 property nullable type

Changes property type by `@var` annotations or default value.

:wrench: **configure it!**

- class: [`Rector\Php74\Rector\Property\TypedPropertyRector`](../rules/Php74/Rector/Property/TypedPropertyRector.php)

```php
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Property\TypedPropertyRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(TypedPropertyRector::class, [
TypedPropertyRector::INLINE_PUBLIC => false,
]);
};
```


```diff
final class SomeClass
{
Expand Down Expand Up @@ -5826,8 +5811,23 @@ Change `$this::class` to static::class or self::class depends on class modifier

Change simple property init and assign to constructor promotion

:wrench: **configure it!**

- class: [`Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector`](../rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php)

```php
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ClassPropertyAssignToConstructorPromotionRector::class, [
ClassPropertyAssignToConstructorPromotionRector::INLINE_PUBLIC => false,
]);
};
```


```diff
class SomeClass
{
Expand Down Expand Up @@ -9296,6 +9296,25 @@ Change `@return` types and type from static analysis to type declarations if not

<br>

### ReturnTypeFromReturnDirectArrayRector

Add return type from return direct array

- class: [`Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector`](../rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnDirectArrayRector.php)

```diff
final class AddReturnArray
{
- public function getArray()
+ public function getArray(): array
{
return [1, 2, 3];
}
}
```

<br>

### ReturnTypeFromReturnNewRector

Add return type to function like with return new
Expand Down Expand Up @@ -9334,6 +9353,27 @@ Add strict return type based on returned strict expr type

<br>

### ReturnTypeFromStrictConstantReturnRector

Add strict type declaration based on returned constants

- class: [`Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector`](../rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictConstantReturnRector.php)

```diff
class SomeClass
{
public const NAME = 'name';

- public function run()
+ public function run(): string
{
return self::NAME;
}
}
```

<br>

### ReturnTypeFromStrictNativeCallRector

Add strict return type based native function or class method return
Expand Down Expand Up @@ -9374,6 +9414,30 @@ Add strict return array type based on created empty array and returned

<br>

### ReturnTypeFromStrictTypedCallRector

Add return type from strict return type of call

- class: [`Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector`](../rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php)

```diff
final class SomeClass
{
- public function getData()
+ public function getData(): int
{
return $this->getNumber();
}

private function getNumber(): int
{
return 1000;
}
}
```

<br>

### ReturnTypeFromStrictTypedPropertyRector

Add return method return type based on strict typed property
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\FixtureInlinePublicDisable;

final class FinalClassNonTypedProtectedProperty
{
/**
* @var object
*/
protected $x;

public function __construct(object $x)
{
$this->x = $x;
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\FixtureInlinePublicDisable;

final class FinalClassNonTypedProtectedProperty
{
public function __construct(protected object $x)
{
}
}

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

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\FixtureInlinePublicDisable;

class NonFinalNonTypedPrivateProperty
{
/**
* @var object
*/
private $x;

public function __construct(object $x)
{
$this->x = $x;
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\FixtureInlinePublicDisable;

class NonFinalNonTypedPrivateProperty
{
public function __construct(private object $x)
{
}
}

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

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\FixtureInlinePublicDisable;

class SkipNonTypedNonFinalClassProtectedProperty
{
/**
* @var object
*/
protected $x;

public function __construct(object $x)
{
$this->x = $x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\FixtureInlinePublicDisable;

class TypedNonFinalClassProtectedProperty
{
protected object $x;

public function __construct(object $x)
{
$this->x = $x;
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\FixtureInlinePublicDisable;

class TypedNonFinalClassProtectedProperty
{
public function __construct(protected object $x)
{
}
}

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

declare(strict_types=1);

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class InlinePublicDisableTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureInlinePublicDisable');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule_disable_inline_public.php';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->importNames();
$rectorConfig->rule(ClassPropertyAssignToConstructorPromotionRector::class);
$rectorConfig->ruleWithConfiguration(ClassPropertyAssignToConstructorPromotionRector::class, [
ClassPropertyAssignToConstructorPromotionRector::INLINE_PUBLIC => true,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ClassPropertyAssignToConstructorPromotionRector::class);
$rectorConfig->ruleWithConfiguration(ClassPropertyAssignToConstructorPromotionRector::class, [
ClassPropertyAssignToConstructorPromotionRector::INLINE_PUBLIC => true,
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;

return static function (RectorConfig $rectorConfig): void {
// inline public is disable by default
$rectorConfig->rule(ClassPropertyAssignToConstructorPromotionRector::class);
};
Loading

0 comments on commit 3f2a16a

Please sign in to comment.