| Conditions | 8 | 
| Paths | 12 | 
| Total Lines | 101 | 
| Code Lines | 64 | 
| Lines | 12 | 
| Ratio | 11.88 % | 
| 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  | 
            ||
| 55 | protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)  | 
            ||
| 56 |     { | 
            ||
| 57 |         $reg_id = $request->get_param('REG_ID'); | 
            ||
| 58 |         $dtt_id = $request->get_param('DTT_ID'); | 
            ||
| 59 |         $force = $request->get_param('force'); | 
            ||
| 60 |         if ($force == 'true') { | 
            ||
| 61 | $force = true;  | 
            ||
| 62 |         } else { | 
            ||
| 63 | $force = false;  | 
            ||
| 64 | }  | 
            ||
| 65 | $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);  | 
            ||
| 66 |         if (! $reg instanceof EE_Registration) { | 
            ||
| 67 | return $this->sendResponse(  | 
            ||
| 68 | new WP_Error(  | 
            ||
| 69 | 'rest_registration_toggle_checkin_invalid_id',  | 
            ||
| 70 | sprintf(  | 
            ||
| 71 | __(  | 
            ||
| 72 | 'You cannot checkin registration with ID %1$s because it doesn\'t exist.',  | 
            ||
| 73 | 'event_espresso'  | 
            ||
| 74 | ),  | 
            ||
| 75 | $reg_id  | 
            ||
| 76 | ),  | 
            ||
| 77 |                     array('status' => 422) | 
            ||
| 78 | )  | 
            ||
| 79 | );  | 
            ||
| 80 | }  | 
            ||
| 81 | View Code Duplication |         if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { | 
            |
| 82 | return $this->sendResponse(  | 
            ||
| 83 | new WP_Error(  | 
            ||
| 84 | 'rest_user_cannot_toggle_checkin',  | 
            ||
| 85 | sprintf(  | 
            ||
| 86 |                         __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), | 
            ||
| 87 | $reg_id  | 
            ||
| 88 | ),  | 
            ||
| 89 |                     array('status' => 403) | 
            ||
| 90 | )  | 
            ||
| 91 | );  | 
            ||
| 92 | }  | 
            ||
| 93 | $success = $reg->toggle_checkin_status($dtt_id, ! $force);  | 
            ||
| 94 |         if ($success === false) { | 
            ||
| 95 | //check if we know they can't check in because they're not approved and we aren't forcing  | 
            ||
| 96 |             if (! $reg->is_approved() && ! $force) { | 
            ||
| 97 | //rely on EE_Error::add_error messages to have been added to give more data about why it failed  | 
            ||
| 98 | return $this->sendResponse(  | 
            ||
| 99 | new WP_Error(  | 
            ||
| 100 | 'rest_toggle_checkin_failed',  | 
            ||
| 101 | __(  | 
            ||
| 102 | // @codingStandardsIgnoreStart  | 
            ||
| 103 | 'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',  | 
            ||
| 104 | // @codingStandardsIgnoreEnd  | 
            ||
| 105 | 'event_espresso'  | 
            ||
| 106 | )  | 
            ||
| 107 | )  | 
            ||
| 108 | );  | 
            ||
| 109 | }  | 
            ||
| 110 | return $this->sendResponse(  | 
            ||
| 111 | new WP_Error(  | 
            ||
| 112 | 'rest_toggle_checkin_failed_not_forceable',  | 
            ||
| 113 |                     __('Registration checkin failed. Please see additional error data.', 'event_espresso') | 
            ||
| 114 | )  | 
            ||
| 115 | );  | 
            ||
| 116 | }  | 
            ||
| 117 | $checkin = EEM_Checkin::instance()->get_one(  | 
            ||
| 118 | array(  | 
            ||
| 119 | array(  | 
            ||
| 120 | 'REG_ID' => $reg_id,  | 
            ||
| 121 | 'DTT_ID' => $dtt_id,  | 
            ||
| 122 | ),  | 
            ||
| 123 | 'order_by' => array(  | 
            ||
| 124 | 'CHK_timestamp' => 'DESC',  | 
            ||
| 125 | ),  | 
            ||
| 126 | )  | 
            ||
| 127 | );  | 
            ||
| 128 |         if (! $checkin instanceof EE_Checkin) { | 
            ||
| 129 | return $this->sendResponse(  | 
            ||
| 130 | new WP_Error(  | 
            ||
| 131 | 'rest_toggle_checkin_error',  | 
            ||
| 132 | sprintf(  | 
            ||
| 133 | __(  | 
            ||
| 134 | // @codingStandardsIgnoreStart  | 
            ||
| 135 | 'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',  | 
            ||
| 136 | // @codingStandardsIgnoreEnd  | 
            ||
| 137 | 'event_espresso'  | 
            ||
| 138 | ),  | 
            ||
| 139 | $reg_id,  | 
            ||
| 140 | $dtt_id  | 
            ||
| 141 | )  | 
            ||
| 142 | )  | 
            ||
| 143 | );  | 
            ||
| 144 | }  | 
            ||
| 145 | $get_request = new WP_REST_Request(  | 
            ||
| 146 | 'GET',  | 
            ||
| 147 | '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()  | 
            ||
| 148 | );  | 
            ||
| 149 | $get_request->set_url_params(  | 
            ||
| 150 | array(  | 
            ||
| 151 | 'id' => $checkin->ID(),  | 
            ||
| 152 | )  | 
            ||
| 153 | );  | 
            ||
| 154 | return Read::handleRequestGetOne($get_request, $version, 'Checkin');  | 
            ||
| 155 | }  | 
            ||
| 156 | }  | 
            ||
| 157 |