mirror of https://github.com/rectorphp/rector.git
[DX] Drop YamlFileFormatter as Rector does not process YAML (#2376)
This commit is contained in:
parent
a7e6b685e9
commit
2c46d4fc4d
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\FileFormatter\Formatter\YamlFileFormatter;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\ValueObject\Application\File;
|
||||
use Rector\FileFormatter\Formatter\YamlFileFormatter;
|
||||
use Rector\FileFormatter\ValueObject\Indent;
|
||||
use Rector\FileFormatter\ValueObjectFactory\EditorConfigConfigurationBuilder;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
|
||||
use Symplify\EasyTesting\StaticFixtureSplitter;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class YamlFileFormatterTest extends AbstractTestCase
|
||||
{
|
||||
private YamlFileFormatter $yamlFileFormatter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
$this->yamlFileFormatter = $this->getService(YamlFileFormatter::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<array<int, SmartFileInfo>>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return StaticFixtureFinder::yieldDirectory(__DIR__ . '/Fixture', '*.yaml');
|
||||
}
|
||||
|
||||
private function doTestFileInfo(SmartFileInfo $smartFileInfo): void
|
||||
{
|
||||
$inputFileInfoAndExpected = StaticFixtureSplitter::splitFileInfoToLocalInputAndExpected($smartFileInfo);
|
||||
|
||||
$inputFileInfo = $inputFileInfoAndExpected->getInputFileInfo();
|
||||
$file = new File($inputFileInfo, $inputFileInfo->getContents());
|
||||
|
||||
$editorConfigConfigurationBuilder = new EditorConfigConfigurationBuilder();
|
||||
$editorConfigConfigurationBuilder->withIndent(Indent::createSpaceWithSize(4));
|
||||
$editorConfigConfigurationBuilder->withInsertFinalNewline(false);
|
||||
|
||||
$this->yamlFileFormatter->format($file, $editorConfigConfigurationBuilder->build());
|
||||
|
||||
$this->assertSame($inputFileInfoAndExpected->getExpected(), $file->getFileContent());
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\FileFormatter\Formatter;
|
||||
|
||||
use Rector\Core\ValueObject\Application\File;
|
||||
use Rector\FileFormatter\Contract\Formatter\FileFormatterInterface;
|
||||
use Rector\FileFormatter\ValueObject\EditorConfigConfiguration;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* @see \Rector\Tests\FileFormatter\Formatter\YamlFileFormatter\YamlFileFormatterTest
|
||||
*/
|
||||
final class YamlFileFormatter implements FileFormatterInterface
|
||||
{
|
||||
public function supports(File $file): bool
|
||||
{
|
||||
$smartFileInfo = $file->getSmartFileInfo();
|
||||
|
||||
return in_array($smartFileInfo->getExtension(), ['yaml', 'yml'], true);
|
||||
}
|
||||
|
||||
public function format(File $file, EditorConfigConfiguration $editorConfigConfiguration): void
|
||||
{
|
||||
$yaml = Yaml::parse($file->getFileContent(), Yaml::PARSE_CUSTOM_TAGS);
|
||||
|
||||
$newFileContent = Yaml::dump($yaml, 99, $editorConfigConfiguration->getIndentSize());
|
||||
|
||||
$file->changeFileContent($newFileContent);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue