| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Happyr\ApiClient\Api; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Happyr\ApiClient\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Happyr\ApiClient\Model\Dimension\ExtendedMatch; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Happyr\ApiClient\Model\Dimension\SelfDescription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Happyr\ApiClient\Model\Dimension\SimpleMatch; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Happyr\ApiClient\Model\Dimension\TopPattern; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Happyr\ApiClient\Model\Dimension\TopUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Psr\Http\Message\ResponseInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author Tobias Nyholm <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | final class Match extends HttpApi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @param $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @param array $patterns | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @param array $params   valid keys are norm and recalculate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @return SimpleMatch|ResponseInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 25 |  | View Code Duplication |     public function show($user, array $patterns, array $params) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         Assert::stringNotEmpty($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         Assert::notEmpty($patterns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $params['user'] = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $params['pattern'] = implode(',', $patterns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $response = $this->httpGet('/api/match', $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         return $this->hydrateResponse($response, SimpleMatch::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param array $patterns | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param array $params   valid keys are norm and locale | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @return ExtendedMatch|ResponseInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 45 |  | View Code Duplication |     public function showExtended($user, array $patterns, array $params) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         Assert::stringNotEmpty($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         Assert::notEmpty($patterns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $params['user'] = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $params['pattern'] = implode(',', $patterns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $response = $this->httpGet('/api/match/extended', $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return $this->hydrateResponse($response, ExtendedMatch::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @param $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param array $patterns | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param array $params   valid keys are norm and locale | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @return SelfDescription|ResponseInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 65 |  | View Code Duplication |     public function selfDescription($user, array $patterns, array $params) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         Assert::stringNotEmpty($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         Assert::notEmpty($patterns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $params['user'] = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $params['pattern'] = implode(',', $patterns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $response = $this->httpGet('/api/match/self-description', $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         return $this->hydrateResponse($response, SelfDescription::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @param $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @param array $patterns | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @param array $params   valid keys are norm and limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @return TopPattern|ResponseInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 85 |  | View Code Duplication |     public function topPatterns($user, array $patterns, array $params) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         Assert::stringNotEmpty($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         Assert::notEmpty($patterns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $params['user'] = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $params['pattern'] = implode(',', $patterns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $response = $this->httpGet('/api/match/top/patterns', $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         return $this->hydrateResponse($response, TopPattern::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @param $pattern | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @param array $params valid keys are limit, offset and norm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @return TopUser|ResponseInterface | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 103 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 104 |  |  |     public function topUser($pattern, array $params) | 
            
                                                        
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |         Assert::stringNotEmpty($pattern); | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |         $params['pattern'] = $pattern; | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |         $response = $this->httpGet('/api/match/top/users', $params); | 
            
                                                        
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |         return $this->hydrateResponse($response, TopUser::class); | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 114 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |  | 
            
                        
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.