Skip to content

Commit

Permalink
[TASK] Make csfixer happy
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Jul 2, 2024
1 parent e46a1fa commit fde4141
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
7 changes: 1 addition & 6 deletions Classes/Service/ConvertService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@

class ConvertService
{

public function __construct(
protected readonly XlfFileService $xlfFileService,
protected readonly CsvReader $csvReader
)
{

}
) {}

public function convert(string $csvFilePath, string $out, bool $forceRebuild): array
{
Expand Down Expand Up @@ -57,5 +53,4 @@ protected function addExistingLabels(array $labels, string $language, string $pa

return array_merge($existingLabels, $labels);
}

}
2 changes: 0 additions & 2 deletions Classes/Service/CsvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class CsvReader
{

public function getFromFile(string $filePath): array
{
$csvReader = Reader::createFromPath($filePath, 'r');
Expand Down Expand Up @@ -41,5 +40,4 @@ public function getFromFile(string $filePath): array

return $labels;
}

}
22 changes: 7 additions & 15 deletions Classes/Service/XlfFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@

class XlfFileService
{


/**
* @param string $path
* @param string $language
* @return array
*/
public function getLabels(string $path, string $language): array
{
$xmlContent = file_get_contents($path);
Expand All @@ -29,25 +22,24 @@ public function getLabels(string $path, string $language): array
$rootXmlNode = simplexml_load_string($xmlContent, \SimpleXMLElement::class, LIBXML_NOWARNING);
foreach ($rootXmlNode->file->body->children() as $translationElement) {
if ($translationElement->getName() === 'trans-unit' && !isset($translationElement['restype'])) {
$approved = (string)($translationElement['approved'] ?? '');
$parsedData[(string)$translationElement['id']][0] = [
'source' => (string)$translationElement->source,
'target' => (string)$translationElement->target,
$approved = (string) ($translationElement['approved'] ?? '');
$parsedData[(string) $translationElement['id']][0] = [
'source' => (string) $translationElement->source,
'target' => (string) $translationElement->target,
];
$id = (string)$translationElement['id'];
$id = (string) $translationElement['id'];
$newLabels[$id] = new Label(
$id,
$language,
(string)$translationElement->source,
(string)$translationElement->target,
(string) $translationElement->source,
(string) $translationElement->target,
$approved
);
}
}
return $newLabels;
}


/**
* @param Label[] $labels
* @return string|bool
Expand Down
9 changes: 4 additions & 5 deletions Tests/Unit/Service/CsvReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class CsvReaderTest extends UnitTestCase
{

protected CsvReader $subject;

public function setUp(): void
Expand All @@ -33,11 +32,11 @@ public function testForEnAs2ndHeaderField(): void
/**
* @throws \JsonException
*/
public function testCsvReading():void
public function testCsvReading(): void
{
$labels = $this->subject->getFromFile(__DIR__ . '/Fixtures/reader/valid.csv');
$json = json_encode($labels, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE);
$labels = $this->subject->getFromFile(__DIR__ . '/Fixtures/reader/valid.csv');
$json = json_encode($labels, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);

$this->assertJsonStringEqualsJsonFile(__DIR__ . '/Fixtures/reader/valid.json', $json);
self::assertJsonStringEqualsJsonFile(__DIR__ . '/Fixtures/reader/valid.json', $json);
}
}

0 comments on commit fde4141

Please sign in to comment.