| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Xetaravel\Http\Controllers\Discuss; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\View\View; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Xetaio\Mentions\Parser\MentionParser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Xetaravel\Models\DiscussCategory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Xetaravel\Models\DiscussConversation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Xetaravel\Models\DiscussLog; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Xetaravel\Models\Repositories\DiscussConversationRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Xetaravel\Models\Validators\DiscussConversationValidator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class ConversationController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * Show the conversation by its id. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @return \Illuminate\Http\Response | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function show(Request $request, string $slug, int $id) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $conversation = DiscussConversation::findOrFail($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $categories = DiscussCategory::pluckLocked('title', 'id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $posts = $conversation->posts() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             ->where('id', '!=', $conversation->solved_post_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             ->where('id', '!=', $conversation->first_post_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             ->paginate(config('xetaravel.pagination.discuss.post_per_page')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $postsWithLogs = $conversation->getPostsWithLogs( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             collect($posts->items()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             $this->getCurrentPage($request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->breadcrumbs->setListElementClasses('breadcrumbs'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $breadcrumbs = $this->breadcrumbs->addCrumb(e($conversation->title), $conversation->conversation_url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         return view( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             'Discuss::conversation.show', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             compact('conversation', 'posts', 'postsWithLogs', 'breadcrumbs', 'categories') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * Show the create form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @return \Illuminate\View\View | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 49 |  | View Code Duplication |     public function showCreateForm(): View | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $categories = DiscussCategory::pluckLocked('title', 'id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $breadcrumbs = $this->breadcrumbs->addCrumb('Start a discussion', route('discuss.conversation.create')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return view('Discuss::conversation.create', compact('breadcrumbs', 'categories')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * Handle a conversation create request for the application. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param \Illuminate\Http\Request $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function create(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         DiscussConversationValidator::create($request->all())->validate(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         if (DiscussConversation::isFlooding('xetaravel.flood.discuss.conversation')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             return back() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 ->withInput() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                 ->with('danger', 'Wow, keep calm bro, and try to not flood !'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $conversation = DiscussConversationRepository::create($request->all()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $post = $conversation->firstPost; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $parser = new MentionParser($post); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $content = $parser->parse($post->content); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $post->content = $content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $post->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         return redirect() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ->route('discuss.conversation.show', ['slug' => $conversation->slug, 'id' => $conversation->getKey()]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             ->with('success', 'Your discussion has been created successfully !'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * Handle a conversation update request for the application. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @param \Illuminate\Http\Request $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param string $slug | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |     public function update(Request $request, string $slug, int $id) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |         $conversation = DiscussConversation::findOrFail($id); | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |         DiscussConversationValidator::update($request->all(), $id)->validate(); | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |         $conversation = DiscussConversationRepository::update($request->all(), $conversation); | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |         return redirect() | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |             ->route('discuss.conversation.show', ['slug' => $conversation->slug, 'id' => $conversation->getKey()]) | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |             ->with('success', 'Your conversation has been updated successfully !'); | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * Get the current page for the conversation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @param \Illuminate\Http\Request $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     protected function getCurrentPage(Request $request): int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         return !is_null($request->get('page')) ? (int)$request->get('page') : 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 120 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 121 |  |  |  | 
            
                        
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.