| Conditions | 5 |
| Paths | 12 |
| Total Lines | 83 |
| 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 |
||
| 58 | public function associateRelationships($object, Request $request) { |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Validate commentstatus ID, if failed set to default |
||
| 62 | */ |
||
| 63 | $validator = Validator::make($request->all(), [ |
||
| 64 | 'commentstatus_id' => 'required|integer|min:1|exists:commentstatus,id', |
||
| 65 | ]); |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Validator fails - try to set the valid comment id |
||
| 69 | * |
||
| 70 | */ |
||
| 71 | if ($validator->fails()) { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Auto approve ? |
||
| 75 | */ |
||
| 76 | if(env('AUTO_APPROVE_COMMENTS', 0) == 1){ |
||
| 77 | |||
| 78 | $object->commentstatuses()->associate(2); |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Manual approve |
||
| 83 | */ |
||
| 84 | else{ |
||
| 85 | $object->commentstatuses()->associate(1); |
||
| 86 | } |
||
| 87 | |||
| 88 | } |
||
| 89 | else{ |
||
| 90 | |||
| 91 | $object->commentstatuses()->associate($request->input('commentstatus_id')); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Validate article ID, if failed set to actual authorized article |
||
| 96 | */ |
||
| 97 | $validator = Validator::make($request->all(), [ |
||
| 98 | 'article_id' => 'required|integer|min:1|exists:article,id', |
||
| 99 | ]); |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Validator fails - nothing to do |
||
| 103 | */ |
||
| 104 | if ($validator->fails()) { |
||
| 105 | |||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Validator OK - save it |
||
| 110 | */ |
||
| 111 | else { |
||
| 112 | |||
| 113 | $object->articles()->associate($request->input('article_id')); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Validate page ID, if failed set to actual authorized page |
||
| 118 | */ |
||
| 119 | $validator = Validator::make($request->all(), [ |
||
| 120 | 'page_id' => 'required|integer|min:1|exists:page,id', |
||
| 121 | ]); |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Validator fails - nothing to do |
||
| 125 | */ |
||
| 126 | if ($validator->fails()) { |
||
| 127 | |||
| 128 | // nothing |
||
| 129 | |||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Validator OK - save it |
||
| 134 | */ |
||
| 135 | else { |
||
| 136 | |||
| 137 | $object->pages()->associate($request->input('page_id')); |
||
| 138 | } |
||
| 139 | |||
| 140 | } |
||
| 141 | |||
| 225 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.