Skip to content

Commit 88eb487

Browse files
committed
fix: Resolve all PHPCS errors across ArchiMate services
Auto-fixed remaining formatting violations in ArchiMateImportService, ArchiMateExportService, and ArchiMateService. 0 errors remain.
1 parent 3d2c9b0 commit 88eb487

3 files changed

Lines changed: 246 additions & 70 deletions

File tree

lib/Service/ArchiMateExportService.php

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public function arrayToXml(array $data, \SimpleXMLElement $xml): \SimpleXMLEleme
6565
// Skip legacy _attributes bag, handle individual underscored keys as attributes.
6666
$attrKey = substr($key, 1);
6767

68-
// Skip malformed attribute keys that would create invalid XML (e.g., __propertyDefinitionRef -> :propertyDefinitionRef).
68+
// Skip malformed attribute keys that would create invalid XML
69+
// (e.g., __propertyDefinitionRef -> :propertyDefinitionRef).
6970
if (str_starts_with($attrKey, '__') === true || $attrKey === '') {
7071
continue;
7172
}
@@ -168,7 +169,8 @@ public function arrayToXml(array $data, \SimpleXMLElement $xml): \SimpleXMLEleme
168169
}
169170

170171
// Special handling for elementProperties and other nested structures - filter out problematic fields.
171-
if (($key === 'elementProperties' || $key === 'properties' || $key === 'viewNodes') && is_array($value) === true) {
172+
$nestedKeys = ['elementProperties', 'properties', 'viewNodes'];
173+
if (in_array($key, $nestedKeys, true) === true && is_array($value) === true) {
172174
$value = $this->filterProblematicFields(data: $value, fieldsToRemove: $propertyLikeFields);
173175
}
174176

@@ -330,15 +332,18 @@ private function getNamespaceUri(\SimpleXMLElement $xml, string $prefix): string
330332
*/
331333
public function createCleanArchiMateXml(array $modelMetadata): \SimpleXMLElement
332334
{
333-
$modelName = $modelMetadata['name'] ?? 'ArchiMate Model';
334-
$modelId = $modelMetadata['identifier'] ?? 'model-'.uniqid();
335+
$modelName = $modelMetadata['name'] ?? 'ArchiMate Model';
336+
$modelId = $modelMetadata['identifier'] ?? 'model-'.uniqid();
337+
$schemaBase = 'http://www.opengroup.org/xsd/archimate/3.0/';
338+
$schemaXsd = 'http://www.opengroup.org/xsd/archimate/3.1/archimate3_Diagram.xsd';
339+
$schemaLoc = $schemaBase.' '.$schemaXsd;
335340

336341
$xmlString = <<<XML
337342
<?xml version="1.0" encoding="UTF-8"?>
338-
<model xmlns="http://www.opengroup.org/xsd/archimate/3.0/"
343+
<model xmlns="http://www.opengroup.org/xsd/archimate/3.0/"
339344
xmlns:xml="http://www.w3.org/XML/1998/namespace"
340-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
341-
xsi:schemaLocation="http://www.opengroup.org/xsd/archimate/3.0/ http://www.opengroup.org/xsd/archimate/3.1/archimate3_Diagram.xsd"
345+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
346+
xsi:schemaLocation="{$schemaLoc}"
342347
identifier="{$modelId}">
343348
</model>
344349
XML;
@@ -505,7 +510,8 @@ private function addViewToFolder(\SimpleXMLElement $folder, array $view): void
505510
}
506511

507512
// DEBUG: Check if this is our target view with nodes.
508-
if (isset($viewData['_identifier']) === true && $viewData['_identifier'] === 'id-1c197dc3-71e5-40dc-8f5d-a96e983b41af') {
513+
$targetId = 'id-1c197dc3-71e5-40dc-8f5d-a96e983b41af';
514+
if (isset($viewData['_identifier']) === true && $viewData['_identifier'] === $targetId) {
509515
if (is_array($viewData['node'] ?? null) === true) {
510516
$nodeCountValue = count($viewData['node']);
511517
} else {
@@ -747,8 +753,11 @@ private function addObjectToFolder(\SimpleXMLElement $folder, array $object, str
747753
*
748754
* @throws \RuntimeException If retrieval fails.
749755
*/
750-
public function getObjectsFromDatabase(\OCA\OpenRegister\Service\ObjectService $objectService, int $registerId, array $schemaIdMap=[]): array
751-
{
756+
public function getObjectsFromDatabase(
757+
\OCA\OpenRegister\Service\ObjectService $objectService,
758+
int $registerId,
759+
array $schemaIdMap=[]
760+
): array {
752761
$this->logger->info(
753762
'Retrieving all objects from AMEF register',
754763
[
@@ -903,7 +912,11 @@ public function exportArchiMateXml(
903912
);
904913

905914
// Step 1: Get all objects from database (queries each schema separately for magic table support).
906-
$objects = $this->getObjectsFromDatabase(objectService: $objectService, registerId: $registerId, schemaIdMap: $schemaIdMap);
915+
$objects = $this->getObjectsFromDatabase(
916+
objectService: $objectService,
917+
registerId: $registerId,
918+
schemaIdMap: $schemaIdMap
919+
);
907920
$dbTime = microtime(true) - $startTime;
908921

909922
// Step 2: Process and generate XML in single optimized pass (no schema mapping needed).
@@ -1201,7 +1214,8 @@ private function addViewDataToXmlNode(\SimpleXMLElement $viewNode, array $viewDa
12011214
// Add xsi:type if present.
12021215
foreach (['_xsi__type', 'xsi:type', '_xsi:type'] as $typeKey) {
12031216
if (isset($viewData[$typeKey]) === true) {
1204-
$viewNode->addAttribute('xsi:type', (string) $viewData[$typeKey], 'http://www.w3.org/2001/XMLSchema-instance');
1217+
$xsiNs = 'http://www.w3.org/2001/XMLSchema-instance';
1218+
$viewNode->addAttribute('xsi:type', (string) $viewData[$typeKey], $xsiNs);
12051219
break;
12061220
}
12071221
}
@@ -1514,8 +1528,12 @@ private function cleanObjectDataForXml(array $object, array $propertyDefinitionM
15141528
*
15151529
* @return void
15161530
*/
1517-
private function addCleanDataToXmlNode(\SimpleXMLElement $node, array $data, ?string $sectionName=null, array $propertyDefinitionMap=[]): void
1518-
{
1531+
private function addCleanDataToXmlNode(
1532+
\SimpleXMLElement $node,
1533+
array $data,
1534+
?string $sectionName=null,
1535+
array $propertyDefinitionMap=[]
1536+
): void {
15191537
// Extract attributes from various possible locations.
15201538
$attributes = [];
15211539
if (isset($data['identifier']) === true) {
@@ -1536,7 +1554,11 @@ private function addCleanDataToXmlNode(\SimpleXMLElement $node, array $data, ?st
15361554
} else {
15371555
$attributes['xsi:type'] = (string) $attrValue;
15381556
}
1539-
} else if (in_array($attrKey, ['identifier', 'source', 'target', 'accessType', 'isDirected', 'type']) === true) {
1557+
} else if (in_array(
1558+
$attrKey,
1559+
['identifier', 'source', 'target', 'accessType', 'isDirected', 'type']
1560+
) === true
1561+
) {
15401562
if ($attrKey === 'type' && $isPropertyDefinition === false) {
15411563
$attributes['xsi:type'] = (string) $attrValue;
15421564
} else {
@@ -1731,15 +1753,16 @@ private function addPropertiesToXml(\SimpleXMLElement $node, array $properties):
17311753
// Add xml:lang if present in various forms (including double underscore from import service).
17321754
foreach (['xml:lang', '_xml:lang', '_xml__lang', 'xml_lang'] as $langKey) {
17331755
if (isset($property['value'][$langKey]) === true) {
1734-
$valueNode->addAttribute('xml:lang', $property['value'][$langKey], 'http://www.w3.org/XML/1998/namespace');
1756+
$xmlNs = 'http://www.w3.org/XML/1998/namespace';
1757+
$valueNode->addAttribute('xml:lang', $property['value'][$langKey], $xmlNs);
17351758
break;
17361759
}
17371760
}
17381761
} else {
17391762
// Simple string value.
17401763
$valueNode = $propertyNode->addChild('value');
17411764
$valueNode[0] = (string) $property['value'];
1742-
}
1765+
}//end if
17431766
}//end if
17441767
}//end foreach
17451768
}//end addPropertiesToXml()
@@ -2224,12 +2247,13 @@ private function validatePropertiesAreNotEmpty(\SimpleXMLElement $xml): void
22242247
// Check value element exists and has content.
22252248
$valueElements = $property->xpath('value');
22262249
if (empty($valueElements) === true) {
2227-
throw new \InvalidArgumentException("Property missing value element: ".(string) $attributes['propertyDefinitionRef']);
2250+
$propRef = (string) $attributes['propertyDefinitionRef'];
2251+
throw new \InvalidArgumentException("Property missing value element: $propRef");
22282252
}
22292253

22302254
$value = trim((string) $valueElements[0]);
22312255
if (empty($value) === true) {
2232-
throw new \InvalidArgumentException("Property has empty value: ".(string) $attributes['propertyDefinitionRef']);
2256+
throw new \InvalidArgumentException("Property has empty value: $propRef");
22332257
}
22342258
}
22352259

@@ -2365,7 +2389,11 @@ public function exportOrganizationArchiMateXml(
23652389
);
23662390

23672391
// Step 1: Get all base GEMMA objects.
2368-
$baseObjects = $this->getObjectsFromDatabase(objectService: $objectService, registerId: $registerId, schemaIdMap: $schemaIdMap);
2392+
$baseObjects = $this->getObjectsFromDatabase(
2393+
objectService: $objectService,
2394+
registerId: $registerId,
2395+
schemaIdMap: $schemaIdMap
2396+
);
23692397

23702398
// Step 2: Ensure Bron property definition.
23712399
$bronPropDefId = $this->ensureBronPropertyDefinition(baseObjects: $baseObjects);
@@ -2586,8 +2614,12 @@ private function ensureBronPropertyDefinition(array &$baseObjects): string
25862614
*
25872615
* @return array Array of element data arrays ready for XML generation.
25882616
*/
2589-
private function generateApplicationElements(array $moduleRefMap, array $moduleNameMap, string $bronPropDefId, string $prefix=''): array
2590-
{
2617+
private function generateApplicationElements(
2618+
array $moduleRefMap,
2619+
array $moduleNameMap,
2620+
string $bronPropDefId,
2621+
string $prefix=''
2622+
): array {
25912623
$elements = [];
25922624
if ($prefix !== '') {
25932625
$idPrefix = 'id-swc-'.$prefix.'-app-';
@@ -2621,8 +2653,11 @@ private function generateApplicationElements(array $moduleRefMap, array $moduleN
26212653
*
26222654
* @return array Array of relationship data arrays.
26232655
*/
2624-
private function generateSpecializationRelationships(array $moduleRefMap, string $bronPropDefId, string $prefix=''): array
2625-
{
2656+
private function generateSpecializationRelationships(
2657+
array $moduleRefMap,
2658+
string $bronPropDefId,
2659+
string $prefix=''
2660+
): array {
26262661
$relationships = [];
26272662
if ($prefix !== '') {
26282663
$appIdPrefix = 'id-swc-'.$prefix.'-app-';
@@ -2652,7 +2687,10 @@ private function generateSpecializationRelationships(array $moduleRefMap, string
26522687
}
26532688
}
26542689

2655-
$this->logger->debug('Generated specialization relationships', ['count' => count($relationships), 'prefix' => $prefix]);
2690+
$this->logger->debug(
2691+
'Generated specialization relationships',
2692+
['count' => count($relationships), 'prefix' => $prefix]
2693+
);
26562694
return $relationships;
26572695
}//end generateSpecializationRelationships()
26582696

@@ -2864,7 +2902,11 @@ private function injectApplicationNodesInView(array $viewData, array $refCompApp
28642902
}
28652903

28662904
$newConnections = [];
2867-
$viewData['node'] = $this->processNodesForInjection(nodes: $nodes, refCompApps: $refCompApps, newConnections: $newConnections);
2905+
$viewData['node'] = $this->processNodesForInjection(
2906+
nodes: $nodes,
2907+
refCompApps: $refCompApps,
2908+
newConnections: $newConnections
2909+
);
28682910

28692911
// Add connections to the view.
28702912
if (empty($newConnections) === false) {
@@ -2969,7 +3011,11 @@ private function processNodesForInjection(array $nodes, array $refCompApps, arra
29693011
$nestedNodes = [$nestedNodes];
29703012
}
29713013

2972-
$node['node'] = $this->processNodesForInjection(nodes: $nestedNodes, refCompApps: $refCompApps, newConnections: $newConnections);
3014+
$node['node'] = $this->processNodesForInjection(
3015+
nodes: $nestedNodes,
3016+
refCompApps: $refCompApps,
3017+
newConnections: $newConnections
3018+
);
29733019
}
29743020
}//end foreach
29753021

0 commit comments

Comments
 (0)