Skip to content

Commit

Permalink
chore: fix/revert ide formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolGoose committed May 5, 2024
1 parent 29c4f3b commit 3460e87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
14 changes: 5 additions & 9 deletions src/Exporters/LaravelExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ public function handle(LarexExportCommand $command, CsvReader $reader): int

foreach ($groups as $group => $keys) {
$write = fopen(lang_path("$folder/$group.php"), 'wb');
fwrite(
$write,
/** @lang text */
"<?php$eol{$eol}return [$eol$eol"
);
fwrite($write, /** @lang text */ "<?php$eol{$eol}return [$eol$eol");

foreach ($keys as $key => $value) {
self::writeKeyValue($key, $value, $write, 1, $eol);
Expand All @@ -84,7 +80,7 @@ protected static function writeKeyValue($key, $value, &$file, int $level = 1, $e
$enclosure = '"';

if (is_array($value)) {
fwrite($file, str_repeat(' ', $level) . "'$key' => [$eol");
fwrite($file, str_repeat(' ', $level)."'$key' => [$eol");
$level++;
foreach ($value as $childKey => $childValue) {
self::writeKeyValue($childKey, $childValue, $file, $level, $eol);
Expand All @@ -95,13 +91,13 @@ protected static function writeKeyValue($key, $value, &$file, int $level = 1, $e
}

$value = (string)$value;
$value = str_replace(["'", '\\' . $enclosure], ["\'", $enclosure], $value);
$value = str_replace(["'", '\\'.$enclosure], ["\'", $enclosure], $value);

if (is_int($key) || (is_numeric($key) && ctype_digit($key))) {
$key = (int)$key;
fwrite($file, str_repeat(' ', $level) . "$key => '$value',$eol");
fwrite($file, str_repeat(' ', $level)."$key => '$value',$eol");
} else {
fwrite($file, str_repeat(' ', $level) . "'$key' => '$value',$eol");
fwrite($file, str_repeat(' ', $level)."'$key' => '$value',$eol");
}
}
}
4 changes: 2 additions & 2 deletions tests/Exporters/LaravelExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@

$this->artisan(LarexExportCommand::class, ['exporter' => 'laravel', '--exclude' => 'en'])
->expectsOutput(sprintf("Processing the '%s' file...", csv_path(true)))
->expectsOutput(lang_rpath('it/app.php') . ' created successfully.')
->expectsOutput(lang_rpath('it/another.php') . ' created successfully.')
->expectsOutput(lang_rpath('it/app.php').' created successfully.')
->expectsOutput(lang_rpath('it/another.php').' created successfully.')
->assertExitCode(0);

expect(lang_path('en/app.php'))->not->toBeFile();
Expand Down
22 changes: 9 additions & 13 deletions tests/Importers/LaravelImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@
->toEqualStub('importers.laravel.territory.output');
});

it(
'imports strings and set the source language',
it('imports strings and set the source language',
function (string $source, string $expected, bool $skipSourceReordering) {
File::makeDirectory(lang_path('ar'), 0755, true, true);
File::makeDirectory(lang_path('en'), 0755, true, true);
Expand All @@ -96,10 +95,8 @@ function (string $source, string $expected, bool $skipSourceReordering) {

config(['larex.source_language' => $source]);

$this->artisan(
LarexImportCommand::class,
['importer' => 'laravel', '--skip-source-reordering' => $skipSourceReordering]
)
$this->artisan(LarexImportCommand::class,
['importer' => 'laravel', '--skip-source-reordering' => $skipSourceReordering])
->expectsOutput('Importing entries...')
->expectsOutput('Data imported successfully.')
->assertExitCode(0);
Expand All @@ -108,13 +105,12 @@ function (string $source, string $expected, bool $skipSourceReordering) {
->toBeFile()
->fileContent()
->toEqualStub($expected);
}
)->with([
'ar' => ['ar', 'importers.laravel.source.output-ar', false],
'en' => ['en', 'importers.laravel.source.output-en', false],
'en-skip' => ['en', 'importers.laravel.source.output-ar', true],
'invalid-lang' => ['es', 'importers.laravel.source.output-ar', false],
]);
})->with([
'ar' => ['ar', 'importers.laravel.source.output-ar', false],
'en' => ['en', 'importers.laravel.source.output-en', false],
'en-skip' => ['en', 'importers.laravel.source.output-ar', true],
'invalid-lang' => ['es', 'importers.laravel.source.output-ar', false],
]);

it('imports strings with normalize option on', function () {
File::makeDirectory(lang_path('en'), 0755, true, true);
Expand Down

0 comments on commit 3460e87

Please sign in to comment.