We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 6 |
| Paths | 20 |
| Total Lines | 51 |
| Code Lines | 26 |
| 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 |
||
| 34 | public static function renderStatic( |
||
| 35 | array $arguments, |
||
| 36 | \Closure $renderChildrenClosure, |
||
| 37 | RenderingContextInterface $renderingContext |
||
| 38 | ) { |
||
| 39 | $id = $arguments['id']; |
||
| 40 | $inputSettings = $arguments['settings']; |
||
| 41 | |||
| 42 | // Whitelist keys to keep out stuff such as playerTranslations |
||
| 43 | $allowedKeys = ['shareButtons', 'screenshotCaptions', 'constants', 'equalizer']; |
||
| 44 | $result = array_intersect_key($inputSettings, array_flip($allowedKeys)); |
||
| 45 | |||
| 46 | // Add translations |
||
| 47 | $translationBaseFiles = $inputSettings['playerTranslations']['baseFile'] ?? 'EXT:dlf/Resources/Private/Language/locallang_media.xlf'; |
||
| 48 | if (!is_array($translationBaseFiles)) { |
||
| 49 | $translationBaseFiles = [$translationBaseFiles]; |
||
| 50 | } |
||
| 51 | $result['lang'] = self::getTranslations($translationBaseFiles); |
||
| 52 | |||
| 53 | // Resolve paths |
||
| 54 | foreach ($result['shareButtons'] ?? [] as $key => $button) { |
||
| 55 | // For Flexforms-configured button |
||
| 56 | if (isset($button['singleButton'])) { |
||
| 57 | $button = $button['singleButton']; |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($button['type'] === 'image') { |
||
| 61 | $filePath = GeneralUtility::getFileAbsFileName($button['src']); |
||
| 62 | $webPath = PathUtility::getAbsoluteWebPath($filePath); |
||
| 63 | |||
| 64 | $button['src'] = $webPath; |
||
| 65 | } |
||
| 66 | |||
| 67 | $result['shareButtons'][$key] = $button; |
||
| 68 | } |
||
| 69 | |||
| 70 | // Allow using (and overriding) non-numeric keys for shareButtons |
||
| 71 | $result['shareButtons'] = array_values($result['shareButtons'] ?? []); |
||
| 72 | |||
| 73 | // Equalizer configuration |
||
| 74 | foreach ($result['equalizer']['presets'] ?? [] as $key => &$preset) { |
||
|
|
|||
| 75 | $result['equalizer']['presets'][$key]['key'] = $key; |
||
| 76 | } |
||
| 77 | $result['equalizer']['presets'] = array_values($result['equalizer']['presets'] ?? []); |
||
| 78 | |||
| 79 | $idJson = json_encode($id); |
||
| 80 | $resultJson = json_encode($result); |
||
| 81 | |||
| 82 | return <<<CONFIG |
||
| 83 | <script> |
||
| 84 | window[$idJson] = $resultJson; |
||
| 85 | </script> |
||
| 132 |
Let?s assume that you have the following
foreachstatement:$itemValueis assigned by reference. This is possible because the expression (in the example$array) can be used as a reference target.However, if we were to replace
$arraywith something different like the result of a function call as inthen assigning by reference is not possible anymore as there is no target that could be modified.
Available Fixes
1. Do not assign by reference
2. Assign to a local variable first
3. Return a reference