| Conditions | 6 |
| Paths | 10 |
| Total Lines | 55 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 100 | public function getTransformedOutputXML($document, $xmlData = false) |
||
| 101 | { |
||
| 102 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class); |
||
| 103 | $this->clientConfigurationManager = $objectManager->get(ClientConfigurationManager::class); |
||
| 104 | |||
| 105 | $ownerId = $this->clientConfigurationManager->getOwnerId(); |
||
| 106 | $documentType = $document->getDocumentType(); |
||
| 107 | |||
| 108 | $transformationFile = $documentType->getTransformationFileOutput()->toArray()[0]; |
||
| 109 | if (!$transformationFile) { |
||
| 110 | $transformationFile = $this->clientConfigurationManager->getOutputTransformation(); |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($transformationFile != NULL) { |
||
| 114 | $filePath = $transformationFile->getFile()->getOriginalResource()->getIdentifier(); |
||
| 115 | $documentTransformer = new DocumentTransformer(); |
||
| 116 | |||
| 117 | if ( !$document->getRemoteState() || $document->getRemoteState() == 'NONE' ) { |
||
| 118 | $remoteState = 'ACTIVE'; |
||
| 119 | } else { |
||
| 120 | $remoteState = $document->getRemoteState(); |
||
| 121 | } |
||
| 122 | |||
| 123 | $transformParams = [ |
||
| 124 | 'record_state' => $remoteState, |
||
| 125 | 'agent_name' => $ownerId, |
||
| 126 | 'document_type' => $document->getDocumentType()->getName(), |
||
| 127 | 'process_number' => $document->getProcessNumber() |
||
| 128 | ]; |
||
| 129 | |||
| 130 | if ($xmlData) { |
||
| 131 | $transformedXml = $documentTransformer->transform(PATH_site . 'fileadmin' . $filePath, $xmlData, $transformParams); |
||
| 132 | } else { |
||
| 133 | $transformedXml = $documentTransformer->transform(PATH_site . 'fileadmin' . $filePath, $document->getXmlData(), $transformParams); |
||
| 134 | } |
||
| 135 | |||
| 136 | } else { |
||
| 137 | // return generated xml if no transformation file is present |
||
| 138 | $transformedXml = $document->getXmlData(); |
||
| 139 | |||
| 140 | /** @var $logger Logger */ |
||
| 141 | $logger = GeneralUtility::makeInstance( |
||
| 142 | LogManager::class)->getLogger(__CLASS__ |
||
| 143 | ); |
||
| 144 | |||
| 145 | $logger->log( |
||
| 146 | LogLevel::WARNING, |
||
| 147 | "Output XML: No transformation file is present. The generated xml data was taken over as it is", |
||
| 148 | array( |
||
| 149 | 'documentTypeName' => $documentTypeName |
||
|
|
|||
| 150 | ) |
||
| 151 | ); |
||
| 152 | } |
||
| 153 | |||
| 154 | return $transformedXml; |
||
| 155 | } |
||
| 158 |