| Conditions | 11 |
| Paths | 768 |
| Total Lines | 29 |
| Lines | 10 |
| Ratio | 34.48 % |
| 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 parse($data) |
||
| 18 | { |
||
| 19 | // set the repo |
||
| 20 | $repo = []; |
||
| 21 | $repo['name'] = $data['repository']['name']; |
||
| 22 | $repo['homepage'] = $data['repository']['html_url']; |
||
| 23 | $this->repo = $repo; |
||
| 24 | // set the branch |
||
| 25 | $this->branch = isset($data['ref']) ? substr($data['ref'], 11) : ''; // refs/heads/ |
||
| 26 | // get the pusher |
||
| 27 | $user_name = isset($data['pusher']) && isset($data['pusher']['user_name']) ? $data['pusher']['user_name'] : ''; |
||
| 28 | $user_email = isset($data['pusher']) && isset($data['pusher']['user_email']) ? $data['pusher']['user_email'] : ''; |
||
| 29 | $user = [ 'name' => $user_name, 'email' => $user_email ]; |
||
| 30 | View Code Duplication | if ($user_email) { |
|
|
|
|||
| 31 | $user2 = EloquentUser::where('email', $user_email)->first(); |
||
| 32 | if ($user2) { |
||
| 33 | $user['id'] = $user2->id; |
||
| 34 | $user['name'] = $user2->first_name; |
||
| 35 | $user['email'] = $user2->email; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | $this->pusher = $user; |
||
| 39 | // set the commits |
||
| 40 | $this->commits = isset($data['commits']) ? $data['commits'] : []; |
||
| 41 | // get the after |
||
| 42 | $this->after = isset($data['after']) ? $data['after'] : ''; |
||
| 43 | // get the before |
||
| 44 | $this->before = isset($data['before']) ? $data['before'] : ''; |
||
| 45 | } |
||
| 46 | |||
| 89 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.