Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/ignore-interface-in-privatize-constants-command #35

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Command/PrivatizeConstantsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$sources = (array) $input->getArgument('sources');
$excludedPaths = (array) $input->getOption('exclude-path');

$phpFileInfos = PhpFilesFinder::find($sources, $excludedPaths);
$phpFileInfos = PhpFilesFinder::find(
$sources,
$excludedPaths,
static fn (SplFileInfo $splFileInfo): bool => ! str_ends_with(
$splFileInfo->getFilenameWithoutExtension(),
'Interface'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about interface that do not have such suffix?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, do not get your idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface should be skipped too, but the there is no "Interface" suffix:

interface NotSuffixed
{
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parse file content for this check will be ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that's the way.

Somewhere here maybe:

foreach ($phpstanResult['files'] as $fileDetail) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done it another way. It does not cover all edge cases, but it should work for 99% of cases.

)
);
if ($phpFileInfos === []) {
$this->symfonyStyle->warning('No PHP files found in provided paths');

Expand Down
7 changes: 6 additions & 1 deletion src/Finder/PhpFilesFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\SwissKnife\Finder;

use Closure;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Webmozart\Assert\Assert;
Expand All @@ -15,7 +16,7 @@ final class PhpFilesFinder
* @param string[] $excludedPaths
* @return SplFileInfo[]
*/
public static function find(array $paths, array $excludedPaths = []): array
public static function find(array $paths, array $excludedPaths = [], ?Closure $filter = null): array
{
Assert::allString($paths);
Assert::allFileExists($paths);
Expand All @@ -39,6 +40,10 @@ public static function find(array $paths, array $excludedPaths = []): array
return true;
});

if ($filter instanceof Closure) {
$finder->filter($filter);
}

return iterator_to_array($finder->getIterator());
}
}