Conditions | 6 |
Paths | 8 |
Total Lines | 56 |
Code Lines | 32 |
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 |
||
22 | public function getColumnContent($gridField, $record, $columnName) |
||
23 | { |
||
24 | if ($columnName == 'State') { |
||
25 | Requirements::css(BLOGGER_DIR . '/css/cms.css'); |
||
26 | if ($record instanceof BlogPost) { |
||
27 | $modifiedLabel = ''; |
||
28 | |||
29 | if ($record->isModifiedOnStage) { |
||
30 | $modifiedLabel = '<span class="modified">' . _t('GridFieldBlogPostState.Modified') . '</span>'; |
||
31 | } |
||
32 | |||
33 | if (!$record->isPublished()) { |
||
34 | /** |
||
35 | * @var SS_Datetime $lastEdited |
||
36 | */ |
||
37 | $lastEdited = $record->dbObject('LastEdited'); |
||
38 | |||
39 | return _t( |
||
40 | 'GridFieldBlogPostState.Draft', |
||
41 | '<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}', |
||
42 | 'State for when a post is saved.', |
||
43 | array( |
||
44 | 'date' => $lastEdited->FormatFromSettings(), |
||
45 | ) |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @var SS_Datetime $publishDate |
||
51 | */ |
||
52 | $publishDate = $record->dbObject('PublishDate'); |
||
53 | |||
54 | if (strtotime($record->PublishDate) > time()) { |
||
55 | return _t( |
||
56 | 'GridFieldBlogPostState.Timer', |
||
57 | '<i class="gridfield-icon blog-icon-timer"></i> Publish at {date}', |
||
58 | 'State for when a post is published.', |
||
59 | array( |
||
60 | 'date' => $publishDate->FormatFromSettings(), |
||
61 | ) |
||
62 | ) . $modifiedLabel; |
||
63 | } |
||
64 | |||
65 | return _t( |
||
66 | 'GridFieldBlogPostState.Published', |
||
67 | '<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}', |
||
68 | 'State for when a post is published.', |
||
69 | array( |
||
70 | 'date' => $publishDate->FormatFromSettings(), |
||
71 | ) |
||
72 | ) . $modifiedLabel; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | return ''; |
||
77 | } |
||
78 | |||
105 |