Skip to content

Commit

Permalink
[TypeDeclaration] Move Rector Enterprise TypeDeclaration rules here (#…
Browse files Browse the repository at this point in the history
…3125)

* [TypeDeclaration] Move Rector Enterprise TypeDeclaration rules here

* [ci-review] Rector Rectify

* fix duplicate register

* remove unnecesary import config

* fix doc

* fix config

* fix config

* fix doc

* Fix @see

* Fix space

* Remove duplicate register

* Fix phpstan

* Fix phpstan

* [ci-review] Rector Rectify

* rollback array check

* rollback array check

* fix union

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Nov 28, 2022
1 parent ecec40c commit 2b35d2e
Show file tree
Hide file tree
Showing 62 changed files with 2,105 additions and 4 deletions.
6 changes: 6 additions & 0 deletions config/set/type-declaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnAnnotationIncorrectNullableRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictBoolReturnExprRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector;
use Rector\TypeDeclaration\Rector\FunctionLike\AddParamTypeSplFixedArrayRector;
Expand Down Expand Up @@ -60,5 +63,8 @@
AddParamTypeBasedOnPHPUnitDataProviderRector::class,
AddParamTypeFromPropertyTypeRector::class,
AddReturnTypeDeclarationFromYieldsRector::class,
ReturnTypeFromReturnDirectArrayRector::class,
ReturnTypeFromStrictConstantReturnRector::class,
ReturnTypeFromStrictTypedCallRector::class,
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

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

final class AddReturnArray
{
public function getArray()
{
return [1, 2, 3];
}
}

?>
-----
<?php

declare(strict_types=1);

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

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

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

declare(strict_types=1);

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

final class AddReturnArrayArrowFunction
{
public function getArray()
{
$items = fn () => [1, 2, 3];
}
}

?>
-----
<?php

declare(strict_types=1);

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

final class AddReturnArrayArrowFunction
{
public function getArray()
{
$items = fn (): array => [1, 2, 3];
}
}

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

declare(strict_types=1);

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

final class SkipUndirectArrayReturn
{
public function getArray(array $items)
{
return $items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector;

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

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

public function provideData(): Iterator
{
return $this->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,10 @@
<?php

declare(strict_types=1);

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

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ReturnTypeFromReturnDirectArrayRector::class);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

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

use stdClass;

class SkipChildClassHasTyped
{
public function action()
{
return new stdClass();
}
}

class SomeChild extends SkipChildClassHasTyped
{
public function run(): bool
{
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

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

class SkipChildClassHasTyped
{
public function run()
{
return $this->first() && true;
}

public function first()
{
return true;
}
}

class SomeChild extends SkipChildClassHasTyped
{
public function run(): string
{
return 'test';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

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

class SkipChildClassHasTyped
{
public const NAME = 'name';

public function run()
{
return self::NAME;
}
}

class SomeChild extends SkipChildClassHasTyped
{
public function run(): bool
{
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

class SkipNested
{
public const NAME = 'name';

public function run()
{
if (mt_rand(1, 0)) {
return self::NAME;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

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

class SomeClass
{
public const NAME = 'name';

public function run()
{
return self::NAME;
}
}

?>
-----
<?php

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

class SomeClass
{
public const NAME = 'name';

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

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

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector;

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

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

public function provideData(): Iterator
{
return $this->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,10 @@
<?php

declare(strict_types=1);

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

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ReturnTypeFromStrictConstantReturnRector::class);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

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

class SkipChildClassHasTyped
{
public function run()
{
return strlen('value');
}
}

class SomeChild extends SkipChildClassHasTyped
{
public function run(): string
{
return 'test';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

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

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

return $values;
}
}

class SomeChild extends SkipChildClassHasTyped
{
public function run(): string
{
return 'test';
}

}

0 comments on commit 2b35d2e

Please sign in to comment.