| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the LaravelYaml package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Théo FIDRY <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Fidry\LaravelYaml\FileLoader\Parser\Yaml\Util; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Fidry\LaravelYaml\DependencyInjection\Definition\Decoration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Fidry\LaravelYaml\DependencyInjection\Definition\DecorationInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Fidry\LaravelYaml\DependencyInjection\Definition\ServiceInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Fidry\LaravelYaml\Exception\FileLoader\InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @author Théo FIDRY <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | final class DecorationParser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * Parses a factory service definition and return the decoration object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param ServiceInterface $service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @param mixed            $decoration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param string           $fileName file name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @return DecorationInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @throws InvalidArgumentException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 34 | 2 |  |     public function parse(ServiceInterface $service, $decoration, $fileName) | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                        
            
                                                                    
                                                                                                        
            
            
                | 36 | 2 | View Code Duplication |         if (false === is_string($decoration['decorates'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |             throw new InvalidArgumentException( | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |                 sprintf( | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |                     'Parameter "decorates" for service "%s" must be the id of another service, but found "%s" instead in %s. Check your YAML syntax.', | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |                     $service->getName(), | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |                     gettype($decoration['decorates']), | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |                     $fileName | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |                 ) | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |             ); | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 46 | 2 |  |         $decorates = $decoration['decorates']; | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 48 | 2 |  |         $decorationInnerName = (isset($decoration['decoration_inner_name'])) | 
            
                                                        
            
                                    
            
            
                | 49 | 2 |  |             ? $decoration['decoration_inner_name'] | 
            
                                                        
            
                                    
            
            
                | 50 | 2 |  |             : null | 
            
                                                        
            
                                    
            
            
                | 51 | 1 |  |         ; | 
            
                                                        
            
                                                                    
                                                                                                        
            
            
                | 52 | 2 | View Code Duplication |         if (null !== $decorationInnerName && false === is_string($decorationInnerName)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |             throw new InvalidArgumentException( | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |                 sprintf( | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |                     'Parameter "decoration_inner_name" for service "%s" must be a string if is set, but found "%s" instead in %s. Check your YAML syntax.', | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |                     $service->getName(), | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |                     gettype($decorationInnerName), | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |                     $fileName | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |                 ) | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |             ); | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 63 | 2 |  |         return new Decoration($service, $decorates, $decorationInnerName); | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  | 
            
                        
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.