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