From 8e2baaa7d7a305a679c8bb7cfed85ec17d0c7281 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Thu, 28 May 2026 06:41:07 +0200 Subject: [PATCH] fix(archimate): fill all empty-if bodies in export/import/service L1: Fill all empty-if blocks in ArchiMateExportService, ArchiMateImportService, and ArchiMateService that had dead initializer+empty-guard patterns: - extractViewData/addObjectToFolder: json_decode string xml_data to array - extractNodeType/extractConnectionType: return correct type values for Label/Element/namespaced - extractRelationshipEndpoint: return string/href/source values - findItemsSimplified: return multi-item arrays vs single-item wraps - flattenPropertiesBatch: normalize indexed property arrays - generateApplicationElements/generateSpecializationRelationships: apply prefix - AMEF registerId: load from getAmefRegisterId() for AMEF types - Debug log vars (nodeCount, connectionCount, xmlKeys, propMapCount, etc): populate for logging - Error message: distinguish AMEF vs per-type config missing --- lib/Service/ArchiMateExportService.php | 54 ++-- lib/Service/ArchiMateImportService.php | 327 ++++++++----------------- lib/Service/ArchiMateService.php | 70 +++--- 3 files changed, 168 insertions(+), 283 deletions(-) diff --git a/lib/Service/ArchiMateExportService.php b/lib/Service/ArchiMateExportService.php index caf51e8d..d594ca89 100644 --- a/lib/Service/ArchiMateExportService.php +++ b/lib/Service/ArchiMateExportService.php @@ -346,9 +346,8 @@ private function getNamespaceUri(\SimpleXMLElement $xml, string $prefix): string return $wellKnown[$prefix]; } - $namespaces = []; - if ($xml->getDocNamespaces(true) !== false) { - } + $docNamespaces = $xml->getDocNamespaces(true); + $namespaces = ($docNamespaces !== false) ? $docNamespaces : []; return $namespaces[$prefix] ?? ''; }//end getNamespaceUri() @@ -550,12 +549,14 @@ private function addViewToFolder(\SimpleXMLElement $folder, array $view): void // DEBUG: Check if this is our target view with nodes. $targetId = 'id-1c197dc3-71e5-40dc-8f5d-a96e983b41af'; if (isset($viewData['_identifier']) === true && $viewData['_identifier'] === $targetId) { - $nodeCountValue = 0; + $nodeCountValue = 0; if (is_array($viewData['node'] ?? null) === true) { + $nodeCountValue = count($viewData['node']); } - $nodeSampleValue = 'NO FIRST NODE'; + $nodeSampleValue = 'NO FIRST NODE'; if (isset($viewData['node'][0]) === true) { + $nodeSampleValue = $viewData['node'][0]; } $this->logger->debug( @@ -573,12 +574,14 @@ private function addViewToFolder(\SimpleXMLElement $folder, array $view): void ); }//end if - $nodeCountValue = 0; + $nodeCountValue = 0; if (is_array($viewData['node'] ?? null) === true) { + $nodeCountValue = count($viewData['node']); } - $connectionCountValue = 0; + $connectionCountValue = 0; if (is_array($viewData['connection'] ?? null) === true) { + $connectionCountValue = count($viewData['connection']); } $this->logger->debug( @@ -616,26 +619,30 @@ private function extractViewData(array $view): ?array { // Format 1: OpenRegister object format with properties.xml_data. if (isset($view['properties']['xml_data']) === true) { - $xmlData = $view['properties']['xml_data']; + $xmlData = $view['properties']['xml_data']; if (is_string($view['properties']['xml_data']) === true) { + $xmlData = json_decode($view['properties']['xml_data'], true) ?? []; } if (is_array($xmlData) === true) { + return $xmlData; } - return null; + return null; } // Format 2: Object with xml_data field (from database). if (isset($view['xml_data']) === true) { - $xmlData = $view['xml_data']; + $xmlData = $view['xml_data']; if (is_string($view['xml_data']) === true) { + $xmlData = json_decode($view['xml_data'], true) ?? []; } if (is_array($xmlData) === true) { + return $xmlData; } - return null; + return null; } // Format 3: Direct XML data (from convertFromOpenRegisterObjects). @@ -735,8 +742,9 @@ private function addObjectToFolder(\SimpleXMLElement $folder, array $object, str // 3. Raw object data as fallback. if (isset($object['properties']['xml_data']) === true) { // Format 1: OpenRegister object format. - $xmlData = $object['properties']['xml_data']; + $xmlData = $object['properties']['xml_data']; if (is_string($object['properties']['xml_data']) === true) { + $xmlData = json_decode($object['properties']['xml_data'], true) ?? []; } if (is_array($xmlData) === true) { @@ -744,8 +752,9 @@ private function addObjectToFolder(\SimpleXMLElement $folder, array $object, str } } else if (isset($object['xml_data']) === true) { // Format 2: Object with xml_data field (from database). - $xmlData = $object['xml_data']; + $xmlData = $object['xml_data']; if (is_string($object['xml_data']) === true) { + $xmlData = json_decode($object['xml_data'], true) ?? []; } if (is_array($xmlData) === true) { @@ -2561,8 +2570,9 @@ private function buildModuleLookupMaps(array $gebruikData, array $modulesData): } foreach ($refComps as $refComp) { - $refCompUuid = ($refComp['id'] ?? $refComp['uuid'] ?? null); + $refCompUuid = ($refComp['id'] ?? $refComp['uuid'] ?? null); if (is_string($refComp) === true) { + $refCompUuid = $refComp; } if ($refCompUuid === null) { @@ -2644,9 +2654,10 @@ private function generateApplicationElements( string $bronPropDefId, string $prefix='' ): array { - $elements = []; - $idPrefix = 'id-swc-app-'; + $elements = []; + $idPrefix = 'id-swc-app-'; if ($prefix !== '') { + $idPrefix = $prefix.'-app-'; } foreach ($moduleRefMap as $moduleId => $refCompIds) { @@ -2680,13 +2691,15 @@ private function generateSpecializationRelationships( string $bronPropDefId, string $prefix='' ): array { - $relationships = []; - $appIdPrefix = 'id-swc-app-'; + $relationships = []; + $appIdPrefix = 'id-swc-app-'; if ($prefix !== '') { + $appIdPrefix = $prefix.'-app-'; } - $relIdPrefix = 'id-swc-rel-'; + $relIdPrefix = 'id-swc-rel-'; if ($prefix !== '') { + $relIdPrefix = $prefix.'-rel-'; } foreach ($moduleRefMap as $moduleId => $refCompIds) { @@ -2841,9 +2854,10 @@ private function getViewSwcTitle(array $viewData): ?string $propName = $prop['_name'] ?? $prop['name'] ?? ''; if (is_string($propName) === true && stripos($propName, 'Titel view SWC') !== false && $value !== null) { if (is_string($value) === true) { + return $value; } - return null; + return null; } } diff --git a/lib/Service/ArchiMateImportService.php b/lib/Service/ArchiMateImportService.php index f19fa96c..9280bc12 100644 --- a/lib/Service/ArchiMateImportService.php +++ b/lib/Service/ArchiMateImportService.php @@ -210,10 +210,10 @@ public function xmlToArray(\SimpleXMLElement $xml): array foreach ($attributes as $attrName => $attrValue) { $name = (string) $attrName; $value = (string) $attrValue; - // OPTIMIZATION: Only create underscored key if needed (skip str_replace for simple names). - $underscoredKey = '_'.$name; - if ((strpos($name, ':') !== false)) { - } + // OPTIMIZATION: Only apply str_replace for namespaced names (e.g. xsi:type -> _xsi_type). + $underscoredKey = (strpos($name, ':') !== false) + ? '_'.str_replace(':', '_', $name) + : '_'.$name; $result[$underscoredKey] = $value; $attrBag[$name] = $value; @@ -515,9 +515,7 @@ public function importArchiMateFileFromPath(array $options=[]): array $created = $statistics['summary']['total_objects_created']; $updated = $statistics['summary']['total_objects_updated']; $totalObjects = $created + $updated; - $itemsPerSecond = 0; - if ($totalObjects > 0) { - } + $itemsPerSecond = ($totalObjects > 0) ? round($totalObjects / max($totalTime, 0.001), 2) : 0; // Extract detailed error information from statistics. $detailedErrors = $this->extractDetailedErrors(statistics: $statistics); @@ -1283,10 +1281,6 @@ private function saveObjectsToDatabase(array $objects): array $objects, fn($o) => ($o['section'] ?? '') === 'element' && empty($o['gemmaType']) === false ); - $sampleGemmaElem = null; - if (empty($gemmaElements) === false) { - } - $this->logger->debug( 'Objects before save', [ @@ -1350,9 +1344,7 @@ private function saveObjectsToDatabase(array $objects): array try { // Save this schema group with the specific schema ID. // PERFORMANCE: Disabled validation and events for bulk import (like CSV import pattern). - $schemaValue = null; - if ($schemaId !== 'unknown') { - } + $schemaValue = ($schemaId !== 'unknown') ? $schemaId : null; $saveResult = $objectService->saveObjects( objects: $schemaObjects, @@ -1427,9 +1419,7 @@ private function saveObjectsToDatabase(array $objects): array $updatedCount = count($aggregatedStats['updated'] ?? []); $unchangedCount = count($aggregatedStats['unchanged'] ?? []); $totalSavedCount = $savedCount + $updatedCount + $unchangedCount; - $objectsSavedValue = count($objects); - if ($totalSavedCount > 0) { - } + $objectsSavedValue = ($totalSavedCount > 0) ? $totalSavedCount : count($objects); $this->lastSaveTiming = [ 'total_save_seconds' => round($totalSaveTime, 3), @@ -1566,9 +1556,7 @@ private function saveObjectsDirectToService(array $objects, ObjectService $objec $allInvalid = []; foreach ($schemaGroups as $schemaId => $schemaObjects) { - $schemaValue = null; - if ($schemaId !== 'unknown') { - } + $schemaValue = ($schemaId !== 'unknown') ? $schemaId : null; $saveResult = $objectService->saveObjects( objects: $schemaObjects, @@ -1672,9 +1660,8 @@ private function saveObjectsInParallelBatches(array $objects, ObjectService $obj $chunkInputCount = count($chunk); try { - $_rbacValue = true; - if (self::PERFORMANCE_OPTIMIZATIONS['disable_rbac'] === true) { - } + // Disable RBAC for bulk import when the performance optimisation flag is set. + $_rbacValue = (self::PERFORMANCE_OPTIMIZATIONS['disable_rbac'] === true) ? false : true; $saveResult = $objectService->saveObjects( objects: $chunk, @@ -1762,9 +1749,8 @@ private function saveObjectsInParallelBatches(array $objects, ObjectService $obj private function saveObjectsInSingleBatch(array $objects, ObjectService $objectService, int $registerId): array { // Using single batch processing. - $_rbacValue = true; - if (self::PERFORMANCE_OPTIMIZATIONS['disable_rbac'] === true) { - } + // Disable RBAC for bulk import when the performance optimisation flag is set. + $_rbacValue = (self::PERFORMANCE_OPTIMIZATIONS['disable_rbac'] === true) ? false : true; $saveResult = $objectService->saveObjects( objects: $objects, @@ -2012,8 +1998,9 @@ private function getAmefRegisterId(): ?int // Fallback to legacy individual app config keys if not present in JSON. if ($rawRegisterId === null || $rawRegisterId === '') { - $rawRegisterId = $this->config->getValueString('softwarecatalog', 'amef_register_id', ''); + $rawRegisterId = $this->config->getValueString('softwarecatalog', 'amef_register_id', ''); if ($this->config->getValueString('softwarecatalog', 'amef_register', '') !== '') { + $rawRegisterId = $this->config->getValueString('softwarecatalog', 'amef_register', ''); } } @@ -2021,9 +2008,8 @@ private function getAmefRegisterId(): ?int if ($rawRegisterId !== null && $rawRegisterId !== '' && is_numeric((string) $rawRegisterId) === true) { $registerId = (int) $rawRegisterId; if ($registerId > 0) { + return $registerId; } - - return null; } return null; @@ -2085,8 +2071,9 @@ private function getAmefSchemaIdForType(string $archiMateType): ?int // Fallback to legacy individual app config keys if not present in JSON. foreach ($candidates as $key) { - $raw = $this->config->getValueString('softwarecatalog', $key, ''); + $raw = $this->config->getValueString('softwarecatalog', $key, ''); if ($this->config->getValueString('softwarecatalog', 'amef_'.$key, '') !== '') { + $raw = $this->config->getValueString('softwarecatalog', 'amef_'.$key, ''); } if ($raw !== '' && is_numeric((string) $raw) === true) { @@ -2680,11 +2667,13 @@ private function extractIdentifierByPattern(array $item, array $pattern): ?strin switch ($type) { case 'direct': if (is_string($current) === true) { + return $current; } return null; case 'value': if (is_array($current) === true && isset($current['_value']) === true) { + return $current['_value']; } return null; @@ -2895,21 +2884,10 @@ private function extractViewNodesRecursively($nodeData, array $elementsLookup=[] } // Create viewNode with standardized structure. - $xValue = 0; - if (isset($node['_attributes']['x']) === true) { - } - - $yValue = 0; - if (isset($node['_attributes']['y']) === true) { - } - - $widthValue = 100; - if (isset($node['_attributes']['w']) === true) { - } - - $heightValue = 50; - if (isset($node['_attributes']['h']) === true) { - } + $xValue = (int) ($node['_attributes']['x'] ?? 0); + $yValue = (int) ($node['_attributes']['y'] ?? 0); + $widthValue = (int) ($node['_attributes']['w'] ?? 100); + $heightValue = (int) ($node['_attributes']['h'] ?? 50); $viewNode = [ 'modelNodeId' => $elementRef, @@ -3100,21 +3078,10 @@ private function extractNodesRecursively($nodeData, array $elementsLookup=[]): a foreach ($nodeData as $node) { if (isset($node['_attributes']) === true) { - $xValue = null; - if (isset($node['_attributes']['x']) === true) { - } - - $yValue = null; - if (isset($node['_attributes']['y']) === true) { - } - - $wValue = null; - if (isset($node['_attributes']['w']) === true) { - } - - $hValue = null; - if (isset($node['_attributes']['h']) === true) { - } + $xValue = isset($node['_attributes']['x']) === true ? (int) $node['_attributes']['x'] : null; + $yValue = isset($node['_attributes']['y']) === true ? (int) $node['_attributes']['y'] : null; + $wValue = isset($node['_attributes']['w']) === true ? (int) $node['_attributes']['w'] : null; + $hValue = isset($node['_attributes']['h']) === true ? (int) $node['_attributes']['h'] : null; $processedNode = [ 'identifier' => $node['_attributes']['identifier'] ?? null, @@ -3305,17 +3272,9 @@ private function applyNodeStyle(array &$viewNode, array $style): void // Extract fillColor. if (isset($style['fillColor']['_attributes']) === true) { $fillColor = $style['fillColor']['_attributes']; - $r = 255; - if (isset($fillColor['r']) === true) { - } - - $g = 255; - if (isset($fillColor['g']) === true) { - } - - $b = 255; - if (isset($fillColor['b']) === true) { - } + $r = (int) ($fillColor['r'] ?? 255); + $g = (int) ($fillColor['g'] ?? 255); + $b = (int) ($fillColor['b'] ?? 255); $viewNode['color'] = "rgb($r, $g, $b)"; }//end if @@ -3323,21 +3282,10 @@ private function applyNodeStyle(array &$viewNode, array $style): void // Extract lineColor (including alpha for border visibility). if (isset($style['lineColor']['_attributes']) === true) { $lineColor = $style['lineColor']['_attributes']; - $r = 0; - if (isset($lineColor['r']) === true) { - } - - $g = 0; - if (isset($lineColor['g']) === true) { - } - - $b = 0; - if (isset($lineColor['b']) === true) { - } - - $a = 100; - if (isset($lineColor['a']) === true) { - } + $r = (int) ($lineColor['r'] ?? 0); + $g = (int) ($lineColor['g'] ?? 0); + $b = (int) ($lineColor['b'] ?? 0); + $a = (int) ($lineColor['a'] ?? 100); if ($a < 100) { $viewNode['borderColor'] = "rgba($r, $g, $b, ".round($a / 100, 2).")"; @@ -3361,19 +3309,10 @@ private function applyNodeStyle(array &$viewNode, array $style): void } if (isset($style['font']['color']['_attributes']) === true) { - $fontColor = $style['font']['color']['_attributes']; - $r = 0; - if (isset($fontColor['r']) === true) { - } - - $g = 0; - if (isset($fontColor['g']) === true) { - } - - $b = 0; - if (isset($fontColor['b']) === true) { - } - + $fontColor = $style['font']['color']['_attributes']; + $r = (int) ($fontColor['r'] ?? 0); + $g = (int) ($fontColor['g'] ?? 0); + $b = (int) ($fontColor['b'] ?? 0); $font['color'] = "rgb($r, $g, $b)"; }//end if @@ -3437,19 +3376,13 @@ private function extractViewRelationshipsRecursively($connectionData): array // Extract bend points if present. if (isset($connection['bendpoint']) === true) { - $bendpoints = [$connection['bendpoint']]; - if (isset($connection['bendpoint'][0]) === true) { - } + // Normalise to indexed array: single bendpoint is a plain assoc array. + $bendpoints = (isset($connection['bendpoint'][0]) === true) ? $connection['bendpoint'] : [$connection['bendpoint']]; foreach ($bendpoints as $bendpoint) { if (isset($bendpoint['_attributes']) === true) { - $xValue = 0; - if (isset($bendpoint['_attributes']['x']) === true) { - } - - $yValue = 0; - if (isset($bendpoint['_attributes']['y']) === true) { - } + $xValue = (int) ($bendpoint['_attributes']['x'] ?? 0); + $yValue = (int) ($bendpoint['_attributes']['y'] ?? 0); $viewRelationship['bendpoints'][] = [ 'x' => $xValue, @@ -3515,21 +3448,10 @@ private function extractLabelMarkup(array $style): array if (isset($style['font']['color']['_attributes']) === true) { $fontColor = $style['font']['color']['_attributes']; - $r = 0; - if (isset($fontColor['r']) === true) { - } - - $g = 0; - if (isset($fontColor['g']) === true) { - } - - $b = 0; - if (isset($fontColor['b']) === true) { - } - - $a = 1; - if (isset($fontColor['a']) === true) { - } + $r = (int) ($fontColor['r'] ?? 0); + $g = (int) ($fontColor['g'] ?? 0); + $b = (int) ($fontColor['b'] ?? 0); + $a = (int) ($fontColor['a'] ?? 1); // Convert percentage to decimal. $markup['style']['fontColor'] = "rgba($r, $g, $b, $a)"; @@ -3554,16 +3476,19 @@ private function extractNodeType(array $node): ?string // Handle different xsi:type formats. if ($xsiType === 'Label') { + return 'label'; } if ($xsiType === 'Element') { + return 'element'; } if (str_contains($xsiType, ':') === true) { // Handle namespaced types like "archimate:BusinessService". + return strtolower(substr($xsiType, (int)strpos($xsiType, ':') + 1)); } - return strtolower($xsiType); + return strtolower($xsiType); } // Priority 2: Check if this is a Label node (has label content). @@ -3601,13 +3526,15 @@ private function extractConnectionType(array $connection): string // Remove namespace. $type = preg_replace('/relationship$/i', '', $type); // Remove "Relationship" suffix. + return strtolower((string)$type); } if (str_contains($xsiType, ':') === true) { // Handle other namespaced types. + return strtolower(substr($xsiType, (int)strpos($xsiType, ':') + 1)); } - return strtolower($xsiType); + return strtolower($xsiType); } // Priority 2: Check if this has a relationshipRef (use that to determine type if possible). @@ -3634,55 +3561,23 @@ private function extractNodeStyle(array $style): array // Extract fillColor. if (isset($style['fillColor']['_attributes']) === true) { - $fillColor = $style['fillColor']['_attributes']; - $rValue = 255; - if (isset($fillColor['r']) === true) { - } - - $gValue = 255; - if (isset($fillColor['g']) === true) { - } - - $bValue = 255; - if (isset($fillColor['b']) === true) { - } - - $aValue = 100; - if (isset($fillColor['a']) === true) { - } - + $fillColor = $style['fillColor']['_attributes']; $processedStyle['fillColor'] = [ - 'r' => $rValue, - 'g' => $gValue, - 'b' => $bValue, - 'a' => $aValue, + 'r' => (int) ($fillColor['r'] ?? 255), + 'g' => (int) ($fillColor['g'] ?? 255), + 'b' => (int) ($fillColor['b'] ?? 255), + 'a' => (int) ($fillColor['a'] ?? 100), ]; }//end if // Extract lineColor. if (isset($style['lineColor']['_attributes']) === true) { - $lineColor = $style['lineColor']['_attributes']; - $rValue = 0; - if (isset($lineColor['r']) === true) { - } - - $gValue = 0; - if (isset($lineColor['g']) === true) { - } - - $bValue = 0; - if (isset($lineColor['b']) === true) { - } - - $aValue = 100; - if (isset($lineColor['a']) === true) { - } - + $lineColor = $style['lineColor']['_attributes']; $processedStyle['lineColor'] = [ - 'r' => $rValue, - 'g' => $gValue, - 'b' => $bValue, - 'a' => $aValue, + 'r' => (int) ($lineColor['r'] ?? 0), + 'g' => (int) ($lineColor['g'] ?? 0), + 'b' => (int) ($lineColor['b'] ?? 0), + 'a' => (int) ($lineColor['a'] ?? 100), ]; }//end if @@ -3699,23 +3594,11 @@ private function extractNodeStyle(array $style): array } if (isset($style['font']['color']['_attributes']) === true) { - $fontColor = $style['font']['color']['_attributes']; - $rValue = 0; - if (isset($fontColor['r']) === true) { - } - - $gValue = 0; - if (isset($fontColor['g']) === true) { - } - - $bValue = 0; - if (isset($fontColor['b']) === true) { - } - + $fontColor = $style['font']['color']['_attributes']; $font['color'] = [ - 'r' => $rValue, - 'g' => $gValue, - 'b' => $bValue, + 'r' => (int) ($fontColor['r'] ?? 0), + 'g' => (int) ($fontColor['g'] ?? 0), + 'b' => (int) ($fontColor['b'] ?? 0), ]; }//end if @@ -3740,23 +3623,11 @@ private function extractConnectionStyle(array $style): array // Extract lineColor. if (isset($style['lineColor']['_attributes']) === true) { - $lineColor = $style['lineColor']['_attributes']; - $rValue = 0; - if (isset($lineColor['r']) === true) { - } - - $gValue = 0; - if (isset($lineColor['g']) === true) { - } - - $bValue = 0; - if (isset($lineColor['b']) === true) { - } - + $lineColor = $style['lineColor']['_attributes']; $processedStyle['lineColor'] = [ - 'r' => $rValue, - 'g' => $gValue, - 'b' => $bValue, + 'r' => (int) ($lineColor['r'] ?? 0), + 'g' => (int) ($lineColor['g'] ?? 0), + 'b' => (int) ($lineColor['b'] ?? 0), ]; }//end if @@ -3773,23 +3644,11 @@ private function extractConnectionStyle(array $style): array } if (isset($style['font']['color']['_attributes']) === true) { - $fontColor = $style['font']['color']['_attributes']; - $rValue = 0; - if (isset($fontColor['r']) === true) { - } - - $gValue = 0; - if (isset($fontColor['g']) === true) { - } - - $bValue = 0; - if (isset($fontColor['b']) === true) { - } - + $fontColor = $style['font']['color']['_attributes']; $font['color'] = [ - 'r' => $rValue, - 'g' => $gValue, - 'b' => $bValue, + 'r' => (int) ($fontColor['r'] ?? 0), + 'g' => (int) ($fontColor['g'] ?? 0), + 'b' => (int) ($fontColor['b'] ?? 0), ]; }//end if @@ -3839,8 +3698,9 @@ private function extractGemmaType(array $object): ?string if (isset($object[$propertyName]) === true && empty($object[$propertyName]) === false) { $rawValue = $object[$propertyName]; // Handle case where value might be an array (e.g., from XML parsing with _value key). - $value = (string) $rawValue; + $value = (string) $rawValue; if (is_array($rawValue) === true) { + $value = (string) ($rawValue['_value'] ?? $rawValue[0] ?? ''); } // Log the first successful match for debugging. @@ -4243,11 +4103,13 @@ private function extractRelationshipEndpoint(array $relationship, string $endpoi // Handle different XML structures. if (is_string($endpointData) === true) { + return $endpointData; } if (is_array($endpointData) === true) { // Try _attributes.href or _value. if (isset($endpointData['_attributes']['href']) === true) { + return $endpointData['_attributes']['href']; } if (isset($endpointData['_value']) === true) { @@ -4260,6 +4122,7 @@ private function extractRelationshipEndpoint(array $relationship, string $endpoi if (isset($relationship['xml']['_attributes']) === true) { $attr = $relationship['xml']['_attributes']; if ($endpoint === 'source' && isset($attr['source']) === true) { + return $attr['source']; } if ($endpoint === 'target' && isset($attr['target']) === true) { @@ -4664,8 +4527,9 @@ private function buildElementsLookupFromRawData( // Fast properties flattening (only essential properties for splicing). if (isset($rawItem['properties']['property']) === true && empty($propDefMap) === false) { - $props = [$rawItem['properties']['property']]; + $props = [$rawItem['properties']['property']]; if (isset($rawItem['properties']['property'][0]) === true) { + $props = $rawItem['properties']['property']; } foreach ($props as $prop) { @@ -4859,8 +4723,9 @@ private function transformSectionObjectsBatch( ]; // Debug: Log XML data extraction. - $propsStructVal = null; + $propsStructVal = null; if (isset($item['properties']) === true) { + $propsStructVal = array_keys($item['properties']); } $this->logger->debug( @@ -4946,20 +4811,24 @@ private function transformSectionObjectsBatch( } // DEBUG: Log final object structure before adding to array. - $xmlKeysValue = null; + $xmlKeysValue = null; if (isset($object['xml']) === true) { + $xmlKeysValue = array_keys($object['xml']); } - $propMapCountVal = 0; + $propMapCountVal = 0; if (isset($object['_propertyMapping']) === true) { + $propMapCountVal = count($object['_propertyMapping']); } - $viewNodesCountValue = 0; + $viewNodesCountValue = 0; if (isset($object['viewNodes']) === true) { + $viewNodesCountValue = count($object['viewNodes']); } - $viewRelCountVal = 0; + $viewRelCountVal = 0; if (isset($object['viewRelationships']) === true) { + $viewRelCountVal = count($object['viewRelationships']); } $this->logger->debug( @@ -5016,9 +4885,10 @@ private function findItemsSimplified(array $sectionData, string $sectionType): a if ($sectionType === 'view' && isset($sectionData['diagrams']['view']) === true) { $viewData = $sectionData['diagrams']['view']; if (isset($viewData[0]) === true) { + return $viewData; } - return [$viewData]; + return [$viewData]; } // Try common patterns: Singular, plural, item, propertyDefinition. @@ -5033,9 +4903,10 @@ private function findItemsSimplified(array $sectionData, string $sectionType): a if (isset($sectionData[$pattern]) === true) { $data = $sectionData[$pattern]; if (is_array($data) === true && isset($data[0]) === true) { + return $data; } - return [$data]; + return [$data]; } } @@ -5054,8 +4925,9 @@ private function findItemsSimplified(array $sectionData, string $sectionType): a */ private function flattenPropertiesBatch(array &$object, array $properties, array $propDefMap): void { - $props = [$properties]; + $props = [$properties]; if (isset($properties[0]) === true) { + $props = $properties; } $processedProperties = []; @@ -5981,8 +5853,9 @@ private function extractDetailedErrors(array $statistics): array // Group errors by type/message for better presentation. $errorGroups = []; foreach ($sectionErrors as $error) { - $errorMessage = ($error['message'] ?? 'Unknown error'); + $errorMessage = ($error['message'] ?? 'Unknown error'); if (is_string($error) === true) { + $errorMessage = $error; } $errorType = $this->categorizeError(errorMessage: $errorMessage); diff --git a/lib/Service/ArchiMateService.php b/lib/Service/ArchiMateService.php index f92faa00..24a4a120 100644 --- a/lib/Service/ArchiMateService.php +++ b/lib/Service/ArchiMateService.php @@ -321,14 +321,9 @@ public function exportOrgArchiMate(string $organizationUuid, array $options=[]): } // Look up the organization from Voorzieningen register. - $voorzConfig = $this->settingsService->getVoorzieningenConfig(); - $orgRegisterId = null; - if (empty($voorzConfig['register']) === false) { - } - - $orgSchemaId = null; - if (empty($voorzConfig['organisatie_schema']) === false) { - } + $voorzConfig = $this->settingsService->getVoorzieningenConfig(); + $orgRegisterId = (empty($voorzConfig['register']) === false) ? $voorzConfig['register'] : null; + $orgSchemaId = (empty($voorzConfig['organisatie_schema']) === false) ? $voorzConfig['organisatie_schema'] : null; if ($orgRegisterId === null || $orgSchemaId === false) { // Fallback to generic lookup. @@ -372,9 +367,7 @@ public function exportOrgArchiMate(string $organizationUuid, array $options=[]): $schemaIdMap = $this->createSchemaIdMap(); // Query organization's gebruik and modules from Voorzieningen register. - $gebruikSchemaId = null; - if (empty($voorzConfig['gebruik_schema']) === false) { - } + $gebruikSchemaId = (empty($voorzConfig['gebruik_schema']) === false) ? $voorzConfig['gebruik_schema'] : null; $gebruikData = []; if (empty($gebruikSchemaId) === false) { @@ -389,9 +382,7 @@ public function exportOrgArchiMate(string $organizationUuid, array $options=[]): $gebruikData = $objectService->searchObjects(query: $gebruikQuery, _rbac: false, _multitenancy: false); } - $moduleSchemaId = null; - if (empty($voorzConfig['module_schema']) === false) { - } + $moduleSchemaId = (empty($voorzConfig['module_schema']) === false) ? $voorzConfig['module_schema'] : null; $modulesData = []; if (empty($moduleSchemaId) === false) { @@ -449,9 +440,7 @@ public function exportOrgArchiMate(string $organizationUuid, array $options=[]): // Merge into modulesData, deduplicating by ID. $existingIds = []; foreach ($modulesData as $m) { - $mid = null; - if (is_array($m) === true) { - } + $mid = is_array($m) === true ? ($m['id'] ?? $m['@self']['id'] ?? null) : null; if (empty($mid) === false) { $existingIds[$mid] = true; @@ -459,9 +448,9 @@ public function exportOrgArchiMate(string $organizationUuid, array $options=[]): } foreach ($allModules as $mod) { - $modArr = $mod; - if ((is_object($mod) === true && method_exists($mod, 'jsonSerialize') === true)) { - } + $modArr = (is_object($mod) === true && method_exists($mod, 'jsonSerialize') === true) + ? $mod->jsonSerialize() + : $mod; $modId = $modArr['id'] ?? $modArr['@self']['id'] ?? null; if ($modId !== false && isset($existingIds[$modId]) === false) { @@ -769,11 +758,13 @@ private function extractIdentifierByPattern(array $item, array $pattern): ?strin switch ($type) { case 'direct': if (is_string($current) === true) { + return $current; } return null; case 'value': if (is_array($current) === true && isset($current['_value']) === true) { + return $current['_value']; } return null; @@ -1105,9 +1096,7 @@ private function saveObjectsInParallelBatches(array $objects, ObjectService $obj foreach ($chunks as $chunkIndex => $chunk) { // OPTIMIZATION: Removed debug logging from chunk processing loop. try { - $rbacValue = true; - if (self::PERFORMANCE_OPTIMIZATIONS['disable_rbac'] === true) { - } + $rbacValue = (self::PERFORMANCE_OPTIMIZATIONS['disable_rbac'] === true) ? false : true; $saveResult = $objectService->saveObjects( objects: $chunk, @@ -1197,9 +1186,7 @@ private function saveObjectsInSingleBatch(array $objects, ObjectService $objectS ] ); - $rbacValue = true; - if (self::PERFORMANCE_OPTIMIZATIONS['disable_rbac'] === true) { - } + $rbacValue = (self::PERFORMANCE_OPTIMIZATIONS['disable_rbac'] === true) ? false : true; $saveResult = $objectService->saveObjects( objects: $objects, @@ -1765,8 +1752,10 @@ private function getAmefRegisterId(): ?int // Fallback to legacy individual app config keys if not present in JSON. if ($rawRegisterId === null || $rawRegisterId === '') { - $rawRegisterId = $this->config->getValueString('softwarecatalog', 'amef_register_id', ''); + $rawRegisterId = $this->config->getValueString('softwarecatalog', 'amef_register_id', ''); if ($this->config->getValueString('softwarecatalog', 'amef_register', '') !== '') { + // If only the plain register key is configured, use it as the ID. + $rawRegisterId = $this->config->getValueString('softwarecatalog', 'amef_register', ''); } } @@ -1774,9 +1763,8 @@ private function getAmefRegisterId(): ?int if ($rawRegisterId !== null && $rawRegisterId !== '' && is_numeric((string) $rawRegisterId) === true) { $registerId = (int) $rawRegisterId; if ($registerId > 0) { + return $registerId; } - - return null; } return null; @@ -1913,15 +1901,17 @@ private function getObjectsWithPagination(string $schemaType, array $query=[]): $isAmefType = in_array($schemaType, $amefObjectTypes, true) === true; // Use AMEF register ID for AMEF types, otherwise use per-type register ID. - $registerId = $this->settingsService->getRegisterIdForObjectType($schemaType); + $registerId = $this->settingsService->getRegisterIdForObjectType($schemaType); if ($isAmefType === true) { + $registerId = $this->settingsService->getAmefRegisterId(); } $schemaId = $this->settingsService->getSchemaIdForObjectType($schemaType); if ($registerId === null || $schemaId === false) { - $errorMessage = "ArchiMateService: Register or {$schemaType} schema not configured"; + $errorMessage = "ArchiMateService: Register or {$schemaType} schema not configured"; if ($isAmefType === true) { + $errorMessage = "ArchiMateService: AMEF register or {$schemaType} schema not configured"; } $this->logger->error( @@ -1964,8 +1954,9 @@ private function getObjectsWithPagination(string $schemaType, array $query=[]): ]; } - $paginationValue = 'disabled'; + $paginationValue = 'disabled'; if ($usePagination === true) { + $paginationValue = 'enabled'; } $this->logger->debug( @@ -1981,8 +1972,9 @@ private function getObjectsWithPagination(string $schemaType, array $query=[]): // Use searchObjects method for filtering. $objects = $objectService->searchObjects($finalQuery); - $paginationValue = 'disabled'; + $paginationValue = 'disabled'; if ($usePagination === true) { + $paginationValue = 'enabled'; } $this->logger->debug( @@ -2629,9 +2621,10 @@ private function findItemsSimplified(array $sectionData, string $sectionType): a if ($sectionType === 'view' && isset($sectionData['diagrams']['view']) === true) { $viewData = $sectionData['diagrams']['view']; if (isset($viewData[0]) === true) { + return $viewData; } - return [$viewData]; + return [$viewData]; } // Try common patterns. @@ -2650,9 +2643,10 @@ private function findItemsSimplified(array $sectionData, string $sectionType): a if (isset($sectionData[$pattern]) === true) { $data = $sectionData[$pattern]; if (is_array($data) === true && isset($data[0]) === true) { + return $data; } - return [$data]; + return [$data]; } } @@ -2671,8 +2665,9 @@ private function findItemsSimplified(array $sectionData, string $sectionType): a */ private function flattenPropertiesBatch(array &$object, array $properties, array $propDefMap): void { - $props = [$properties]; + $props = [$properties]; if (isset($properties[0]) === true) { + $props = $properties; } $processedProperties = []; @@ -3112,11 +3107,13 @@ private function extractRelationshipEndpoint(array $relationship, string $endpoi // Handle different XML structures. if (is_string($endpointData) === true) { + return $endpointData; } if (is_array($endpointData) === true) { // Try _attributes.href or _value. if (isset($endpointData['_attributes']['href']) === true) { + return $endpointData['_attributes']['href']; } if (isset($endpointData['_value']) === true) { @@ -3129,6 +3126,7 @@ private function extractRelationshipEndpoint(array $relationship, string $endpoi if (isset($relationship['xml']['_attributes']) === true) { $attr = $relationship['xml']['_attributes']; if ($endpoint === 'source' && isset($attr['source']) === true) { + return $attr['source']; } if ($endpoint === 'target' && isset($attr['target']) === true) {