Conditions | 6 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 36 |
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 |
||
42 | public function columns() |
||
43 | { |
||
44 | return [ |
||
45 | 'Icon' => [ |
||
46 | 'title' => '', |
||
47 | 'formatting' => function ($value, BaseElement $item) { |
||
48 | return $item->getIcon(); |
||
49 | }, |
||
50 | ], |
||
51 | 'Title' => [ |
||
52 | 'title' => _t(__CLASS__ . '.Title', 'Title'), |
||
53 | 'formatting' => function ($value, BaseElement $item) { |
||
54 | $value = $item->Title; |
||
55 | |||
56 | if (!empty($value)) { |
||
57 | if ($link = $item->CMSEditLink()) { |
||
58 | return $this->getEditLink($value, $link); |
||
59 | } |
||
60 | return $value; |
||
61 | } |
||
62 | return '<span class="element__note">' . _t(__CLASS__ . '.None', 'None') . '</span>'; |
||
63 | }, |
||
64 | ], |
||
65 | 'ElementSummary' => [ |
||
66 | 'title' => _t(__CLASS__ . '.Summary', 'Summary'), |
||
67 | 'casting' => 'HTMLText->RAW', |
||
68 | 'formatting' => function ($value, BaseElement $item) { |
||
69 | try { |
||
70 | return $item->getSummary(); |
||
71 | } catch (InvalidArgumentException $exception) { |
||
72 | // Don't break the report, just continue. Image manipulation is an example which may |
||
73 | // throw exceptions here. |
||
74 | Injector::inst()->get(LoggerInterface::class)->debug( |
||
75 | 'Element #' . $item->ID . ' threw exception in ElementInUseReport via getSummary(): ' |
||
76 | . $exception->getMessage() |
||
77 | ); |
||
78 | return ''; |
||
79 | } |
||
80 | }, |
||
81 | ], |
||
82 | 'Type' => [ |
||
83 | 'title' => _t(__CLASS__ . '.Type', 'Type'), |
||
84 | 'formatting' => function ($value, BaseElement $item) { |
||
85 | return $item->getTypeNice(); |
||
86 | }, |
||
87 | ], |
||
88 | 'Page.Title' => [ |
||
89 | 'title' => _t(__CLASS__ . '.Page', 'Page'), |
||
90 | 'formatting' => function ($value, BaseElement $item) { |
||
91 | if ($value) { |
||
92 | if ($link = $item->getPage()->CMSEditLink()) { |
||
93 | return $this->getEditLink($value, $link); |
||
94 | } |
||
95 | } |
||
96 | return $item->getPageTitle(); |
||
97 | }, |
||
172 |