| Conditions | 10 |
| Paths | 14 |
| Total Lines | 61 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 51 | public function complete($entity, stdClass $row) { |
||
| 52 | // Load the new node |
||
| 53 | list($id) = entity_extract_ids('node', $entity); |
||
| 54 | $node = node_load($id); |
||
| 55 | |||
| 56 | // As each node is imported, add default Panels displays and Panels if necessary |
||
| 57 | foreach ($row as $key => $value) { |
||
|
|
|||
| 58 | // Check if this is a region column and that there are UUIDs set |
||
| 59 | if (strpos($key, 'region-') === 0 && !empty($value)) { |
||
| 60 | // Parse out the region name |
||
| 61 | $location = str_replace('region-', '', $key); |
||
| 62 | |||
| 63 | // Grab the display from the new Landing node |
||
| 64 | $display = $node->panelizer['page_manager']->display; |
||
| 65 | |||
| 66 | // Loop through each UUID in this region and add a new pane for this node |
||
| 67 | foreach ($value as $uuid) { |
||
| 68 | $pane = panels_new_pane('fieldable_panels_pane', 'uuid:' . $uuid, TRUE); |
||
| 69 | // Check to see if any classy panel styles are included for this pane |
||
| 70 | if (array_key_exists($uuid . '-style', $row) && $settings = json_decode($row->{$uuid . '-style'}, TRUE)) { |
||
| 71 | // Add our default settings |
||
| 72 | $settings['classy_panel_styles_flag'] = 'classy-panel-styles pane'; |
||
| 73 | $pane->style = array( |
||
| 74 | 'style' => 'classy_panel_styles:cps_default', |
||
| 75 | 'settings' => $settings |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | // Add the pane to the display |
||
| 79 | $display->add_pane($pane, $location); |
||
| 80 | // Save the display |
||
| 81 | $display = panels_save_display($display); |
||
| 82 | } |
||
| 83 | |||
| 84 | // Mark the Node as modified so that Panelizer is aware of our changes |
||
| 85 | $node->panelizer['page_manager']->display_is_modified = TRUE; |
||
| 86 | } |
||
| 87 | // Check to see if a display setting needs to be changed |
||
| 88 | elseif (strpos($key, 'display-') === 0) { |
||
| 89 | // Parse out the display setting name |
||
| 90 | $setting = str_replace('display-', '', $key); |
||
| 91 | |||
| 92 | // Change the value for this display setting |
||
| 93 | $node->panelizer['page_manager']->display->$setting = $value; |
||
| 94 | // Mark the Node as modified so that Panelizer is aware of our changes |
||
| 95 | $node->panelizer['page_manager']->display_is_modified = TRUE; |
||
| 96 | panels_save_display($node->panelizer['page_manager']->display); |
||
| 97 | } |
||
| 98 | // Check to see if a panelizer settings needs to be changed |
||
| 99 | elseif (strpos($key, 'panelizer-') === 0) { |
||
| 100 | // Parse out the panelizer setting name |
||
| 101 | $setting = str_replace('panelizer-', '', $key); |
||
| 102 | $node->panelizer['page_manager']->$setting = $value; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | // If we've made changes, save the node |
||
| 107 | if ($node->panelizer['page_manager']->display_is_modified == TRUE) { |
||
| 108 | node_save($node); |
||
| 109 | } |
||
| 110 | |||
| 111 | } |
||
| 112 | |||
| 114 |