Skip to content

Commit

Permalink
slash
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Dec 16, 2023
1 parent 2321183 commit bdc71e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/ConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class ConfigLoader
* @see https://regex101.com/r/4Uanps/4
* @var string
*/
private const PHP_CONST_REGEX = '#!php/const:?\s*([a-zA-Z0-9_\\\]+(::\w+)?)+(:\s*(.*))?#';
private const PHP_CONST_REGEX = '#!php/const:?\s*([a-zA-Z0-9_\\\\]+(::\w+)?)+(:\s*(.*))?#';
/**
* @see https://regex101.com/r/spi4ir/1
Expand All @@ -43,15 +43,15 @@ public function __construct(
}

public function createAndLoadContainerBuilderFromFileInfo(
SplFileInfo $smartFileInfo,
SplFileInfo $fileInfo,
): ContainerBuilderAndFileContent {
$containerBuilder = new ContainerBuilder();

$delegatingLoader = $this->createLoaderBySuffix($containerBuilder, $smartFileInfo->getExtension());
$fileRealPath = $smartFileInfo->getRealPath();
$delegatingLoader = $this->createLoaderBySuffix($containerBuilder, $fileInfo->getExtension());
$fileRealPath = $fileInfo->getRealPath();

// correct old syntax of tags so we can parse it
$content = $smartFileInfo->getContents();
$content = $fileInfo->getContents();

// fake quoting of parameter, as it was removed in Symfony 3.1: https://symfony.com/blog/new-in-symfony-3-1-yaml-deprecations
$content = Strings::replace(
Expand All @@ -60,7 +60,7 @@ public function createAndLoadContainerBuilderFromFileInfo(
static fn (array $match): string => $match[1] . '"' . $match[2] . ($match[4] ?? '') . '"'
);

if (in_array($smartFileInfo->getExtension(), [Format::YML, Format::YAML], true)) {
if (in_array($fileInfo->getExtension(), [Format::YML, Format::YAML], true)) {
$content = Strings::replace(
$content,
self::PHP_CONST_REGEX,
Expand All @@ -70,8 +70,8 @@ public function createAndLoadContainerBuilderFromFileInfo(
(string) $match[1]
) . ')%"' . ($match[3] ?? '')
);
if ($content !== $smartFileInfo->getContents()) {
$fileRealPath = sys_get_temp_dir() . '/__symplify_config_tranformer_clean_yaml/' . $smartFileInfo->getFilename();
if ($content !== $fileInfo->getContents()) {
$fileRealPath = sys_get_temp_dir() . '/__symplify_config_tranformer_clean_yaml/' . $fileInfo->getFilename();
FileSystem::write($fileRealPath, $content);
}

Expand Down
20 changes: 10 additions & 10 deletions tests/Helper/FixtureSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ public static function splitFileInfoToInputAndExpected(SplFileInfo $smartFileInf
}

public static function splitFileInfoToLocalInputAndExpectedFileInfos(
SplFileInfo $smartFileInfo,
bool $autoloadTestFixture = false,
bool $preserveDirStructure = false
SplFileInfo $fileInfo,
bool $autoloadTestFixture = false,
bool $preserveDirStructure = false
): InputFileInfoAndExpectedFileInfo {
$inputAndExpected = self::splitFileInfoToInputAndExpected($smartFileInfo);
$inputAndExpected = self::splitFileInfoToInputAndExpected($fileInfo);

$prefix = '';
if ($preserveDirStructure) {
$dir = explode('Fixture', $smartFileInfo->getRealPath(), 2);
$dir = explode('Fixture', $fileInfo->getRealPath(), 2);
$prefix = isset($dir[1]) ? dirname($dir[1]) . '/' : '';
$prefix = ltrim($prefix, '/\\');
}

$inputFileInfo = self::createTemporaryFileInfo(
$smartFileInfo,
$fileInfo,
$prefix . 'input',
$inputAndExpected->getInput()
);
Expand All @@ -64,7 +64,7 @@ public static function splitFileInfoToLocalInputAndExpectedFileInfos(
}

$expectedFileInfo = self::createTemporaryFileInfo(
$smartFileInfo,
$fileInfo,
$prefix . 'expected',
$inputAndExpected->getExpected()
);
Expand Down Expand Up @@ -96,11 +96,11 @@ public static function createTemporaryFileInfo(
return new SplFileInfo($temporaryFilePath, '', '');
}

private static function createTemporaryPathWithPrefix(SplFileInfo $smartFileInfo, string $prefix): string
private static function createTemporaryPathWithPrefix(SplFileInfo $fileInfo, string $prefix): string
{
$hash = Strings::substring(md5($smartFileInfo->getRealPath()), -20);
$hash = Strings::substring(md5($fileInfo->getRealPath()), -20);

$fileBasename = $smartFileInfo->getBasename('.inc');
$fileBasename = $fileInfo->getBasename('.inc');

return self::getTemporaryPath() . sprintf('/%s_%s_%s', $prefix, $hash, $fileBasename);
}
Expand Down

0 comments on commit bdc71e9

Please sign in to comment.