| Conditions | 14 | 
| Paths | 324 | 
| Total Lines | 67 | 
| Code Lines | 33 | 
| Lines | 4 | 
| Ratio | 5.97 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 54 |     public function run() { | 
            ||
| 55 | View Code Duplication | if (!is_dir($_SERVER['HOME'].'/rpmbuild/SOURCES'))  | 
            |
| 56 | mkdir($_SERVER['HOME'].'/rpmbuild/SOURCES', 0777);  | 
            ||
| 57 | View Code Duplication | if (!is_dir($_SERVER['HOME'].'/rpmbuild/SPECS'))  | 
            |
| 58 | mkdir($_SERVER['HOME'].'/rpmbuild/SPECS', 0777);  | 
            ||
| 59 | |||
| 60 |         if (file_exists($this->getOutputPath())) { | 
            ||
| 61 | $iterator = new DirectoryIterator($this->getOutputPath());  | 
            ||
| 62 |             foreach ($iterator as $path) { | 
            ||
| 63 |                 if ($path != '.' && $path != '..') { | 
            ||
| 64 | echo "OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!" . PHP_EOL;  | 
            ||
| 65 | exit();  | 
            ||
| 66 | }  | 
            ||
| 67 | }  | 
            ||
| 68 | }  | 
            ||
| 69 | |||
| 70 | if (!is_dir($this->getOutputPath()))  | 
            ||
| 71 | mkdir($this->getOutputPath(), 0777);  | 
            ||
| 72 | |||
| 73 |         foreach ($this->mountPoints as $path => $dest) { | 
            ||
| 74 | $this->pathToPath($path, $this->getOutputPath().DIRECTORY_SEPARATOR.$dest);  | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 | $spec = $this->_spec;  | 
            ||
| 78 |         $spec->setPrep('%autosetup -c package'); | 
            ||
| 79 |         $install_section = 'rm -rf %{buildroot}'."\n".'mkdir -p %{buildroot}'."\n".'cp -rp * %{buildroot}'; | 
            ||
| 80 | $spec->setInstall($install_section);  | 
            ||
| 81 | |||
| 82 | $files_section = null;  | 
            ||
| 83 |         foreach ($this->mountPoints as $sourcePath => $destinationPath) { | 
            ||
| 84 |             if (is_dir($sourcePath)) { | 
            ||
| 85 | $files_section .= (strlen($files_section) > 0 ? "\n" : null).rtrim($destinationPath, '/').'/';  | 
            ||
| 86 |             } else { | 
            ||
| 87 |                 $files_section .= (strlen($files_section) > 0 ? "\n" : null).'%attr('.substr(sprintf('%o', fileperms($sourcePath)), -4).',root,root) '.$destinationPath; | 
            ||
| 88 | }  | 
            ||
| 89 | }  | 
            ||
| 90 | |||
| 91 | $spec->setFiles($files_section);  | 
            ||
| 92 | // $used_dirs = array();  | 
            ||
| 93 |         // foreach ($this->mountPoints as $source => $dest) { | 
            ||
| 94 |         //     if (is_dir($source)) { | 
            ||
| 95 | // $files[] = $dest;  | 
            ||
| 96 |         //     } else { | 
            ||
| 97 | // $dir = dirname($dest);  | 
            ||
| 98 | // // directory exists on a real machine - add files one by one  | 
            ||
| 99 |         //         if (is_dir($dir)) { | 
            ||
| 100 | // $files[] = $dest;  | 
            ||
| 101 |         //         } else { // add all files within directory | 
            ||
| 102 |         //             if (!in_array($dir, $files)) { | 
            ||
| 103 | // $files[] = $dir;  | 
            ||
| 104 | // }  | 
            ||
| 105 | // }  | 
            ||
| 106 | // }  | 
            ||
| 107 | // }  | 
            ||
| 108 |         // $spec->setFiles(implode("\n", $files)); | 
            ||
| 109 | |||
| 110 |         if (file_exists($_SERVER['HOME'].'/rpmbuild/SOURCES/'.$this->_spec->Name.'.tar')) { | 
            ||
| 111 | unlink($_SERVER['HOME'].'/rpmbuild/SOURCES/'.$this->_spec->Name.'.tar');  | 
            ||
| 112 | }  | 
            ||
| 113 | $tar = new PharData($_SERVER['HOME'].'/rpmbuild/SOURCES/'.$this->_spec->Name.'.tar');  | 
            ||
| 114 | $tar->buildFromDirectory($this->outputPath);  | 
            ||
| 115 |         $spec->setKey('Source0', $this->_spec->Name.'.tar'); | 
            ||
| 116 | |||
| 117 | file_put_contents($_SERVER['HOME'].'/rpmbuild/SPECS/'.$this->_spec->Name.'.spec', (string)$this->_spec);  | 
            ||
| 118 | |||
| 119 | return $this;  | 
            ||
| 120 | }  | 
            ||
| 121 | |||
| 154 | }  | 
            
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: