Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
* @param \Ibexa\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
* @param \Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition $fieldDef
*/
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)

Check failure on line 103 in src/lib/Persistence/Legacy/Content/FieldValue/Converter/SelectionConverter.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=ibexa_core&issues=AZ1xySX80GpFjC_qHQ1M&open=AZ1xySX80GpFjC_qHQ1M&pullRequest=706
{
$options = [];
$multiLingualOptions = [$fieldDef->mainLanguageCode => []];
Expand All @@ -119,7 +119,7 @@
}

foreach ($storageDef->multilingualData as $languageCode => $mlData) {
$xml = simplexml_load_string($mlData->dataText);
$xml = $mlData->dataText ? simplexml_load_string($mlData->dataText) : false;
if ($xml !== false) {
foreach ($xml->options->option as $option) {
$multiLingualOptions[$languageCode][(int)$option['id']] = (string)$option['name'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition as PersistenceFieldDefinition;
use Ibexa\Core\FieldType\FieldSettings;
use Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter\SelectionConverter;
use Ibexa\Core\Persistence\Legacy\Content\MultilingualStorageFieldDefinition;
use Ibexa\Core\Persistence\Legacy\Content\StorageFieldDefinition;
use Ibexa\Core\Persistence\Legacy\Content\StorageFieldValue;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -325,6 +326,43 @@ public function testToFieldDefinitionSingleEmpty()

$this->assertEquals($expectedFieldDefinition, $actualFieldDefinition);
}

public function testToFieldDefinitionWithMultilingualDataSkipsEmptyDataText(): void
{
$storageFieldDefinition = new StorageFieldDefinition();
$storageFieldDefinition->dataInt1 = 1;
$storageFieldDefinition->dataText5 = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<ezselection><options><option id="0" name="First"/></options></ezselection>
EOT;

$mlDataEmpty = new MultilingualStorageFieldDefinition();
$mlDataEmpty->dataText = '';

$mlDataValid = new MultilingualStorageFieldDefinition();
$mlDataValid->dataText = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<ezselection><options><option id="0" name="Premier"/></options></ezselection>
EOT;

$storageFieldDefinition->multilingualData = [
'eng-GB' => $mlDataEmpty,
'fre-FR' => $mlDataValid,
];

$actualFieldDefinition = new PersistenceFieldDefinition(
[
'mainLanguageCode' => 'eng-GB',
]
);

$this->converter->toFieldDefinition($storageFieldDefinition, $actualFieldDefinition);

$fieldSettings = $actualFieldDefinition->fieldTypeConstraints->fieldSettings;
Comment thread
konradoboza marked this conversation as resolved.

self::assertSame([0 => 'First'], $fieldSettings['multilingualOptions']['eng-GB']);
self::assertSame([0 => 'Premier'], $fieldSettings['multilingualOptions']['fre-FR']);
}
}

class_alias(SelectionTest::class, 'eZ\Publish\Core\Persistence\Legacy\Tests\Content\FieldValue\Converter\SelectionTest');
Loading