| Conditions | 4 |
| Paths | 4 |
| Total Lines | 64 |
| Code Lines | 44 |
| 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 |
||
| 40 | public function show(Request $request, string $slug) |
||
|
|
|||
| 41 | { |
||
| 42 | $user = User::with('articles', 'comments') |
||
| 43 | ->where('slug', Str::lower($slug)) |
||
| 44 | ->first(); |
||
| 45 | |||
| 46 | if (is_null($user)) { |
||
| 47 | return redirect() |
||
| 48 | ->route('page.index') |
||
| 49 | ->with('danger', 'This user doesn\'t exist or has been deleted !'); |
||
| 50 | } |
||
| 51 | $articles = $user->articles() |
||
| 52 | ->latest() |
||
| 53 | ->take(config('xetaravel.pagination.user.articles_profile_page')) |
||
| 54 | ->get(); |
||
| 55 | |||
| 56 | $comments = $user->comments() |
||
| 57 | ->with('article') |
||
| 58 | ->latest() |
||
| 59 | ->take(config('xetaravel.pagination.user.comments_profile_page')) |
||
| 60 | ->get(); |
||
| 61 | |||
| 62 | $discussPosts = $user->discussPosts() |
||
| 63 | ->join('discuss_conversations', 'discuss_posts.conversation_id', '=', 'discuss_conversations.id') |
||
| 64 | ->where('discuss_conversations.first_post_id', '!=', 'discuss_posts.id') |
||
| 65 | ->select( |
||
| 66 | 'discuss_posts.*', |
||
| 67 | 'discuss_conversations.first_post_id AS conversation_first_post_id', |
||
| 68 | 'discuss_conversations.title AS conversation_title', |
||
| 69 | 'discuss_conversations.slug AS conversation_slug', |
||
| 70 | 'discuss_conversations.id AS conversation_id' |
||
| 71 | ) |
||
| 72 | ->orderBy('discuss_posts.created_at', 'DESC') |
||
| 73 | ->take(config('xetaravel.pagination.user.posts_profile_page')) |
||
| 74 | ->get(); |
||
| 75 | |||
| 76 | $breadcrumbs = $this->breadcrumbs->addCrumb( |
||
| 77 | e($user->username), |
||
| 78 | $user->profile_url |
||
| 79 | ); |
||
| 80 | |||
| 81 | $badges = Badge::all(); |
||
| 82 | |||
| 83 | //dd($discussPosts); |
||
| 84 | |||
| 85 | $articles = collect($articles); |
||
| 86 | |||
| 87 | $activities = $articles->merge($comments)->merge($discussPosts)->sortBy('created_at', SORT_NATURAL, true); |
||
| 88 | //dd($activities); |
||
| 89 | |||
| 90 | //$level = UserUtility::getLevel($user->experiences_total); |
||
| 91 | $level = UserUtility::getLevel($user->experiences_total); |
||
| 92 | |||
| 93 | if ($level['maxLevel'] == true) { |
||
| 94 | $level['currentProgression'] = 100; |
||
| 95 | } elseif ($level['matchExactXPLevel'] == true) { |
||
| 96 | $level['currentProgression'] = 0; |
||
| 97 | } else { |
||
| 98 | $level['currentProgression'] = ($level['currentUserExperience'] / $level['nextLevelExperience'])*100; |
||
| 99 | } |
||
| 100 | |||
| 101 | return view( |
||
| 102 | 'user.show', |
||
| 103 | compact('user', 'activities', 'articles', 'comments', 'breadcrumbs', 'level', 'badges') |
||
| 104 | ); |
||
| 243 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.