| Conditions | 9 |
| Paths | 8 |
| Total Lines | 89 |
| 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 |
||
| 31 | public function handle($event, $payload) |
||
| 32 | { |
||
| 33 | list($model) = $payload; |
||
| 34 | |||
| 35 | // // Payload |
||
| 36 | // ^ Cmgmyr\Messenger\Models\Message^ {#4332 |
||
| 37 | // #table: "messages" |
||
| 38 | // #touches: array:1 [ |
||
| 39 | // 0 => "thread" |
||
| 40 | // ] |
||
| 41 | // #fillable: array:3 [ |
||
| 42 | // 0 => "thread_id" |
||
| 43 | // 1 => "user_id" |
||
| 44 | // 2 => "body" |
||
| 45 | // ] |
||
| 46 | // #dates: array:1 [ |
||
| 47 | // 0 => "deleted_at" |
||
| 48 | // ] |
||
| 49 | // #connection: null |
||
| 50 | // #primaryKey: "id" |
||
| 51 | // #keyType: "int" |
||
| 52 | // +incrementing: true |
||
| 53 | // #with: [] |
||
| 54 | // #withCount: [] |
||
| 55 | // #perPage: 15 |
||
| 56 | // +exists: false |
||
| 57 | // +wasRecentlyCreated: false |
||
| 58 | // #attributes: [] |
||
| 59 | // #original: [] |
||
| 60 | // #changes: [] |
||
| 61 | // #casts: [] |
||
| 62 | // #dateFormat: null |
||
| 63 | // #appends: [] |
||
| 64 | // #dispatchesEvents: [] |
||
| 65 | // #observables: [] |
||
| 66 | // #relations: [] |
||
| 67 | // +timestamps: true |
||
| 68 | // #hidden: [] |
||
| 69 | // #visible: [] |
||
| 70 | // #guarded: array:1 [ |
||
| 71 | // 0 => "*" |
||
| 72 | // ] |
||
| 73 | // #forceDeleting: false |
||
| 74 | // } |
||
| 75 | |||
| 76 | // Ignore |
||
| 77 | if (!app()->bound(IntegrationsService::class)) { |
||
| 78 | return true; |
||
| 79 | } |
||
| 80 | |||
| 81 | if (!Schema::hasColumn($model->getTable(), 'business_code')) { |
||
| 82 | return true; |
||
| 83 | } |
||
| 84 | |||
| 85 | |||
| 86 | // Get the action from the event name |
||
| 87 | preg_match('#\.(\w+)#', $event, $matches); |
||
| 88 | $action = $matches[1]; |
||
| 89 | |||
| 90 | // If there is matching callback method on the model, call it, passing |
||
| 91 | // any additional event arguments to it |
||
| 92 | $method = 'on'.Str::studly($action); |
||
| 93 | |||
| 94 | if ($method == 'onBooting') { |
||
| 95 | $model::addGlobalScope(new IntegrationsScope); |
||
| 96 | return true; |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($method == 'onCreating') { |
||
| 100 | $business = app()->make(IntegrationsService::class); |
||
| 101 | $model->business_code = $business->getCode(); |
||
| 102 | if (Auth::check()) { |
||
| 103 | // @todo Verifica se tem acesso |
||
| 104 | } |
||
| 105 | return true; |
||
| 106 | } |
||
| 107 | |||
| 108 | if ($method == 'onCreated') { |
||
| 109 | |||
| 110 | return true; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($method == 'onValidating' || $method == 'onValidated') { |
||
| 114 | |||
| 115 | return true; |
||
| 116 | } |
||
| 117 | |||
| 118 | return true; |
||
| 119 | } |
||
| 120 | } |
||
| 121 |