fix static to explicit type

This commit is contained in:
TomasVotruba 2020-05-29 11:38:32 +02:00
parent 9e4558e97d
commit af0358998b
4 changed files with 47 additions and 35 deletions

View File

@ -9,7 +9,6 @@ use PhpParser\Lexer;
use PhpParser\Node;
use PhpParser\ParserFactory;
use Rector\Autodiscovery\ValueObject\NodesWithFileDestinationValueObject;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Configuration\Configuration;
use Rector\Core\PhpParser\Parser\Parser;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
@ -61,11 +60,6 @@ abstract class AbstractFileSystemRector implements FileSystemRectorInterface
*/
private $nodeScopeAndMetadataDecorator;
/**
* @var RemovedAndAddedFilesCollector
*/
private $removedAndAddedFilesCollector;
/**
* @var ParserFactory
*/
@ -85,7 +79,6 @@ abstract class AbstractFileSystemRector implements FileSystemRectorInterface
Lexer $lexer,
FormatPerservingPrinter $formatPerservingPrinter,
NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator,
RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
Configuration $configuration,
BetterStandardPrinter $betterStandardPrinter,
ParameterProvider $parameterProvider,
@ -96,7 +89,6 @@ abstract class AbstractFileSystemRector implements FileSystemRectorInterface
$this->lexer = $lexer;
$this->formatPerservingPrinter = $formatPerservingPrinter;
$this->nodeScopeAndMetadataDecorator = $nodeScopeAndMetadataDecorator;
$this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector;
$this->configuration = $configuration;
$this->betterStandardPrinter = $betterStandardPrinter;
$this->parameterProvider = $parameterProvider;
@ -197,21 +189,6 @@ abstract class AbstractFileSystemRector implements FileSystemRectorInterface
);
}
protected function moveFile(SmartFileInfo $oldFileInfo, string $newFileLocation, ?string $fileContent = null): void
{
$this->removedAndAddedFilesCollector->addMovedFile($oldFileInfo, $newFileLocation, $fileContent);
}
protected function removeFile(SmartFileInfo $smartFileInfo): void
{
$this->removedAndAddedFilesCollector->removeFile($smartFileInfo);
}
private function addFile(string $filePath, string $content): void
{
$this->removedAndAddedFilesCollector->addFileWithContent($filePath, $content);
}
/**
* Also without FQN "\" that are added by basic printer
*/

View File

@ -16,7 +16,6 @@ use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use Rector\CodingStyle\Naming\ClassNaming;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
@ -46,21 +45,14 @@ final class ReplaceMagicPropertyEventWithEventClassRector extends AbstractRector
*/
private $classNaming;
/**
* @var RemovedAndAddedFilesCollector
*/
private $removedAndAddedFilesCollector;
public function __construct(
EventClassNaming $eventClassNaming,
CustomEventFactory $customEventFactory,
ClassNaming $classNaming,
RemovedAndAddedFilesCollector $removedAndAddedFilesCollector
ClassNaming $classNaming
) {
$this->eventClassNaming = $eventClassNaming;
$this->customEventFactory = $customEventFactory;
$this->classNaming = $classNaming;
$this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector;
}
public function getDefinition(): RectorDefinition
@ -123,9 +115,8 @@ PHP
$eventFileLocation = $this->eventClassNaming->resolveEventFileLocationFromMethodCall($node);
// 3. create new event class with args
$eventClass = $this->customEventFactory->create($eventClassName, (array) $node->args);
$eventContent = $this->printFile($eventClass);
$this->removedAndAddedFilesCollector->addFileWithContent($eventFileLocation, $eventContent);
$eventClassInNamespace = $this->customEventFactory->create($eventClassName, (array) $node->args);
$this->printNodesToFilePath($eventClassInNamespace, $eventFileLocation);
// 4. ad disatch method call
$dispatchMethodCall = $this->createDispatchMethodCall($eventClassName);

View File

@ -0,0 +1,28 @@
<?php
namespace Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector\Fixture\Event;
final class SomeClassCopyEvent extends \Symfony\Contracts\EventDispatcher\Event
{
/**
* @var $this
*/
private $this;
/**
* @var string
*/
private $key;
public function __construct(static $this, string $key)
{
$this->this = $this;
$this->key = $key;
}
public function getThis(): static
{
return $this->this;
}
public function getKey(): string
{
return $this->key;
}
}

View File

@ -7,6 +7,7 @@ namespace Rector\Core\Rector\AbstractRector;
use PhpParser\Node;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Symplify\SmartFileSystem\SmartFileInfo;
/**
* This could be part of @see AbstractRector, but decopuling to trait
@ -38,4 +39,19 @@ trait RemovedAndAddedFilesTrait
$eventContent = $this->betterStandardPrinter->prettyPrintFile($node);
$this->removedAndAddedFilesCollector->addFileWithContent($fileLocation, $eventContent);
}
protected function moveFile(SmartFileInfo $oldFileInfo, string $newFileLocation, ?string $fileContent = null): void
{
$this->removedAndAddedFilesCollector->addMovedFile($oldFileInfo, $newFileLocation, $fileContent);
}
protected function removeFile(SmartFileInfo $smartFileInfo): void
{
$this->removedAndAddedFilesCollector->removeFile($smartFileInfo);
}
private function addFile(string $filePath, string $content): void
{
$this->removedAndAddedFilesCollector->addFileWithContent($filePath, $content);
}
}