Conditions | 6 |
Paths | 8 |
Total Lines | 55 |
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 |
||
19 | public function getColumnContent($gridField, $record, $columnName) |
||
20 | { |
||
21 | if ($columnName == 'State') { |
||
22 | if ($record instanceof BlogPost) { |
||
23 | $modifiedLabel = ''; |
||
24 | |||
25 | if ($record->isModifiedOnDraft()) { |
||
26 | $modifiedLabel = '<span class="modified">' . _t(__CLASS__ . '.Modified', 'Modified') . '</span>'; |
||
27 | } |
||
28 | |||
29 | if (!$record->isPublished()) { |
||
30 | /** |
||
31 | * @var DBDatetime $lastEdited |
||
32 | */ |
||
33 | $lastEdited = $record->dbObject('LastEdited'); |
||
34 | |||
35 | return '<i class="font-icon-edit mr-2"></i> ' . _t( |
||
36 | __CLASS__ . '.Draft', |
||
37 | 'Saved as Draft on {date}', |
||
38 | 'State for when a post is saved.', |
||
39 | [ |
||
40 | 'date' => $lastEdited->FormatFromSettings(), |
||
41 | ] |
||
42 | ); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @var DBDatetime $publishDate |
||
47 | */ |
||
48 | $publishDate = $record->dbObject('PublishDate'); |
||
49 | |||
50 | if (strtotime($record->PublishDate) > time()) { |
||
51 | return '<i class="font-icon-clock mr-2"></i> ' . _t( |
||
52 | __CLASS__ . '.Timer', |
||
53 | 'Publish at {date}', |
||
54 | 'State for when a post is published.', |
||
55 | [ |
||
56 | 'date' => $publishDate->FormatFromSettings(), |
||
57 | ] |
||
58 | ) . $modifiedLabel; |
||
59 | } |
||
60 | |||
61 | return '<i class="font-icon-check-mark-circle text-success mr-2"></i> ' . _t( |
||
62 | __CLASS__ . '.Published', |
||
63 | 'Published on {date}', |
||
64 | 'State for when a post is published.', |
||
65 | [ |
||
66 | 'date' => $publishDate->FormatFromSettings(), |
||
67 | ] |
||
68 | ) . $modifiedLabel; |
||
69 | } |
||
70 | } |
||
71 | |||
72 | return ''; |
||
73 | } |
||
74 | |||
101 |