From af4bbe0da06e916aab7b7f16b9c7e0952989e0c9 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 21 Oct 2018 11:35:28 +0200 Subject: [PATCH] cleanup --- .../src/Command/CreateRectorCommand.php | 48 +++++++++++-------- src/Naming/PropertyNaming.php | 20 ++++---- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/packages/ContributorTools/src/Command/CreateRectorCommand.php b/packages/ContributorTools/src/Command/CreateRectorCommand.php index cd91335535c..e6f219e9d90 100644 --- a/packages/ContributorTools/src/Command/CreateRectorCommand.php +++ b/packages/ContributorTools/src/Command/CreateRectorCommand.php @@ -19,10 +19,10 @@ use Symfony\Component\Finder\Finder; use Symplify\PackageBuilder\Console\Command\CommandNaming; use Symplify\PackageBuilder\Console\ShellCode; use Symplify\PackageBuilder\FileSystem\FinderSanitizer; +use Symplify\PackageBuilder\FileSystem\SmartFileInfo; use function Safe\getcwd; use function Safe\sort; use function Safe\sprintf; -use Symplify\PackageBuilder\FileSystem\SmartFileInfo; final class CreateRectorCommand extends Command { @@ -51,6 +51,11 @@ final class CreateRectorCommand extends Command */ private $finderSanitizer; + /** + * @var string[] + */ + private $generatedFiles = []; + public function __construct( ConsoleStyle $consoleStyle, ConfigurationFactory $configurationFactory, @@ -76,34 +81,22 @@ final class CreateRectorCommand extends Command $data = $this->prepareData($configuration); $testCasePath = null; - $generatedFiles = []; + foreach ($this->findTemplateFileInfos() as $smartFileInfo) { $destination = $smartFileInfo->getRelativeFilePathFromDirectory(self::TEMPLATES_DIRECTORY); $destination = $this->applyData($destination, $data); - $content = FileSystem::read($smartFileInfo->getRealPath()); - $content = $this->applyData($content, $data); - - if (Strings::endsWith($destination, 'Test.php')) { - $testCasePath = dirname($destination); - } - + $content = $this->applyData($smartFileInfo->getContents(), $data); FileSystem::write($destination, $content); - $generatedFiles[] = $destination; + $this->generatedFiles[] = $destination; + + if (! $testCasePath && Strings::endsWith($destination, 'Test.php')) { + $testCasePath = dirname($destination); + } } - // @todo make Rector class clickable in CLI output, so we can just jump right in - // probably absolute path might help - $this->consoleStyle->title(sprintf('New files generated for "%s"', $configuration->getName())); - sort($generatedFiles); - $this->consoleStyle->listing($generatedFiles); - - $this->consoleStyle->success(sprintf( - 'Now make these tests green again:%svendor/bin/phpunit %s', - PHP_EOL, - $testCasePath - )); + $this->printSuccess($configuration, $testCasePath); return ShellCode::SUCCESS; } @@ -180,4 +173,17 @@ CODE_SAMPLE; return $this->finderSanitizer->sanitize($finder); } + + private function printSuccess(Configuration $configuration, string $testCasePath): void + { + $this->consoleStyle->title(sprintf('New files generated for "%s"', $configuration->getName())); + sort($this->generatedFiles); + $this->consoleStyle->listing($this->generatedFiles); + + $this->consoleStyle->success(sprintf( + 'Now make these tests green again:%svendor/bin/phpunit %s', + PHP_EOL, + $testCasePath + )); + } } diff --git a/src/Naming/PropertyNaming.php b/src/Naming/PropertyNaming.php index 823d1634299..6c213dac23a 100644 --- a/src/Naming/PropertyNaming.php +++ b/src/Naming/PropertyNaming.php @@ -11,6 +11,16 @@ final class PropertyNaming return lcfirst($this->fqnToShortName($fqn)); } + /** + * @source https://stackoverflow.com/a/2792045/1348344 + */ + public function underscoreToName(string $underscoreName): string + { + $camelCaseName = str_replace('_', '', ucwords($underscoreName, '_')); + + return lcfirst($camelCaseName); + } + private function fqnToShortName(string $fqn): string { if (! Strings::contains($fqn, '\\')) { @@ -24,14 +34,4 @@ final class PropertyNaming return $lastNamePart; } - - /** - * @source https://stackoverflow.com/a/2792045/1348344 - */ - public function underscoreToName(string $underscoreName): string - { - $camelCaseName = str_replace('_', '', ucwords($underscoreName, '_')); - - return lcfirst($camelCaseName); - } }