| Conditions | 2 |
| Paths | 2 |
| Total Lines | 87 |
| 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 |
||
| 29 | public function handle($event, $payload) |
||
| 30 | { |
||
| 31 | list($model) = $payload; |
||
| 32 | if ($this->isToIgnore($model, $event)) { |
||
| 33 | return; |
||
| 34 | } |
||
| 35 | |||
| 36 | Log::warning($event); |
||
| 37 | |||
| 38 | // // Payload |
||
| 39 | // ^ Cmgmyr\Messenger\Models\Message^ {#4332 |
||
| 40 | // #table: "messages" |
||
| 41 | // #touches: array:1 [ |
||
| 42 | // 0 => "thread" |
||
| 43 | // ] |
||
| 44 | // #fillable: array:3 [ |
||
| 45 | // 0 => "thread_id" |
||
| 46 | // 1 => "user_id" |
||
| 47 | // 2 => "body" |
||
| 48 | // ] |
||
| 49 | // #dates: array:1 [ |
||
| 50 | // 0 => "deleted_at" |
||
| 51 | // ] |
||
| 52 | // #connection: null |
||
| 53 | // #primaryKey: "id" |
||
| 54 | // #keyType: "int" |
||
| 55 | // +incrementing: true |
||
| 56 | // #with: [] |
||
| 57 | // #withCount: [] |
||
| 58 | // #perPage: 15 |
||
| 59 | // +exists: false |
||
| 60 | // +wasRecentlyCreated: false |
||
| 61 | // #attributes: [] |
||
| 62 | // #original: [] |
||
| 63 | // #changes: [] |
||
| 64 | // #casts: [] |
||
| 65 | // #dateFormat: null |
||
| 66 | // #appends: [] |
||
| 67 | // #dispatchesEvents: [] |
||
| 68 | // #observables: [] |
||
| 69 | // #relations: [] |
||
| 70 | // +timestamps: true |
||
| 71 | // #hidden: [] |
||
| 72 | // #visible: [] |
||
| 73 | // #guarded: array:1 [ |
||
| 74 | // 0 => "*" |
||
| 75 | // ] |
||
| 76 | // #forceDeleting: false |
||
| 77 | // } |
||
| 78 | |||
| 79 | |||
| 80 | // // Get the action from the event name |
||
| 81 | // preg_match('#\.(\w+)#', $event, $matches); |
||
| 82 | // $action = $matches[1]; |
||
| 83 | |||
| 84 | // // If there is matching callback method on the model, call it, passing |
||
| 85 | // // any additional event arguments to it |
||
| 86 | // $method = 'on'.Str::studly($action); |
||
| 87 | |||
| 88 | // if ($method == 'onCreating') { |
||
| 89 | // $this->runInCreating($model); |
||
| 90 | // } |
||
| 91 | // else if ($method == 'onCreated') { |
||
| 92 | // $this->runInCreated($model); |
||
| 93 | // } |
||
| 94 | // else if ($method == 'onValidating' || $method == 'onValidated') { |
||
| 95 | // if (empty(array_slice($payload, 1))) { |
||
| 96 | // // @todo resolver dps |
||
| 97 | // \Log::debug('[Facilitador] ModelCallbacks: ignorando onValidating porque nao tem parametro '.print_r([get_class($model), $method], true)); |
||
| 98 | // return true; |
||
| 99 | // } |
||
| 100 | // } |
||
| 101 | |||
| 102 | // // @todo resolver isso aqui e o de cima gambi, deu merda |
||
| 103 | // if (method_exists($model, $method)) { |
||
| 104 | // // if (!empty(array_slice($payload, 1))) { |
||
| 105 | // // dd($model, $method, $payload, array_slice($payload, 1), 'erronoModelCallback'); |
||
| 106 | // // } |
||
| 107 | // try { |
||
| 108 | // return call_user_func_array([$model, $method], array_slice($payload, 1)); |
||
| 109 | // } catch (FatalThrowableError|Throwable $th) { |
||
| 110 | // \Log::info('[Facilitador] ModelCallbacks: problema aqui'.print_r([get_class($model), $method], true)); |
||
| 111 | // } |
||
| 112 | |||
| 113 | // } |
||
| 114 | return true; |
||
| 115 | } |
||
| 116 | } |
||
| 117 |