| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Part of ci-phpunit-test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author     Kenji Suzuki <https://github.com/kenjis> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license    MIT License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @copyright  2015 Kenji Suzuki | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @link       https://github.com/kenjis/ci-phpunit-test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class Installer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     private $silent = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     private $app_dir = 'application';  // -a DIRECTORY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $pub_dir = 'public';       // -p DIRECTORY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $test_dir = null;          // -t DIRECTORY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     private $from_composer = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function __construct($argv) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->parse_args($argv); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     private function parse_args($argv) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $argc = count($argv); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         if ($argc === 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         for ($i = 1; $i <= $argc; $i++) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             if (! isset($argv[$i])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             switch ($argv[$i]) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 // php install.php -s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 case '-s': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                     $this->silent = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 // php install.php -a application | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 44 |  | View Code Duplication |                 case '-a': | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                     if (is_dir($argv[$i+1])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                         $this->app_dir = $argv[$i+1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                         throw new Exception('No such application directory: '.$argv[$i+1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                     $i++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 // php install.php -p public | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 54 |  | View Code Duplication |                 case '-p': | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                     if (is_dir($argv[$i+1])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                         $this->pub_dir = $argv[$i+1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                         throw new Exception('No such public directory: '.$argv[$i+1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                     $i++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 // php install.php -t application/tests | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 64 |  | View Code Duplication |                 case '-t': | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                     if (is_dir($argv[$i+1])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                         $this->test_dir = $argv[$i+1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                         throw new Exception('No such test directory: '.$argv[$i+1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                     $i++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 case '--from-composer': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                     $this->from_composer = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                     throw new Exception('Unknown argument: '.$argv[$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         if (is_null($this->test_dir)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $this->test_dir = $this->app_dir.'/tests'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     public function install() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->recursiveCopy( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             dirname(dirname(__FILE__)).'/application/tests', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             $this->test_dir | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->fixPath(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         if ($this->from_composer) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             $this->recursiveUnlink($this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * Fix paths in Bootstrap.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @FIXME Too ad hoc. Must rewrite, because can't handle complex paths. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     private function fixPath() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $file = $this->test_dir.'/Bootstrap.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $contents = file_get_contents($file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         if (! file_exists('system')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             if (file_exists('vendor/codeigniter/framework/system')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                 $contents = str_replace( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                     '$system_path = \'../../system\';', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                     '$system_path = \'../../vendor/codeigniter/framework/system\';', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                     $contents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                 throw new Exception('Can\'t find "system" folder.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         if (! file_exists('index.php')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             if (file_exists($this->pub_dir.'/index.php')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                 // CodeIgniter 3.0.6 and after | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                 $contents = str_replace( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                     "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                     "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').DIRECTORY_SEPARATOR);", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                     $contents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 // CodeIgniter 3.0.5 and before | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 $contents = str_replace( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                     "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                     "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').'/');", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                     $contents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             } elseif (file_exists($this->app_dir.'/public/index.php')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                 // CodeIgniter 3.0.6 and after | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                 $contents = str_replace( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                     "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                     "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                     $contents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                 // CodeIgniter 3.0.5 and before | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                 $contents = str_replace( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                     "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                     "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                     $contents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                 if ($this->app_dir !== 'application') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                     $contents = str_replace( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                         "\$application_folder = '../../application';", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |                         "\$application_folder = '../../{$this->app_dir}';", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                         $contents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |                 throw new Exception('Can\'t find "index.php".'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         file_put_contents($file, $contents); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     public function update() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         $target_dir = $this->test_dir.'/_ci_phpunit_test'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $this->recursiveUnlink($target_dir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         $this->recursiveCopy( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             dirname(dirname(__FILE__)).'/application/tests/_ci_phpunit_test', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |             $target_dir | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |      * Recursive Copy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * @param string $src | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * @param string $dst | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 178 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  |     private function recursiveCopy($src, $dst) | 
            
                                                                        
                            
            
                                    
            
            
                | 180 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 181 |  |  |         @mkdir($dst, 0755); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 183 |  |  |         $iterator = new \RecursiveIteratorIterator( | 
            
                                                                        
                            
            
                                    
            
            
                | 184 |  |  |             new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), | 
            
                                                                        
                            
            
                                    
            
            
                | 185 |  |  |             \RecursiveIteratorIterator::SELF_FIRST | 
            
                                                                        
                            
            
                                    
            
            
                | 186 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 188 |  |  |         foreach ($iterator as $file) { | 
            
                                                                        
                            
            
                                    
            
            
                | 189 |  |  |             if ($file->isDir()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 190 |  |  |                 @mkdir($dst.'/'.$iterator->getSubPathName()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 191 |  |  |             } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 192 |  |  |                 $success = copy($file, $dst.'/'.$iterator->getSubPathName()); | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  |                 if ($success) { | 
            
                                                                        
                            
            
                                    
            
            
                | 194 |  |  |                     if (! $this->silent) { | 
            
                                                                        
                            
            
                                    
            
            
                | 195 |  |  |                         echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  |                     } | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |      * Recursive Unlink | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |      * @param string $dir | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 207 |  | View Code Duplication |     private function recursiveUnlink($dir) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         $iterator = new \RecursiveIteratorIterator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |             new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |             \RecursiveIteratorIterator::CHILD_FIRST | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         foreach ($iterator as $file) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |             if ($file->isDir()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |                 rmdir($file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |                 unlink($file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         rmdir($dir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 224 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 225 |  |  |  | 
            
                        
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.