| Conditions | 10 |
| Paths | 30 |
| Total Lines | 45 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 42 | public function resolveRendererFor(string $table, array $row, int $pageUid): PreviewRendererInterface |
||
| 43 | { |
||
| 44 | $tca = $GLOBALS['TCA'][$table]; |
||
| 45 | $tcaTypeField = $tca['ctrl']['type'] ?? null; |
||
| 46 | $previewRendererClassName = null; |
||
| 47 | if ($tcaTypeField) { |
||
| 48 | $tcaTypeOfRow = $row[$tcaTypeField]; |
||
| 49 | $typeConfiguration = $tca['types'][$tcaTypeOfRow] ?? []; |
||
| 50 | |||
| 51 | $subTypeValueField = $typeConfiguration['subtype_value_field'] ?? null; |
||
| 52 | if (!empty($subTypeValueField) && !empty($typeConfiguration['previewRenderer']) && is_array($typeConfiguration['previewRenderer'])) { |
||
| 53 | // An array of subtype_value_field indexed preview renderers was defined, look up the right |
||
| 54 | // class to use for the sub-type defined in this $row. |
||
| 55 | $previewRendererClassName = $typeConfiguration['previewRenderer'][$row[$subTypeValueField]] ?? null; |
||
| 56 | } |
||
| 57 | |||
| 58 | // If no class was found in the subtype_value_field |
||
| 59 | if (!$previewRendererClassName && !empty($typeConfiguration['previewRenderer'])) { |
||
| 60 | // A type-specific preview renderer was configured for the TCA type (and one was not detected |
||
| 61 | // based on the higher-priority lookups above). |
||
| 62 | $previewRendererClassName = $typeConfiguration['previewRenderer']; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | if (!$previewRendererClassName) { |
||
|
|
|||
| 67 | |||
| 68 | // Table either has no type field or no custom preview renderer was defined for the type. |
||
| 69 | // Use table's standard renderer if any is defined. |
||
| 70 | $previewRendererClassName = $tca['ctrl']['previewRenderer'] ?? null; |
||
| 71 | } |
||
| 72 | |||
| 73 | if (!empty($previewRendererClassName)) { |
||
| 74 | if (!is_a($previewRendererClassName, PreviewRendererInterface::class, true)) { |
||
| 75 | throw new \UnexpectedValueException( |
||
| 76 | sprintf( |
||
| 77 | 'Class %s must implement %s', |
||
| 78 | $previewRendererClassName, |
||
| 79 | PreviewRendererInterface::class |
||
| 80 | ), |
||
| 81 | 1477512798 |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | return GeneralUtility::makeInstance($previewRendererClassName); |
||
| 85 | } |
||
| 86 | throw new \RuntimeException(sprintf('No Preview renderer registered for table %s', $table), 1477520356); |
||
| 87 | } |
||
| 89 |