mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-15 23:52:23 +00:00
add ConfiguredCodeSample
This commit is contained in:
parent
7667c5230a
commit
3b2304e1da
|
@ -261,11 +261,8 @@ final class GenerateRectorOverviewCommand extends Command
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $configuration
|
||||
*/
|
||||
private function printCodeWrapped($configuration, string $format): void
|
||||
private function printCodeWrapped(string $content, string $format): void
|
||||
{
|
||||
$this->consoleStyle->writeln(sprintf('```%s%s%s%s```', $format, PHP_EOL, $configuration, PHP_EOL));
|
||||
$this->consoleStyle->writeln(sprintf('```%s%s%s%s```', $format, PHP_EOL, trim($content), PHP_EOL));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use Rector\Builder\Class_\ClassPropertyCollector;
|
|||
use Rector\Node\Attribute;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
|
@ -47,7 +47,7 @@ final class AnnotatedPropertyInjectToConstructorInjectionRector extends Abstract
|
|||
ClassPropertyCollector $classPropertyCollector,
|
||||
DocBlockAnalyzer $docBlockAnalyzer,
|
||||
NodeTypeResolver $nodeTypeResolver,
|
||||
string $annotation = 'inject'
|
||||
string $annotation
|
||||
) {
|
||||
$this->classPropertyCollector = $classPropertyCollector;
|
||||
$this->docBlockAnalyzer = $docBlockAnalyzer;
|
||||
|
@ -87,11 +87,11 @@ final class AnnotatedPropertyInjectToConstructorInjectionRector extends Abstract
|
|||
return new RectorDefinition(
|
||||
'Turns non-private properties with @annotation to private properties and constructor injection',
|
||||
[
|
||||
new CodeSample(
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
/**
|
||||
* @var SomeService
|
||||
* @annotation
|
||||
* @inject
|
||||
*/
|
||||
public $someService;
|
||||
CODE_SAMPLE
|
||||
|
@ -107,7 +107,11 @@ public function __construct(SomeService $someService)
|
|||
$this->someService = $someService;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
,
|
||||
[
|
||||
'$annotation' => 'inject',
|
||||
]
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use Rector\Exception\Bridge\RectorProviderException;
|
|||
use Rector\Node\Attribute;
|
||||
use Rector\Node\NodeFactory;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class MoveRepositoryFromParentToConstructorRector extends AbstractRector
|
||||
|
@ -104,7 +104,7 @@ final class MoveRepositoryFromParentToConstructorRector extends AbstractRector
|
|||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Turns parent EntityRepository class to constructor dependency', [
|
||||
new CodeSample(
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
namespace App\Repository;
|
||||
|
||||
|
@ -133,7 +133,12 @@ final class PostRepository
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
,
|
||||
[
|
||||
'$entityRepositoryClass' => 'Doctrine\ORM\EntityRepository',
|
||||
'$entityManagerClass' => 'Doctrine\ORM\EntityManager',
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use PhpParser\Node\Expr\Variable;
|
|||
use Rector\Node\MethodCallNodeFactory;
|
||||
use Rector\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class PropertyAssignToMethodCallRector extends AbstractRector
|
||||
|
@ -40,6 +40,7 @@ final class PropertyAssignToMethodCallRector extends AbstractRector
|
|||
private $newMethodName;
|
||||
|
||||
/**
|
||||
* @todo check via https://github.com/rectorphp/rector/issues/548
|
||||
* @param string[] $types
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -59,7 +60,23 @@ final class PropertyAssignToMethodCallRector extends AbstractRector
|
|||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Turns property assign of specific type and property name to method call', [
|
||||
new CodeSample('$control->oldProperty = false;', '$control->newMethodCall(false);'),
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$someObject = new SomeClass;
|
||||
$someObject->oldProperty = false;
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
$someObject = new SomeClass;
|
||||
$someObject->newMethodCall(false);
|
||||
CODE_SAMPLE
|
||||
,
|
||||
[
|
||||
'$types' => ['SomeClass'],
|
||||
'$oldPropertyName' => 'oldProperty',
|
||||
'$newMethodName' => 'newMethodCall',
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
services:
|
||||
Rector\Rector\Architecture\DependencyInjection\AnnotatedPropertyInjectToConstructorInjectionRector: ~
|
||||
Rector\Rector\Architecture\DependencyInjection\AnnotatedPropertyInjectToConstructorInjectionRector:
|
||||
$annotation: 'inject'
|
||||
|
|
Loading…
Reference in New Issue
Block a user