Skip to content

Commit

Permalink
relative file path
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 15, 2024
1 parent 13a2213 commit 00e1054
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/Command/FinalizeClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Nette\Utils\Strings;
use Rector\SwissKnife\Analyzer\NeedsFinalizeAnalyzer;
use Rector\SwissKnife\EntityClassResolver;
use Rector\SwissKnife\FileSystem\PathHelper;
use Rector\SwissKnife\Finder\PhpFilesFinder;
use Rector\SwissKnife\ParentClassResolver;
use Rector\SwissKnife\PhpParser\CachedPhpParser;
Expand Down Expand Up @@ -94,19 +95,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}

$this->symfonyStyle->writeln(sprintf(
'File "%s" %s finalized',
$phpFileInfo->getRelativePathname(),
$isDryRun ? 'would be' : 'was'
));

$finalizedContents = Strings::replace(
$phpFileInfo->getContents(),
self::NEWLINE_CLASS_START_REGEX,
'final class '
);

$finalizedFilePaths[] = $phpFileInfo->getRelativePath();
$finalizedFilePaths[] = PathHelper::relativeToCwd($phpFileInfo->getRealPath());

if ($isDryRun === false) {
FileSystem::write($phpFileInfo->getRealPath(), $finalizedContents);
Expand All @@ -118,6 +113,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

$this->symfonyStyle->listing($finalizedFilePaths);

$this->symfonyStyle->success(sprintf(
'%d classes %s finalized',
count($finalizedFilePaths),
Expand Down
14 changes: 14 additions & 0 deletions src/FileSystem/PathHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\FileSystem;

final class PathHelper
{
public static function relativeToCwd(string $filePath): string
{
// get relative path from getcwd()
return str_replace(getcwd() . '/', '', $filePath);
}
}
2 changes: 1 addition & 1 deletion tests/EntityClassResolver/Fixture/SomeClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Rector\SwissKnife\Tests\EntityClassResolver\Fixture;

class SomeClass
final class SomeClass
{
}

0 comments on commit 00e1054

Please sign in to comment.