| Conditions | 10 |
| Paths | 66 |
| Total Lines | 69 |
| Code Lines | 50 |
| 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 |
||
| 45 | public function renderPageModulePreviewContent(GridColumnItem $item): string |
||
| 46 | { |
||
| 47 | $row = $item->getRecord(); |
||
| 48 | $itemContent = $this->linkEditContent('<strong>' . htmlspecialchars($item->getContext()->getContentTypeLabels()['form_formframework']) . '</strong>', $row) . '<br />'; |
||
| 49 | |||
| 50 | $flexFormData = GeneralUtility::makeInstance(FlexFormService::class) |
||
| 51 | ->convertFlexFormContentToArray($row['pi_flexform']); |
||
| 52 | |||
| 53 | $persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier']; |
||
| 54 | if (!empty($persistenceIdentifier)) { |
||
| 55 | try { |
||
| 56 | $formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class); |
||
| 57 | |||
| 58 | try { |
||
| 59 | if ( |
||
| 60 | StringUtility::endsWith($persistenceIdentifier, FormPersistenceManager::FORM_DEFINITION_FILE_EXTENSION) |
||
| 61 | || strpos($persistenceIdentifier, 'EXT:') === 0 |
||
| 62 | ) { |
||
| 63 | $formDefinition = $formPersistenceManager->load($persistenceIdentifier); |
||
| 64 | $formLabel = $formDefinition['label']; |
||
| 65 | } else { |
||
| 66 | $formLabel = sprintf( |
||
| 67 | $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'), |
||
| 68 | $persistenceIdentifier |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | } catch (ParseErrorException $e) { |
||
| 72 | $formLabel = sprintf( |
||
| 73 | $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidPersistenceIdentifier'), |
||
| 74 | $persistenceIdentifier |
||
| 75 | ); |
||
| 76 | } catch (PersistenceManagerException $e) { |
||
| 77 | $formLabel = sprintf( |
||
| 78 | $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'), |
||
| 79 | $persistenceIdentifier |
||
| 80 | ); |
||
| 81 | } catch (Exception $e) { |
||
| 82 | $formLabel = sprintf( |
||
| 83 | $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'), |
||
| 84 | $persistenceIdentifier |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | } catch (NoSuchFileException $e) { |
||
| 88 | $this->addInvalidFrameworkConfigurationFlashMessage($e); |
||
| 89 | $formLabel = sprintf( |
||
| 90 | $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'), |
||
| 91 | $persistenceIdentifier |
||
| 92 | ); |
||
| 93 | } catch (ParseErrorException $e) { |
||
| 94 | $this->addInvalidFrameworkConfigurationFlashMessage($e); |
||
| 95 | $formLabel = sprintf( |
||
| 96 | $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration'), |
||
| 97 | $persistenceIdentifier |
||
| 98 | ); |
||
| 99 | } catch (\Exception $e) { |
||
| 100 | // Top level catch - FAL throws top level exceptions on missing files, eg. in getFileInfoByIdentifier() of LocalDriver |
||
| 101 | $this->addInvalidFrameworkConfigurationFlashMessage($e); |
||
| 102 | $formLabel = $e->getMessage(); |
||
| 103 | } |
||
| 104 | } else { |
||
| 105 | $formLabel = $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.noPersistenceIdentifier'); |
||
| 106 | } |
||
| 107 | |||
| 108 | $itemContent .= $this->linkEditContent( |
||
| 109 | htmlspecialchars($formLabel), |
||
| 110 | $row |
||
| 111 | ) . '<br />'; |
||
| 112 | |||
| 113 | return $itemContent; |
||
| 114 | } |
||
| 147 |