| Conditions | 6 | 
| Paths | 5 | 
| Total Lines | 65 | 
| Code Lines | 29 | 
| 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  | 
            ||
| 17 |     public function approve($data) { | 
            ||
| 18 | // Approve items for inclusion  | 
            ||
| 19 | // Create new epobject and update the editqueue  | 
            ||
| 20 | |||
| 21 | global $THEUSER;  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 22 | |||
| 23 | // We need a list of editqueue items to play with  | 
            ||
| 24 | $this->get_pending();  | 
            ||
| 25 |         if (!isset($this->pending)) { | 
            ||
| 26 | return false;  | 
            ||
| 27 | }  | 
            ||
| 28 |         $timestamp = date('Y-m-d H:i:s', time()); | 
            ||
| 29 | |||
| 30 |         foreach ($data['approvals'] as $approval_id) { | 
            ||
| 31 | // create a new epobject  | 
            ||
| 32 | // title VARCHAR(255),  | 
            ||
| 33 | // body TEXT,  | 
            ||
| 34 | // type INTEGER,  | 
            ||
| 35 | // created DATETIME,  | 
            ||
| 36 | // modified DATETIME,  | 
            ||
| 37 | /*print "<pre>";  | 
            ||
| 38 | print_r($data);  | 
            ||
| 39 | print "</pre>";*/  | 
            ||
| 40 | // Check to see that we actually have something to approve  | 
            ||
| 41 |             if (!isset($this->pending[$approval_id])) { | 
            ||
| 42 | break;  | 
            ||
| 43 | }  | 
            ||
| 44 |             $q = $this->db->query("INSERT INTO glossary | 
            ||
| 45 | (title, body, type, created, visible)  | 
            ||
| 46 | VALUES  | 
            ||
| 47 |                             ('" . addslashes($this->pending[$approval_id]['title']) . "', | 
            ||
| 48 | '" . addslashes($this->pending[$approval_id]['body']) . "',  | 
            ||
| 49 | '" . $data['epobject_type'] . "',  | 
            ||
| 50 | '" . $timestamp . "',  | 
            ||
| 51 | 1);");  | 
            ||
| 52 | |||
| 53 | // If that didn't work we can't go any further...  | 
            ||
| 54 |             if (!$q->success()) { | 
            ||
| 55 | print "glossary trouble";  | 
            ||
| 56 | return false;  | 
            ||
| 57 | }  | 
            ||
| 58 | $this->current_epobject_id = $q->insert_id();  | 
            ||
| 59 | |||
| 60 | // Then finally update the editqueue with  | 
            ||
| 61 | // the new epobject id and approval details.  | 
            ||
| 62 |             $q = $this->db->query("UPDATE editqueue | 
            ||
| 63 | SET  | 
            ||
| 64 | glossary_id='" . $this->current_epobject_id. "',  | 
            ||
| 65 | editor_id='" . addslashes($THEUSER->user_id()) . "',  | 
            ||
| 66 | approved='1',  | 
            ||
| 67 | decided='" . $timestamp . "'  | 
            ||
| 68 | WHERE edit_id=" . $approval_id . ";");  | 
            ||
| 69 |             if (!$q->success()) { | 
            ||
| 70 | break;  | 
            ||
| 71 | }  | 
            ||
| 72 |             else { | 
            ||
| 73 | // Scrub that one from the list of pending items  | 
            ||
| 74 | unset ($this->pending[$approval_id]);  | 
            ||
| 75 | }  | 
            ||
| 76 | }  | 
            ||
| 77 | |||
| 78 | $this->update_pending_count();  | 
            ||
| 79 | |||
| 80 | return true;  | 
            ||
| 81 | }  | 
            ||
| 82 | |||
| 84 | 
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state