diff --git a/src/Api/Controllers/V1/ElixFormsController.php b/src/Api/Controllers/V1/ElixFormsController.php index 624adcf..f296a77 100644 --- a/src/Api/Controllers/V1/ElixFormsController.php +++ b/src/Api/Controllers/V1/ElixFormsController.php @@ -50,7 +50,7 @@ class ElixFormsController $matchingInstances = []; foreach ($instances as $instance) { - if (!is_array($instance)) { + if (!\is_array($instance)) { continue; } @@ -67,18 +67,16 @@ class ElixFormsController $exportGroup ); - foreach ($exportTags as $exportTag) { - if (!is_array($exportTag) || !isset($exportTag['name'])) { - continue; - } + $exportTagsByName = array_column($exportTags, null, 'name'); + if (!\array_key_exists($fieldName, $exportTagsByName)) { + continue; + } - $name = (string) $exportTag['name']; - $value = isset($exportTag['value']) ? (string) $exportTag['value'] : ''; + $exportTag = $exportTagsByName[$fieldName]; + $value = isset($exportTag['value']) ? (string) $exportTag['value'] : ''; - if (strcasecmp($name, $fieldName) === 0 && stripos($value, $fieldValue) !== false) { - $matchingInstances[] = $instance; - break; - } + if (stripos($value, $fieldValue) !== false) { + $matchingInstances[] = $instance; } } diff --git a/tests/Unit/ElixFormsControllerTest.php b/tests/Unit/ElixFormsControllerTest.php index 88f6640..752aafd 100644 --- a/tests/Unit/ElixFormsControllerTest.php +++ b/tests/Unit/ElixFormsControllerTest.php @@ -54,16 +54,22 @@ final class ElixFormsControllerTest extends TestCase throw new \RuntimeException('exportGroup non inoltrato al client.'); } - $values = [ - 10 => 'Nessuna corrispondenza', - 20 => 'Il contratto ABC-123 è presente', - 30 => 'Altro valore', + $tags = [ + 10 => [ + 'name' => 'contratto.altro', + 'value' => 'Il contratto ABC-123 è presente', + ], + 20 => [ + 'name' => 'contratto.id', + 'value' => 'Il contratto ABC-123 è presente', + ], + 30 => [ + 'name' => 'contratto.id', + 'value' => 'Altro valore', + ], ]; - return [[ - 'name' => 'contratto.id', - 'value' => $values[$requestId], - ]]; + return [$tags[$requestId]]; } }; $config = new class extends Config {