| Conditions | 1 |
| Paths | 1 |
| Total Lines | 60 |
| Code Lines | 37 |
| 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 |
||
| 70 | public function getReportField() |
||
| 71 | { |
||
| 72 | Requirements::css('bringyourownideas/silverstripe-maintenance: css/sitesummary.css'); |
||
| 73 | |||
| 74 | /** @var GridField $grid */ |
||
| 75 | $grid = parent::getReportField(); |
||
| 76 | |||
| 77 | /** @var GridFieldConfig $config */ |
||
| 78 | $config = $grid->getConfig(); |
||
| 79 | |||
| 80 | $grid->addExtraClass('package-summary'); |
||
| 81 | |||
| 82 | /** @var GridFieldExportButton $exportButton */ |
||
| 83 | $exportButton = $config->getComponentByType(GridFieldExportButton::class); |
||
| 84 | $exportButton->setExportColumns(Package::create()->summaryFields()); |
||
| 85 | |||
| 86 | $versionHtml = ArrayData::create([ |
||
| 87 | 'Title' => _t(__CLASS__ . '.VERSION', 'Version'), |
||
| 88 | 'Version' => $this->resolveCmsVersion(), |
||
| 89 | ])->renderWith('SiteSummary_VersionHeader'); |
||
| 90 | |||
| 91 | /** @var GridFieldDropdownFilter $dropdownFilter */ |
||
| 92 | $dropdownFilter = Injector::inst()->create( |
||
| 93 | GridFieldDropdownFilter::class, |
||
| 94 | 'addonFilter', |
||
| 95 | 'buttons-before-right', |
||
| 96 | _t(__CLASS__ . '.ShowAllModules', 'Show all modules') |
||
| 97 | ); |
||
| 98 | |||
| 99 | $dropdownFilter->addFilterOption( |
||
| 100 | 'supported', |
||
| 101 | _t(__CLASS__ . '.FilterSupported', 'Supported modules'), |
||
| 102 | ['Supported' => true] |
||
| 103 | ); |
||
| 104 | $dropdownFilter->addFilterOption( |
||
| 105 | 'unsupported', |
||
| 106 | _t(__CLASS__ . '.FilterUnsupported', 'Unsupported modules'), |
||
| 107 | ['Supported' => false] |
||
| 108 | ); |
||
| 109 | |||
| 110 | $this->extend('updateDropdownFilterOptions', $dropdownFilter); |
||
| 111 | |||
| 112 | $config->addComponents( |
||
| 113 | Injector::inst()->create(GridFieldRefreshButton::class, 'buttons-before-left'), |
||
| 114 | Injector::inst()->create( |
||
| 115 | GridFieldLinkButton::class, |
||
| 116 | 'https://addons.silverstripe.org', |
||
| 117 | _t(__CLASS__ . '.LINK_TO_ADDONS', 'Explore Addons'), |
||
| 118 | 'buttons-before-left' |
||
| 119 | ), |
||
| 120 | $dropdownFilter, |
||
| 121 | Injector::inst()->create(GridFieldHtmlFragment::class, 'header', $versionHtml) |
||
| 122 | ); |
||
| 123 | |||
| 124 | // Re-order the paginator to ensure it counts correctly. |
||
| 125 | $paginator = $config->getComponentByType(GridFieldPaginator::class); |
||
| 126 | $config->removeComponent($paginator); |
||
| 127 | $config->addComponent($paginator); |
||
| 128 | |||
| 129 | return $grid; |
||
| 130 | } |
||
| 162 |