Skip to content

Commit

Permalink
tv add finalize 2 (#3)
Browse files Browse the repository at this point in the history
* misc

* move finalize here
  • Loading branch information
TomasVotruba committed Feb 10, 2024
1 parent 5d74acc commit 7903aa5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"webmozart/assert": "^1.11"
},
"require-dev": {
"nikic/php-parser": "^4.18",
"phpunit/phpunit": "^10.5",
"rector/rector": "^1.0",
"symplify/easy-coding-standard": "^12.1",
Expand Down Expand Up @@ -54,6 +55,6 @@
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi",
"phpstan": "vendor/bin/phpstan analyse --ansi",
"rector": "vendor/bin/rector process --dry-run --ansi"
"rector": "vendor/bin/rector process --ansi"
}
}
8 changes: 5 additions & 3 deletions src/Command/FinalizeClassesCommand.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\Command;

use Nette\Utils\FileSystem;
use Nette\Utils\Strings;
use Rector\SwissKnife\Analyzer\NeedsFinalizeAnalyzer;
use Rector\SwissKnife\EntityClassResolver;
use Rector\SwissKnife\FileSystem\PhpFilesFinder;
use Rector\SwissKnife\Finder\PhpFilesFinder;
use Rector\SwissKnife\ParentClassResolver;
use Rector\SwissKnife\PhpParser\CachedPhpParser;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -47,10 +49,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$paths = (array) $input->getArgument('paths');

$phpFileInfos = PhpFilesFinder::findPhpFileInfos($paths);

$this->symfonyStyle->title('1. Detecting parent and entity classes');

$phpFileInfos = PhpFilesFinder::findPhpFileInfos($paths);

// double to count for both parent and entity resolver
$this->symfonyStyle->progressStart(2 * count($phpFileInfos));

Expand Down
8 changes: 8 additions & 0 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Rector\SwissKnife\DependencyInjection;

use Illuminate\Container\Container;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use Rector\SwissKnife\Command\CheckCommentedCodeCommand;
use Rector\SwissKnife\Command\CheckConflictsCommand;
use Rector\SwissKnife\Command\DumpEditorconfigCommand;
Expand Down Expand Up @@ -52,6 +54,12 @@ public function create(): Container
return $application;
});

// parser
$container->singleton(Parser::class, static function (): Parser {
$phpParserFactory = new ParserFactory();
return $phpParserFactory->create(ParserFactory::PREFER_PHP7);
});

$container->singleton(
SymfonyStyle::class,
static fn (): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput())
Expand Down
2 changes: 1 addition & 1 deletion src/Finder/PhpFilesFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\SwissKnife\FileSystem;
namespace Rector\SwissKnife\Finder;

use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@ public function getParentClassNames(): array
// remove native classes
$namespacedClassNames = array_filter(
$uniqueParentClassNames,
static fn(string $parentClassName): bool => str_contains($parentClassName, '\\')
static fn (string $parentClassName): bool => str_contains($parentClassName, '\\')
);

// remove obviously vendor names
$namespacedClassNames = array_filter($namespacedClassNames, static function (string $className) : bool {
if (str_contains($className, 'Symfony\\')) {
return false;
}

if (str_contains($className, 'PHPStan\\')) {
return false;
}
return !str_contains($className, 'PhpParser\\');
return ! str_contains($className, 'PhpParser\\');
});

return array_values($namespacedClassNames);
Expand Down

0 comments on commit 7903aa5

Please sign in to comment.