Skip to content

Commit

Permalink
Reduce array_merge call in case exclude-path or exclude-files passed …
Browse files Browse the repository at this point in the history
…by user (#170)
  • Loading branch information
sidz authored Nov 11, 2023
1 parent 84016e4 commit 2a47d8c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
10 changes: 2 additions & 8 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,10 @@ private function getCSVOption(InputInterface $input, string $option): array
return [];
}

if (false === is_array($result)) {
return array_filter(
explode(',', (string) $result),
static function ($value) {
return false === empty($value);
}
);
if (!is_array($result)) {
return array_filter(explode(',', (string) $result));
}


return $result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public function doRun(InputInterface $input, OutputInterface $output): int

public function getLongVersion(): string
{
return trim(sprintf(
return sprintf(
'<info>%s</info> version <comment>%s</comment> by Povilas Susinskas',
$this->getName(),
$this->getVersion()
));
);
}

public function getContainer(): Container
Expand Down
24 changes: 9 additions & 15 deletions src/PHPFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,19 @@ public function __construct(
->exclude(array_merge(['vendor'], $exclude))
->ignoreDotFiles(true)
->ignoreVCS(true)
->notPath($excludePaths)
->notName($excludeFiles)
->name(
array_map(
static fn (string $suffix) => '*.' . $suffix,
$suffixes
)
)
->append(
array_map(
function (string $file) {
return new SplFileInfo(realpath($file), dirname($file), $file);
},
static fn (string $file) => new SplFileInfo(realpath($file), dirname($file), $file),
$files
)
);

foreach ($suffixes as $suffix) {
$this->name('*.' . $suffix);
}

foreach ($excludePaths as $notPath) {
$this->notPath($notPath);
}

foreach ($excludeFiles as $notName) {
$this->notName($notName);
}
}
}
12 changes: 12 additions & 0 deletions tests/Command/RunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@ public function testItDoesNotFailCommandWhenFileOnPathDoesNotExist(): void
$this->assertSame(RunCommand::SUCCESS, $this->commandTester->getStatusCode());
$this->assertStringContainsString('No files found to scan', $this->commandTester->getDisplay());
}

public function testFilterBySuffixes(): void
{
$this->commandTester->execute([
'directories' => ['tests/Fixtures/Files'],
'--extensions' => 'all',
'--suffixes' => 'php5',
]);

$this->assertSame(RunCommand::FAILURE, $this->commandTester->getStatusCode());
$this->assertStringContainsString('Total of Magic Numbers: 1', $this->commandTester->getDisplay());
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/Files/test_4.php5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$variable_0 = 123;

0 comments on commit 2a47d8c

Please sign in to comment.