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