Skip to content

Commit

Permalink
[DowngradePhp72] Allow empty config on DowngradeParameterTypeWidening…
Browse files Browse the repository at this point in the history
…Rector (#1451)

* [DowngradePhp72] Allow empty config on DowngradeParameterTypeWideningRector

* [ci-review] Rector Rectify

* fix

* early check on empty unsafeTypesToMethods

* added back removed fixture

* final touch: eol

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Dec 10, 2021
1 parent 8d6eb87 commit 4681067
Show file tree
Hide file tree
Showing 14 changed files with 513 additions and 18 deletions.
6 changes: 2 additions & 4 deletions build/config/config-downgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@

$services->set(DowngradeParameterTypeWideningRector::class)
->configure([
DowngradeParameterTypeWideningRector::UNSAFE_TYPES_TO_METHODS => [
LoaderInterface::class => ['load'],
Loader::class => ['import']
],
LoaderInterface::class => ['load'],
Loader::class => ['import'],
]);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class EmptyConfigTest extends AbstractRectorTestCase
{
/**
* @requires PHP 7.2
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}

/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureEmptyConfig');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/empty_config.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

class SomeClass
{
public function hello(string $world = 'world') {
printf('Hello %s', $world);
}
}

class SomeOtherClassUsingAnAnonymousClass
{
public function doSomething(): void
{
$class = new class () extends SomeClass {
public function hello(string $world = 'world') {
printf('Hi %s', $world);
}
};
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

class SomeClass
{
/**
* @param string $world
*/
public function hello($world = 'world') {
printf('Hello %s', $world);
}
}

class SomeOtherClassUsingAnAnonymousClass
{
public function doSomething(): void
{
$class = new class () extends SomeClass {
/**
* @param string $world
*/
public function hello($world = 'world') {
printf('Hi %s', $world);
}
};
}
}

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

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

interface SomeInterface
{
public function hello(string $world = 'world');
}

class SomeClass2
{
public function doSomething(): void
{
$class = new class (function () {
return $this->doSomethingElse();
}) implements SomeInterface {
public function hello(string $world = 'world') {
printf('Hi %s', $world);
}
};
}

public function doSomethingElse(): void
{
print('Hello again');
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

interface SomeInterface
{
/**
* @param string $world
*/
public function hello($world = 'world');
}

class SomeClass2
{
public function doSomething(): void
{
$class = new class (function () {
return $this->doSomethingElse();
}) implements SomeInterface {
/**
* @param string $world
*/
public function hello($world = 'world') {
printf('Hi %s', $world);
}
};
}

public function doSomethingElse(): void
{
print('Hello again');
}
}

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

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

interface SomeInterface2
{
public function test(\SplFileInfo $file);
}

abstract class SomeAbstractClass implements SomeInterface2
{
public function test2(\SplFileInfo $file, string $world = 'world') {
printf('Hello %s', $world);
}
}

return new class extends SomeAbstractClass {
public function test(\SplFileInfo $file) {
$this->test2($file);
}
};

?>
-----
<?php

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

interface SomeInterface2
{
/**
* @param \SplFileInfo $file
*/
public function test($file);
}

abstract class SomeAbstractClass implements SomeInterface2
{
/**
* @param \SplFileInfo $file
* @param string $world
*/
public function test2($file, $world = 'world') {
printf('Hello %s', $world);
}
}

return new class extends SomeAbstractClass {
/**
* @param \SplFileInfo $file
*/
public function test($file) {
$this->test2($file);
}
};

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

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

interface SomeContainerInterface
{
public function has(string $id);
}

final class SomeContainerBuilder extends SomeUniqueContainer
{
public function has($id)
{
}
}

class SomeUniqueContainer implements SomeContainerInterface
{
public function has($id)
{
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

interface SomeContainerInterface
{
/**
* @param string $id
*/
public function has($id);
}

final class SomeContainerBuilder extends SomeUniqueContainer
{
public function has($id)
{
}
}

class SomeUniqueContainer implements SomeContainerInterface
{
public function has($id)
{
}
}

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

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

interface A
{
public function test(array $input);
}

class B implements A
{
public function test($input)
{
}
}

final class MostChild implements A
{
public function test(array $input)
{
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

interface A
{
/**
* @param mixed[] $input
*/
public function test($input);
}

class B implements A
{
public function test($input)
{
}
}

final class MostChild implements A
{
/**
* @param mixed[] $input
*/
public function test($input)
{
}
}

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

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

use Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\Source\AnotherContainerInterface;

final class YetAnotherContainer implements AnotherContainerInterface
{
use AnotherServiceLocatorTrait;
}

trait AnotherServiceLocatorTrait
{
public function get(string $name)
{
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\FixtureEmptyConfig;

use Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\Source\AnotherContainerInterface;

final class YetAnotherContainer implements AnotherContainerInterface
{
use AnotherServiceLocatorTrait;
}

trait AnotherServiceLocatorTrait
{
/**
* @param string $name
*/
public function get($name)
{
}
}

?>
Loading

0 comments on commit 4681067

Please sign in to comment.