Compare commits

...
Sign in to create a new pull request.

6 commits

5 changed files with 107 additions and 0 deletions

View file

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\DataTransferObject\ConfigDto;
use App\DataTransferObject\TemplateFile;
use Illuminate\Support\Collection;
use Symfony\Component\Filesystem\Filesystem;
use Twig\Environment;
final class RemoveIgnoredFilesCommand
{
public function __construct(private array $filenames)
{
}
public function execute(array $filesToGenerateAndConfigurationData, \Closure $next)
{
/**
* @var Collection<int,TemplateFile> $filesToGenerate
* @var ConfigDto $configurationDataDto,
* @var array<non-empty-string,mixed> $configurationData
*/
[$configurationData, $configurationDataDto, $filesToGenerate] = $filesToGenerateAndConfigurationData;
$filesToGenerate = $filesToGenerate->filter(function (TemplateFile $templateFile): bool {
return !collect($this->filenames)->contains($templateFile->name);
});
return $next([$configurationData, $configurationDataDto, $filesToGenerate]);
}
}

View file

@ -8,9 +8,11 @@ use App\Command\CreateFinalConfigurationDataCommand;
use App\Command\CreateListOfFilesToGenerateCommand;
use App\Command\FindBuildConfigurationFileCommand;
use App\Command\GenerateConfigurationFilesCommand;
use App\Command\RemoveIgnoredFilesCommand;
use App\Command\ValidateConfigurationDataCommand;
use App\DataTransferObject\ConfigDto;
use App\DataTransferObject\TemplateFile;
use App\IgnoreFile;
use Illuminate\Pipeline\Pipeline;
use Illuminate\Support\Collection;
use Symfony\Component\Console\Attribute\AsCommand;
@ -72,6 +74,7 @@ class GenerateCommand extends Command
new CreateFinalConfigurationDataCommand(),
new ValidateConfigurationDataCommand(),
new CreateListOfFilesToGenerateCommand(),
new RemoveIgnoredFilesCommand(IgnoreFile::parse()),
new GenerateConfigurationFilesCommand(
$this->filesystem,
$this->twig,

19
src/IgnoreFile.php Normal file
View file

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace App;
final class IgnoreFile
{
public const FILENAME = '.bcignore';
public static function parse(): array
{
if (@stat(self::FILENAME) === false) {
return [];
}
return explode("\n", file_get_contents(self::FILENAME));
}
}

View file

@ -0,0 +1,25 @@
<?php
use App\Command\RemoveIgnoredFilesCommand;
use App\DataTransferObject\TemplateFile;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class RemoveIgnoredFilesCommandTest extends KernelTestCase
{
public function test_it_removes_any_ignored_files(): void
{
$filenamesToGenerate = collect([
new TemplateFile(data: '', name: 'phpcs.xml.dist'),
new TemplateFile(data: '', name: 'phpstan.neon.dist'),
]);
$filenamesToIgnore = ['phpstan.neon.dist'];
$command = new RemoveIgnoredFilesCommand($filenamesToIgnore);
$command->execute([[], [], $filenamesToGenerate], function ($result) {
self::assertCount(1, $result[2]);
self::assertSame('phpcs.xml.dist', $result[2][0]->name);
});
}
}

View file

@ -0,0 +1,26 @@
<?php
use App\IgnoreFile;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class IgnoreFileTest extends KernelTestCase
{
public function tearDown(): void
{
@unlink(IgnoreFile::FILENAME);
parent::tearDown();
}
public function test_it_parses_a_list_of_file_names_from_an_ignore_file(): void
{
file_put_contents(IgnoreFile::FILENAME, join("\n", ['phpstan.neon.dist']));
self::assertSame(['phpstan.neon.dist'], IgnoreFile::parse());
}
public function test_it_returns_an_empty_array_of_filenames_if_there_is_no_ignore_file(): void
{
self::assertSame([], IgnoreFile::parse());
}
}