Conditions | 6 |
Paths | 6 |
Total Lines | 57 |
Code Lines | 21 |
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 run($request) |
||
20 | { |
||
21 | |||
22 | // update block/set titles |
||
23 | // Name field has been reverted back to Title |
||
24 | // DB::query("update Block set Name = Title"); |
||
|
|||
25 | // DB::query("update BlockSet set Name = Title"); |
||
26 | |||
27 | // update block areas |
||
28 | |||
29 | DB::query(' |
||
30 | update SiteTree_Blocks |
||
31 | left join Block on SiteTree_Blocks.BlockID = Block.ID |
||
32 | set BlockArea = Block.Area |
||
33 | where BlockID = Block.ID |
||
34 | '); |
||
35 | |||
36 | // update block sort |
||
37 | |||
38 | DB::query(' |
||
39 | update SiteTree_Blocks |
||
40 | left join Block on SiteTree_Blocks.BlockID = Block.ID |
||
41 | set Sort = Block.Weight |
||
42 | where BlockID = Block.ID |
||
43 | '); |
||
44 | |||
45 | echo 'BlockAreas, Sort updated<br />'; |
||
46 | |||
47 | // migrate global blocks |
||
48 | |||
49 | $sc = SiteConfig::current_site_config(); |
||
50 | if ($sc->Blocks()->Count()) { |
||
51 | $set = BlockSet::get()->filter('Title', 'Global')->first(); |
||
52 | if (!$set) { |
||
53 | $set = BlockSet::create([ |
||
54 | 'Title' => 'Global', |
||
55 | ]); |
||
56 | $set->write(); |
||
57 | } |
||
58 | foreach ($sc->Blocks() as $block) { |
||
59 | if (!$set->Blocks()->find('ID', $block->ID)) { |
||
60 | $set->Blocks()->add($block, [ |
||
61 | 'Sort' => $block->Weight, |
||
62 | 'BlockArea' => $block->Area, |
||
63 | ]); |
||
64 | echo "Block #$block->ID added to Global block set<br />"; |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | |||
69 | // publish blocks |
||
70 | $blocks = Block::get()->filter('Published', 1); |
||
71 | foreach ($blocks as $block) { |
||
72 | $block->publish('Stage', 'Live'); |
||
73 | echo "Published Block #$block->ID<br />"; |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.