| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Xetaravel\Models\Validators; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Eloquence\Behaviours\Slug; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Support\Facades\Validator as FacadeValidator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Validation\Rule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Validation\Validator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 9 |  | View Code Duplication | class DiscussThreadValidator | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * Get a validator for an incoming create request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @param array $data The data to validate. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @return \Illuminate\Validation\Validator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public static function create(array $data): Validator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $rules = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             'title' => 'required|min:5', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             'category_id' => 'required|integer|exists:discuss_categories,id', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             'slug' => 'unique:discuss_threads', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             'content' => 'required|min:10' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $data['slug'] = Slug::fromTitle($data['title']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         return FacadeValidator::make($data, $rules); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * Get a validator for an incoming update request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param array $data The data to validate. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param int $id The actual article id to ignore the slug rule. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @return \Illuminate\Validation\Validator | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |     public static function update(array $data, int $id): Validator | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |         $rules = [ | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |             'title' => 'required|min:5', | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |             'category_id' => 'required|integer|exists:discuss_categories,id', | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |             'slug' => [ | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |                 Rule::unique('discuss_threads')->ignore($id) | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |             ], | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |             'content' => 'required|min:10' | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |         ]; | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |         $data['slug'] = Slug::fromTitle($data['title']); | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |         return FacadeValidator::make($data, $rules); | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 53 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |  | 
            
                        
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.