| Conditions | 5 |
| Paths | 2 |
| Total Lines | 92 |
| 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 |
||
| 64 | private function customiseFilters(GridFieldConfig $config): void |
||
| 65 | { |
||
| 66 | /** @var GridFieldDataColumns $gridFieldColumns */ |
||
| 67 | $gridFieldColumns = $config->getComponentByType(GridFieldDataColumns::class); |
||
| 68 | |||
| 69 | $gridFieldColumns->setDisplayFields([ |
||
| 70 | 'getImplementationSummary' => 'Type', |
||
| 71 | 'JobTypeString' => 'Queue', |
||
| 72 | 'JobStatus' => 'Status', |
||
| 73 | 'JobTitle' => 'Description', |
||
| 74 | 'Created' => 'Added', |
||
| 75 | 'StartAfter' => 'Scheduled', |
||
| 76 | 'JobFinished' => 'Finished', |
||
| 77 | ]); |
||
| 78 | |||
| 79 | $config->removeComponentsByType(GridFieldFilterHeader::class); |
||
| 80 | |||
| 81 | $filter = new RichFilterHeader(); |
||
| 82 | $filter |
||
| 83 | ->setFilterConfig([ |
||
| 84 | 'getImplementationSummary' => 'Implementation', |
||
| 85 | 'Description' => 'JobTitle', |
||
| 86 | 'Status' => [ |
||
| 87 | 'title' => 'JobStatus', |
||
| 88 | 'filter' => 'ExactMatchFilter', |
||
| 89 | ], |
||
| 90 | 'JobTypeString' => [ |
||
| 91 | 'title' => 'JobType', |
||
| 92 | 'filter' => 'ExactMatchFilter', |
||
| 93 | ], |
||
| 94 | 'Created' => 'Added', |
||
| 95 | 'StartAfter' => 'Scheduled', |
||
| 96 | ]) |
||
| 97 | ->setFilterFields([ |
||
| 98 | 'JobType' => $queueType = DropdownField::create( |
||
| 99 | '', |
||
| 100 | '', |
||
| 101 | $this->getQueueTypes() |
||
| 102 | ), |
||
| 103 | 'JobStatus' => $jobStatus = DropdownField::create( |
||
| 104 | '', |
||
| 105 | '', |
||
| 106 | $this->getJobStatuses() |
||
| 107 | ), |
||
| 108 | 'Added' => $added = DropdownField::create( |
||
| 109 | '', |
||
| 110 | '', |
||
| 111 | $this->getAddedDates() |
||
| 112 | ), |
||
| 113 | 'Scheduled' => $scheduled = DropdownField::create( |
||
| 114 | '', |
||
| 115 | '', |
||
| 116 | [ |
||
| 117 | self::SCHEDULED_FILTER_FUTURE => self::SCHEDULED_FILTER_FUTURE, |
||
| 118 | self::SCHEDULED_FILTER_PAST => self::SCHEDULED_FILTER_PAST, |
||
| 119 | ] |
||
| 120 | ), |
||
| 121 | ]) |
||
| 122 | ->setFilterMethods([ |
||
| 123 | 'Added' => static function (DataList $list, $name, $value): DataList { |
||
| 124 | if ($value) { |
||
| 125 | $added = DBDatetime::now()->modify($value); |
||
| 126 | |||
| 127 | return $list->filter(['Created:LessThanOrEqual' => $added->Rfc2822()]); |
||
| 128 | } |
||
| 129 | |||
| 130 | return $list; |
||
| 131 | }, |
||
| 132 | 'Scheduled' => static function (DataList $list, $name, $value): DataList { |
||
| 133 | if ($value === static::SCHEDULED_FILTER_FUTURE) { |
||
| 134 | return $list->filter([ |
||
| 135 | 'StartAfter:GreaterThan' => DBDatetime::now()->Rfc2822(), |
||
| 136 | ]); |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($value === static::SCHEDULED_FILTER_PAST) { |
||
| 140 | return $list->filter([ |
||
| 141 | 'StartAfter:LessThanOrEqual' => DBDatetime::now()->Rfc2822(), |
||
| 142 | ]); |
||
| 143 | } |
||
| 144 | |||
| 145 | return $list; |
||
| 146 | }, |
||
| 147 | ]); |
||
| 148 | |||
| 149 | foreach ([$jobStatus, $queueType, $added, $scheduled] as $dropDownField) { |
||
| 150 | /** @var DropdownField $dropDownField */ |
||
| 151 | $dropDownField->setEmptyString('-- select --'); |
||
| 152 | } |
||
| 153 | |||
| 154 | $config->addComponent($filter, GridFieldPaginator::class); |
||
| 155 | } |
||
| 156 | |||
| 223 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: