| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the CS library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Copyright (c) 2015-present LIN3S <[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 LIN3S\CS\Composer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use LIN3S\CS\Application; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use LIN3S\CS\Checker\EsLint; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use LIN3S\CS\Checker\PhpCsFixer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use LIN3S\CS\Checker\ScssLint; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\Filesystem\Filesystem; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @author Beñat Espiña <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | final class Hooks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 25 |  | View Code Duplication |     public static function addHooks() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $hooksDirectory = self::rootDir() . '/.git/hooks'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $fileSystem = new Filesystem(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             if ($fileSystem->exists($hooksDirectory)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 $fileSystem->remove($hooksDirectory); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $fileSystem->symlink(__DIR__ . '/../Hooks', $hooksDirectory, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         } catch (\Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             echo sprintf("Something wrong happens during the symlink process: \n%s\n", $exception->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 40 |  | View Code Duplication |     public static function buildDistFile() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $distFile = self::rootDir() . '/.lin3s_cs.yml.dist'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $fileSystem = new Filesystem(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             if ($fileSystem->exists($distFile)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $fileSystem->copy(self::lin3sCsRootDir() . '/.lin3s_cs.yml.dist', $distFile); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         } catch (\Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             echo sprintf("Something wrong happens during the touch process: \n%s\n", $exception->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public static function addFiles() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $app = new Application(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ScssLint::file($app->parameters()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         EsLint::file($app->parameters()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         PhpCsFixer::file($app->parameters()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $editorConfig = self::rootDir() . '/.editorconfig'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $fileSystem = new Filesystem(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             $fileSystem->remove($editorConfig); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             $fileSystem->symlink(self::lin3sCsRootDir() . '/.editorconfig', $editorConfig, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         } catch (\Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             echo sprintf("Something wrong happens during the symlink process: \n%s\n", $exception->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     private function rootDir() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         return __DIR__ . '/../../../../../../..'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |     private function lin3sCsRootDir() | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |         return __DIR__ . '/../..'; | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  | 
            
                        
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.