| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * RoboKassa driver for Omnipay PHP payment library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @link      https://github.com/hiqdev/omnipay-robokassa | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @package   omnipay-robokassa | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license   MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace Omnipay\RoboKassa\Message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class PurchaseRequest extends AbstractRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public function getData() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $this->validate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |             'purse', 'amount', 'currency', 'description' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             'MrchLogin' => $this->getPurse(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             'OutSum' => $this->getAmount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             'Desc' => $this->getDescription(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             'IncCurrLabel' => $this->getCurrency(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             'SignatureValue' => $this->generateSignature(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         ] + $this->getCustomFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 30 |  | View Code Duplication |     public function generateSignature() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             $this->getPurse(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $this->getAmount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             $this->getSecretKey() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         foreach ($this->getCustomFields() as $field => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             $params[] = "$field=$value"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         return md5(implode(':', $params)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 46 |  | View Code Duplication |     public function getCustomFields() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $fields = array_filter([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             'Shp_TransactionId' => $this->getTransactionId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'Shp_Client' => $this->getClient(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             'Shp_Currency' => $this->getCurrency() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         ksort($fields); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return $fields; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function sendData($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         return $this->response = new PurchaseResponse($this, $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                        
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.