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

[TASK] Streamline folder and files naming #17

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

// see https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata
namespace PHPSTORM_META;

override(\Psr\Container\ContainerInterface::get(0), type(0));
4 changes: 2 additions & 2 deletions fractor-xml/src/XmlFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace a9f\FractorXml;

use a9f\Fractor\Contract\FileProcessor;
use a9f\Fractor\ValueObject\File;
use a9f\Fractor\Application\Contract\FileProcessor;
use a9f\Fractor\Application\ValueObject\File;
use a9f\FractorXml\Contract\XmlFractor;

final class XmlFileProcessor implements FileProcessor
Expand Down
17 changes: 9 additions & 8 deletions fractor/config/application.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

use a9f\Fractor\Application\Contract\FileProcessor;
use a9f\Fractor\Application\FractorRunner;
use a9f\Fractor\Configuration\AllowedFileExtensionsResolver;
use a9f\Fractor\Configuration\ConfigurationFactory;
use a9f\Fractor\Configuration\Option;
use a9f\Fractor\Contract\FileProcessor;
use a9f\Fractor\Factory\ConfigurationFactory;
use a9f\Fractor\Fractor\FractorRunner;
use a9f\Fractor\ValueObject\Configuration;
use a9f\Fractor\Configuration\ValueObject\Configuration;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
Expand All @@ -25,10 +26,10 @@
$services->load('a9f\\Fractor\\', __DIR__ . '/../src/')
->exclude(
[
__DIR__ . '/../src/Configuration',
__DIR__ . '/../src/Console',
__DIR__ . '/../src/ValueObject',
__DIR__ . '/../src/Console/Output',
__DIR__ . '/../src/Testing',
__DIR__ . '/../src/ValueObject',
__DIR__ . '/../src/**/ValueObject',
]
);

Expand All @@ -41,7 +42,7 @@

$services->set(Configuration::class)->factory([service(ConfigurationFactory::class), 'create']);
$services->set(FractorRunner::class)->arg('$processors', tagged_iterator('fractor.file_processor'));
$services->set(ConfigurationFactory::class)->arg('$processors', tagged_iterator('fractor.file_processor'));
$services->set(AllowedFileExtensionsResolver::class)->arg('$processors', tagged_iterator('fractor.file_processor'));

$containerBuilder->registerForAutoconfiguration(FileProcessor::class)->addTag('fractor.file_processor');
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace a9f\Fractor\Contract;
namespace a9f\Fractor\Application\Contract;

use a9f\Fractor\ValueObject\File;
use a9f\Fractor\Application\ValueObject\File;

interface FilePrinter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace a9f\Fractor\Contract;
namespace a9f\Fractor\Application\Contract;

use a9f\Fractor\ValueObject\File;
use a9f\Fractor\Application\ValueObject\File;

interface FileProcessor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace a9f\Fractor\FileSystem;
namespace a9f\Fractor\Application;

use a9f\Fractor\ValueObject\File;
use a9f\Fractor\Application\ValueObject\File;

final class FileCollector
final class FilesCollector
{
/**
* @var array<string, File>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

namespace a9f\Fractor\Fractor;

use a9f\Fractor\Contract\FilePrinter;
use a9f\Fractor\Contract\FileProcessor;
use a9f\Fractor\Contract\Output;
use a9f\Fractor\FileSystem\FileCollector;
use a9f\Fractor\FileSystem\FileFinder;
use a9f\Fractor\ValueObject\Configuration;
use a9f\Fractor\ValueObject\File;
namespace a9f\Fractor\Application;

use a9f\Fractor\Application\Contract\FilePrinter;
use a9f\Fractor\Application\Contract\FileProcessor;
use a9f\Fractor\Application\ValueObject\File;
use a9f\Fractor\Configuration\ValueObject\Configuration;
use a9f\Fractor\Console\Contract\Output;
use a9f\Fractor\FileSystem\FilesFinder;
use Nette\Utils\FileSystem;

/**
Expand All @@ -18,9 +17,9 @@
final readonly class FractorRunner
{
/**
* @param list<FileProcessor> $processors
* @param FileProcessor[] $processors
*/
public function __construct(private FileFinder $fileFinder, private FileCollector $fileCollector, private iterable $processors, private Configuration $configuration, private FilePrinter $filePrinter)
public function __construct(private FilesFinder $fileFinder, private FilesCollector $fileCollector, private iterable $processors, private Configuration $configuration, private FilePrinter $filePrinter)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace a9f\Fractor\FileSystem;
namespace a9f\Fractor\Application;

use a9f\Fractor\Contract\FilePrinter;
use a9f\Fractor\ValueObject\File;
use a9f\Fractor\Application\Contract\FilePrinter;
use a9f\Fractor\Application\ValueObject\File;
use Nette\Utils\FileSystem;

final class LocalFileSystemPrinter implements FilePrinter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace a9f\Fractor\ValueObject;
namespace a9f\Fractor\Application\ValueObject;

final class File
{
Expand Down
30 changes: 30 additions & 0 deletions fractor/src/Configuration/AllowedFileExtensionsResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace a9f\Fractor\Configuration;

use a9f\Fractor\Application\Contract\FileProcessor;

final readonly class AllowedFileExtensionsResolver
{
/**
* @param FileProcessor[] $processors
*/
public function __construct(private iterable $processors)
{
}

/**
* @return list<non-empty-string>
*/
public function resolve(): array
{
$fileExtensions = [];
foreach ($this->processors as $processor) {
$fileExtensions = array_merge($processor->allowedFileExtensions(), $fileExtensions);
}

return array_unique($fileExtensions);
}
}
23 changes: 23 additions & 0 deletions fractor/src/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace a9f\Fractor\Configuration;

use a9f\Fractor\Configuration\ValueObject\Configuration;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;

final readonly class ConfigurationFactory
{
public function __construct(private ContainerBagInterface $parameterBag, private AllowedFileExtensionsResolver $allowedFileExtensionsResolver)
{
}

public function create(): Configuration
{
return new Configuration(
$this->allowedFileExtensionsResolver->resolve(),
$this->parameterBag->get(Option::PATHS),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace a9f\Fractor\ValueObject;
namespace a9f\Fractor\Configuration\ValueObject;

use Webmozart\Assert\Assert;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

namespace a9f\Fractor\Command;
namespace a9f\Fractor\Console\Command;

use a9f\Fractor\Console\SymfonyConsoleOutput;
use a9f\Fractor\Fractor\FractorRunner;
use a9f\Fractor\Application\FractorRunner;
use a9f\Fractor\Console\Output\SymfonyConsoleOutput;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('process', 'Runs Fractor with the given configuration file')]
class ProcessCommand extends Command
final class ProcessCommand extends Command
{
public function __construct(private readonly FractorRunner $runner)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace a9f\Fractor\Contract;
namespace a9f\Fractor\Console\Contract;

interface Output
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace a9f\Fractor\Console;
namespace a9f\Fractor\Console\Output;

use a9f\Fractor\Contract\Output;
use a9f\Fractor\Console\Contract\Output;

final class NullOutput implements Output
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace a9f\Fractor\Console;
namespace a9f\Fractor\Console\Output;

use a9f\Fractor\Contract\Output;
use a9f\Fractor\Console\Contract\Output;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down
33 changes: 0 additions & 33 deletions fractor/src/Factory/ConfigurationFactory.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\Finder\Finder;

final class FileFinder
final class FilesFinder
{
/**
* @param list<non-empty-string> $directories
Expand Down
10 changes: 5 additions & 5 deletions fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace a9f\Fractor\Testing\PHPUnit;

use a9f\Fractor\Console\NullOutput;
use a9f\Fractor\Application\FilesCollector;
use a9f\Fractor\Application\FractorRunner;
use a9f\Fractor\Console\Output\NullOutput;
use a9f\Fractor\DependencyInjection\ContainerContainerBuilder;
use a9f\Fractor\Exception\ShouldNotHappenException;
use a9f\Fractor\FileSystem\FileCollector;
use a9f\Fractor\Fractor\FractorRunner;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

abstract class AbstractFractorTestCase extends TestCase
{
private ?ContainerInterface $currentContainer = null;
private FractorRunner $fractorRunner;
protected FileCollector $fileCollector;
protected FilesCollector $fileCollector;

/**
* @return array<int, string>
Expand All @@ -29,7 +29,7 @@ protected function additionalConfigurationFiles(): array
protected function setUp(): void
{
$this->bootFromConfigFile();
$this->fileCollector = $this->getService(FileCollector::class);
$this->fileCollector = $this->getService(FilesCollector::class);
$this->fractorRunner = $this->getService(FractorRunner::class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Fractor\FractorRunner;
namespace a9f\Fractor\Tests\Application\FractorRunner;

use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase;

Expand All @@ -16,7 +16,7 @@ public function test(): void
protected function additionalConfigurationFiles(): array
{
return [
__DIR__ . '/config/application.php'
__DIR__ . '/config/config.php'
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace a9f\Fractor\Tests\Configuration\AllowedFileExtensionsResolver;

use a9f\Fractor\Configuration\AllowedFileExtensionsResolver;
use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase;

final class AllowedFileExtensionsResolverTest extends AbstractFractorTestCase
{
public function test(): void
{
// Arrange
$allowedFileExtensionsResolver = $this->getService(AllowedFileExtensionsResolver::class);

// Act & Assert
self::assertSame(['txt'], $allowedFileExtensionsResolver->resolve());
}
protected function additionalConfigurationFiles(): array
{
return [
__DIR__ . '/config/config.php'
];
}
}
Loading