mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
Merge pull request #649 from rectorphp/php-exception-handler
[PHP] Exception handler typehint
This commit is contained in:
commit
6b87d9e545
@ -85,8 +85,102 @@
|
||||
"packages/Symfony/tests",
|
||||
"packages/Twig/tests",
|
||||
"packages/Utils/tests",
|
||||
"tests/Issues",
|
||||
"tests/Rector"
|
||||
"tests/Source",
|
||||
"tests/Rector/Architecture/DependencyInjection/ActionInjectionToConstructorInjectionRector/Wrong",
|
||||
"tests/Rector/Architecture/DependencyInjection/AnnotatedPropertyInjectToConstructorInjectionRector/Wrong",
|
||||
"tests/Issues/Issue594/Wrong",
|
||||
"tests/Rector/Assign/PropertyAssignToMethodCallRector/Wrong",
|
||||
"tests/Rector/RectorOrder/Wrong",
|
||||
"tests/Rector/DomainDrivenDesign/ValueObjectRemoverRector/Wrong",
|
||||
"tests/Rector/DomainDrivenDesign/ValueObjectRemoverDocBlockRector/Wrong",
|
||||
"tests/Rector/StaticCall/StaticCallToFunctionRector/Wrong",
|
||||
"tests/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector/Wrong",
|
||||
"tests/Rector/MethodCall/StaticMethodNameReplacerRector/Wrong",
|
||||
"tests/Rector/MethodCall/MethodNameReplacerRector/Wrong",
|
||||
"tests/Rector/MethodBody/ReturnThisRemoveRector/Wrong",
|
||||
"tests/Rector/MethodBody/NormalToFluentRector/Wrong",
|
||||
"tests/Rector/MethodBody/FluentReplaceRector/Wrong",
|
||||
"tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Wrong",
|
||||
"tests/Rector/MagicDisclosure/UnsetAndIssetToMethodCallRector/Wrong",
|
||||
"tests/Rector/MagicDisclosure/ToStringToMethodCallRector/Wrong",
|
||||
"tests/Rector/Typehint/ReturnTypehintRector/Wrong",
|
||||
"tests/Rector/Typehint/ParentTypehintedArgumentRector/Wrong",
|
||||
"tests/Rector/Argument/ArgumentRemoverRector/Wrong",
|
||||
"tests/Rector/Argument/ArgumentAdderRector/Wrong",
|
||||
"tests/Rector/Argument/ArgumentDefaultValueReplacerRector/Wrong",
|
||||
"tests/Rector/Namespace_/NamespaceReplacerRector/Wrong",
|
||||
"tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Wrong",
|
||||
"tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source",
|
||||
"tests/Rector/Function_/FunctionToStaticCallRector/Wrong",
|
||||
"tests/Rector/Function_/FunctionReplaceRector/Wrong",
|
||||
"tests/Rector/Function_/FunctionToMethodCallRector/Wrong",
|
||||
"tests/Rector/Property/PropertyNameReplacerRector/Wrong",
|
||||
"tests/Rector/Property/PropertyToMethodRector/Wrong",
|
||||
"tests/Rector/Architecture/DependencyInjection/AnnotatedPropertyInjectToConstructorInjectionRector/Wrong",
|
||||
"tests/Rector/Architecture/DependencyInjection/ActionInjectionToConstructorInjectionRector/Wrong",
|
||||
"tests/Rector/Architecture/DoctrineRepositoryAsService/Wrong",
|
||||
"tests/Rector/Interface_/MergeInterfacesRector/Wrong",
|
||||
"tests/Rector/Visibility/ChangeMethodVisibilityRector/Wrong",
|
||||
"tests/Rector/Visibility/ChangePropertyVisibilityRector/Wrong",
|
||||
"tests/Rector/Visibility/ChangeConstantVisibilityRector/Wrong",
|
||||
"tests/Rector/Annotation/AnnotationReplacerRector/Wrong",
|
||||
"tests/Rector/CodeQuality/UnnecessaryTernaryExpressionRector/Wrong",
|
||||
"tests/Rector/CodeQuality/InArrayAndArrayKeysToArrayKeyExistsRector/Wrong",
|
||||
"tests/Rector/Constant/ClassConstantReplacerRector/Wrong",
|
||||
"tests/Rector/Constant/RenameClassConstantsUseToStringsRector/Wrong",
|
||||
"tests/Rector/Class_/ParentClassToTraitsRector/Wrong",
|
||||
"tests/Rector/Class_/ClassReplacerRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/DelegateExceptionArgumentsRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/ArrayToYieldDataProviderRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/ExceptionAnnotationRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/TryCatchToExpectExceptionRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertPropertyExistsRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertIssetToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertRegExpRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertComparisonToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertCompareToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertSameBoolNullToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertTrueFalseToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertTrueFalseInternalTypeToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertNotOperatorRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertInstanceOfComparisonRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertFalseStrposToContainsRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/GetMockRector/Wrong",
|
||||
"packages/Sylius/tests/Rector/Review/Wrong",
|
||||
"packages/Silverstripe/tests/Rector/DefineConstantToStaticCallRector/Wrong",
|
||||
"packages/Silverstripe/tests/Rector/ConstantToStaticCallRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Controller/RedirectToRouteRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Controller/AddFlashRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Controller/ActionSuffixRemoverRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Validator/ConstraintUrlOptionRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Console/ConsoleExceptionToErrorEventConstantRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Yaml/SessionStrictTrueByDefaultYamlRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Yaml/SpaceBetweenKeyAndValueYamlRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Yaml/ParseFileRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/DependencyInjection/ContainerBuilderCompileEnvArgumentRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/VarDumper/VarDumperTestTraitMethodArgsRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/FrameworkBundle/ContainerGetToConstructorInjectionRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/FrameworkBundle/GetParameterToConstructorInjectionRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/FrameworkBundle/GetToConstructorInjectionRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Form/OptionNameRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Form/FormIsValidRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Form/StringFormTypeToClassRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Form/FormTypeGetParentRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Process/ProcessBuilderGetProcessRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Process/ProcessBuilderInstanceRector/Wrong",
|
||||
"packages/Twig/tests/Rector/SimpleFunctionAndFilterRector/Wrong",
|
||||
"packages/Doctrine/tests/Rector/AliasToClassRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/RemoveNodeRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/IdentifierRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/ParamAndStaticVarNameRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/UseWithAliasRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/CatchAndClosureUseNameRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/SetLineRector/Wrong",
|
||||
"packages/CakePHP/tests/Rector/MethodCall/ModalToGetSetRector/Wrong",
|
||||
"packages/Sensio/tests/Rector/FrameworkExtraBundle/TemplateAnnotationRector/Wrong",
|
||||
"packages/Php/tests/Rector/TypedPropertyRector/Wrong",
|
||||
"packages/Php/tests/Rector/ExceptionHandlerTypehintRector/Wrong"
|
||||
],
|
||||
"files": [
|
||||
"tests/Rector/Psr4/MultipleClassFileToPsr4ClassesRector/Source/exceptions.php",
|
||||
|
2
config/level/php/php70.yml
Normal file
2
config/level/php/php70.yml
Normal file
@ -0,0 +1,2 @@
|
||||
services:
|
||||
Rector\Php\Rector\ExceptionHandlerTypehintRector: ~
|
73
packages/Php/src/Rector/ExceptionHandlerTypehintRector.php
Normal file
73
packages/Php/src/Rector/ExceptionHandlerTypehintRector.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Php\Rector;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @group php7
|
||||
* @source https://wiki.php.net/rfc/typed_properties_v2#proposal
|
||||
*/
|
||||
final class ExceptionHandlerTypehintRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
'Changes property @var annotations from annotation to type.',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
function handler(Exception $exception) { ... }
|
||||
set_exception_handler('handler');
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
function handler(Throwable $exception) { ... }
|
||||
set_exception_handler('handler');
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Function_|ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
// exception handle has 1 param exactly
|
||||
if (count($node->params) !== 1) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
$paramNode = $node->params[0];
|
||||
// handle only Exception typehint
|
||||
if ((string) $paramNode->type !== 'Exception') {
|
||||
return $node;
|
||||
}
|
||||
|
||||
// is probably handling exceptions
|
||||
if (! Strings::match((string) $node->name, '#handle#i')) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
$paramNode->type = new FullyQualified('Throwable');
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
function handler(\Throwable $exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
set_error_handler('handler');
|
@ -0,0 +1,30 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Php\Tests\Rector\ExceptionHandlerTypehintRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Rector\Php\Rector\ExceptionHandlerTypehintRector
|
||||
*/
|
||||
final class ExceptionHandlerTypehintRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideWrongToFixedFiles()
|
||||
*/
|
||||
public function test(string $wrong, string $fixed): void
|
||||
{
|
||||
$this->doTestFileMatchesExpectedContent($wrong, $fixed);
|
||||
}
|
||||
|
||||
public function provideWrongToFixedFiles(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
{
|
||||
return __DIR__ . '/config.yml';
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
function handler(Exception $exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
set_error_handler('handler');
|
@ -0,0 +1,2 @@
|
||||
services:
|
||||
Rector\Php\Rector\ExceptionHandlerTypehintRector: ~
|
@ -1,9 +1,23 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
class SomeVisitor implements \PhpParser\NodeVisitor
|
||||
{
|
||||
public function leaveNode(\PhpParser\Node $node)
|
||||
{
|
||||
return \PhpParser\NodeTraverser::REMOVE_NODE;
|
||||
}
|
||||
|
||||
public function beforeTraverse(array $nodes)
|
||||
{
|
||||
}
|
||||
|
||||
public function enterNode(Node $node)
|
||||
{
|
||||
}
|
||||
|
||||
public function afterTraverse(array $nodes)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,23 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
class SomeVisitor implements \PhpParser\NodeVisitor
|
||||
{
|
||||
public function leaveNode(\PhpParser\Node $node)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function beforeTraverse(array $nodes)
|
||||
{
|
||||
}
|
||||
|
||||
public function enterNode(Node $node)
|
||||
{
|
||||
}
|
||||
|
||||
public function afterTraverse(array $nodes)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Rector\Testing\PHPUnit;
|
||||
|
||||
use PHPStan\AnalysedCodeException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Rector\Application\FileProcessor;
|
||||
@ -68,7 +69,14 @@ abstract class AbstractRectorTestCase extends TestCase
|
||||
|
||||
$this->parameterProvider->changeParameter('source', [$file]);
|
||||
|
||||
try {
|
||||
$reconstructedFileContent = $this->fileProcessor->processFileToString(new SmartFileInfo($file));
|
||||
} catch (AnalysedCodeException $analysedCodeException) {
|
||||
// change message to include responsible file
|
||||
$message = sprintf('Analyze error in "%s" file:%s%s', $file, PHP_EOL, $analysedCodeException->getMessage());
|
||||
$exceptionClass = get_class($analysedCodeException);
|
||||
throw new $exceptionClass($message);
|
||||
}
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
$reconstructedFile,
|
||||
|
@ -6,6 +6,7 @@ use Iterator;
|
||||
use Rector\FileSystem\FilesFinder;
|
||||
use Rector\Tests\AbstractContainerAwareTestCase;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use function Safe\sort;
|
||||
|
||||
final class FilesFinderTest extends AbstractContainerAwareTestCase
|
||||
{
|
||||
@ -20,25 +21,39 @@ final class FilesFinderTest extends AbstractContainerAwareTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $suffixes
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(array $suffixes, int $count, string $fileName): void
|
||||
public function testSingleSuffix(string $suffix, int $count, string $expectedFileName): void
|
||||
{
|
||||
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], $suffixes);
|
||||
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], [$suffix]);
|
||||
$this->assertCount($count, $foundFiles);
|
||||
|
||||
/** @var SplFileInfo $foundFile */
|
||||
$foundFile = array_pop($foundFiles);
|
||||
$this->assertSame($fileName, $foundFile->getBasename());
|
||||
$this->assertSame($expectedFileName, $foundFile->getBasename());
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [['php'], 1, 'SomeFile.php'];
|
||||
yield [['yml'], 1, 'some_config.yml'];
|
||||
yield [['yaml'], 1, 'other_config.yaml'];
|
||||
yield [['php'], 1, 'SomeFile.php'];
|
||||
yield [['yaml', 'yml'], 2, 'some_config.yml'];
|
||||
yield ['php', 1, 'SomeFile.php'];
|
||||
yield ['yml', 1, 'some_config.yml'];
|
||||
yield ['yaml', 1, 'other_config.yaml'];
|
||||
yield ['php', 1, 'SomeFile.php'];
|
||||
}
|
||||
|
||||
public function testMultipleSuffixes(): void
|
||||
{
|
||||
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], ['yaml', 'yml']);
|
||||
$this->assertCount(2, $foundFiles);
|
||||
|
||||
$foundFileNames = [];
|
||||
foreach ($foundFiles as $foundFile) {
|
||||
$foundFileNames[] = $foundFile->getFilename();
|
||||
}
|
||||
$expectedFoundFileNames = ['some_config.yml', 'other_config.yaml'];
|
||||
|
||||
sort($foundFileNames);
|
||||
sort($expectedFoundFileNames);
|
||||
$this->assertSame($expectedFoundFileNames, $foundFileNames);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
namespace Rector\Tests\Rector\Architecture\DoctrineRepositoryAsService\Wrong;
|
||||
|
||||
use AppBundle\Entity\Post;
|
||||
use Rector\Tests\Rector\Architecture\DoctrineRepositoryAsService\Source\SymfonyController;
|
||||
|
@ -23,7 +23,7 @@ final class DoctrineRepositoryAsServiceTest extends AbstractRectorTestCase
|
||||
public function provideWrongToFixedFiles(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/wrong2.php.inc', __DIR__ . '/Correct/correct2.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/PostController.php', __DIR__ . '/Correct/correct2.php.inc'];
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
namespace Rector\Tests\Rector\Architecture\DoctrineRepositoryAsService\Wrong;
|
||||
|
||||
use AppBundle\Entity\Post;
|
||||
use Rector\Tests\Rector\Architecture\DoctrineRepositoryAsService\Source\SymfonyController;
|
@ -1,5 +1,8 @@
|
||||
<?php declare (strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Class_\ParentClassToTraitsRector\Wrong;
|
||||
|
||||
use Rector\Tests\Rector\Class_\ParentClassToTraitsRector\Source\AnotherTrait;
|
||||
use Rector\Tests\Rector\Class_\ParentClassToTraitsRector\Source\ParentObject;
|
||||
|
||||
class ClassWithExternalConstant
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Class_\ParentClassToTraitsRector\Source;
|
||||
|
||||
trait AnotherTrait
|
||||
{
|
||||
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
<?php declare (strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Class_\ParentClassToTraitsRector\Wrong;
|
||||
|
||||
use Rector\Tests\Rector\Class_\ParentClassToTraitsRector\Source\AnotherTrait;
|
||||
use Rector\Tests\Rector\Class_\ParentClassToTraitsRector\Source\ParentObject;
|
||||
|
||||
class ClassWithExternalConstant extends ParentObject
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Function_\FunctionReplacerRector;
|
||||
namespace Rector\Tests\Rector\Function_\FunctionReplaceRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
@ -8,7 +8,7 @@ use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
/**
|
||||
* @see \Rector\Rector\Function_\FunctionReplaceRector
|
||||
*/
|
||||
final class FunctionReplacerRectorTest extends AbstractRectorTestCase
|
||||
final class FunctionReplaceRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideWrongToFixedFiles()
|
@ -4,7 +4,7 @@ namespace OldNamespace\SubNamespace;
|
||||
|
||||
class SomeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function create(\PHPUnit\Something $argument): \PHPUnit\Something
|
||||
public function create(\PHPUnit\Something $argument): \PHPUnit\Framework\Something
|
||||
{
|
||||
return new \PHPUnit\Framework\Something;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Namespace_\PseudoNamespaceToNamespaceRector\Wrong;
|
||||
|
||||
use PHPUnit\SpecialClass;
|
||||
|
||||
class SomeTest
|
||||
|
@ -0,0 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
final class PHPUnit_Framework_Something
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
abstract class PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
final class PHPUnit_Something
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
final class PHPUnit_SpecialClass
|
||||
{
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ namespace OldNamespace\SubNamespace;
|
||||
|
||||
class SomeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function create(\PHPUnit_Something $argument): \PHPUnit_Something
|
||||
public function create(\PHPUnit_Something $argument): \PHPUnit_Framework_Something
|
||||
{
|
||||
return new \PHPUnit_Framework_Something;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Namespace_\PseudoNamespaceToNamespaceRector\Wrong;
|
||||
|
||||
use PHPUnit_SpecialClass;
|
||||
|
||||
class SomeTest
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace SomeNamespace;
|
||||
namespace Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Wrong;
|
||||
|
||||
use Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source\ParserInterface;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace SomeNamespace;
|
||||
namespace Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Wrong;
|
||||
|
||||
use Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source\ClassMetadataFactory;
|
||||
|
||||
|
@ -20,8 +20,8 @@ final class ParentTypehintedArgumentRectorTest extends AbstractRectorTestCase
|
||||
|
||||
public function provideWrongToFixedFiles(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/wrong2.php.inc', __DIR__ . '/Correct/correct2.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/SomeClassImplementingParserInterface.php', __DIR__ . '/Correct/correct.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/MyMetadataFactory.php', __DIR__ . '/Correct/correct2.php.inc'];
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
|
@ -4,5 +4,5 @@ namespace Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source;
|
||||
|
||||
interface ParserInterface
|
||||
{
|
||||
public function parse(string $code, \PhpParser\ErrorHandler $errorHandler = null);
|
||||
public function parse($code, \PhpParser\ErrorHandler $errorHandler = null);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace SomeNamespace;
|
||||
namespace Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Wrong;
|
||||
|
||||
use Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source\ClassMetadataFactory;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace SomeNamespace;
|
||||
namespace Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Wrong;
|
||||
|
||||
use Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source\ParserInterface;
|
||||
|
@ -1,9 +1,9 @@
|
||||
services:
|
||||
Rector\Rector\Typehint\ParentTypehintedArgumentRector:
|
||||
$typehintForArgumentByMethodAndClass:
|
||||
'Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source\ParserInterface':
|
||||
'parse':
|
||||
'code': 'string'
|
||||
'Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source\ClassMetadataFactory':
|
||||
'setEntityManager':
|
||||
'em': 'Doctrine\ORM\EntityManagerInterface'
|
||||
Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source\ParserInterface:
|
||||
parse:
|
||||
code: 'string'
|
||||
Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source\ClassMetadataFactory:
|
||||
setEntityManager:
|
||||
em: 'Doctrine\ORM\EntityManagerInterface'
|
||||
|
@ -6,7 +6,7 @@ use Rector\Tests\Rector\Visibility\ChangeConstantVisibilityRector\Source\ParentO
|
||||
|
||||
class ClassWithInvalidConstants extends ParentObject
|
||||
{
|
||||
private const TO_BE_PUBLIC_CONSTANT = 1;
|
||||
public const TO_BE_PUBLIC_CONSTANT = 1;
|
||||
public const TO_BE_PROTECTED_CONSTANT = 2;
|
||||
protected const TO_BE_PRIVATE_CONSTANT = 3;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
/**
|
||||
* @covers \Rector\Rector\Visibility\ChangeMethodVisibilityRector
|
||||
*/
|
||||
final class ChangePropertyVisibilityRectorTest extends AbstractRectorTestCase
|
||||
final class ChangeMethodVisibilityRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideWrongToFixedFiles()
|
@ -4,11 +4,11 @@ namespace Rector\Tests\Rector\Visibility\ChangeMethodVisibilityRector\Source;
|
||||
|
||||
class ParentObject
|
||||
{
|
||||
public function toBePublicMethod() {
|
||||
private function toBePublicMethod() {
|
||||
|
||||
}
|
||||
|
||||
public function toBePublicStaticMethod() {
|
||||
static function toBePublicStaticMethod() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ use Rector\Tests\Rector\Visibility\ChangeMethodVisibilityRector\Source\ParentObj
|
||||
|
||||
class ClassThatInherits extends ParentObject
|
||||
{
|
||||
private function toBePublicStaticMethod() {
|
||||
static function toBePublicStaticMethod() {
|
||||
|
||||
}
|
||||
}
|
||||
|
10
tests/Source/SomeClass.php
Normal file
10
tests/Source/SomeClass.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
// class that is used all over the code
|
||||
// autoloaded manually via composer to keep the rest of code clean
|
||||
namespace SomeNamespace;
|
||||
|
||||
final class SomeClass
|
||||
{
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user