| Conditions | 4 |
| Paths | 8 |
| Total Lines | 96 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 110 | public function createPhar() |
||
| 111 | { |
||
| 112 | |||
| 113 | // prepare the PHAR archive name |
||
| 114 | $archiveName = sprintf( |
||
| 115 | '%s/%s.phar', |
||
| 116 | $this->properties['target.dir'], |
||
| 117 | $this->properties['webapp.name'] |
||
| 118 | ); |
||
| 119 | |||
| 120 | // prepare the target directory |
||
| 121 | $targetDir = $this->properties['target.dir'] . DIRECTORY_SEPARATOR . $this->properties['webapp.version']; |
||
| 122 | |||
| 123 | // copy the composer.json file |
||
| 124 | $this->taskFilesystemStack() |
||
| 125 | ->copy( |
||
| 126 | __DIR__ . DIRECTORY_SEPARATOR . 'composer.json', |
||
| 127 | $targetDir. DIRECTORY_SEPARATOR. 'composer.json' |
||
| 128 | )->run(); |
||
| 129 | |||
| 130 | // copy the composer.json file |
||
| 131 | $this->taskFilesystemStack() |
||
| 132 | ->copy( |
||
| 133 | __DIR__ . DIRECTORY_SEPARATOR . '.semver', |
||
| 134 | $targetDir. DIRECTORY_SEPARATOR. '.semver' |
||
| 135 | )->run(); |
||
| 136 | |||
| 137 | // copy the src/etc directory |
||
| 138 | $this->taskCopyDir( |
||
| 139 | array( |
||
| 140 | $this->properties['src.dir'] => $targetDir . DIRECTORY_SEPARATOR . 'src', |
||
| 141 | $this->properties['etc.dir'] => $targetDir . DIRECTORY_SEPARATOR . 'etc' |
||
| 142 | ) |
||
| 143 | )->run(); |
||
| 144 | |||
| 145 | // install the composer dependencies |
||
| 146 | $this->taskComposerInstall() |
||
| 147 | ->dir($targetDir) |
||
| 148 | ->noDev() |
||
| 149 | ->optimizeAutoloader() |
||
| 150 | ->run(); |
||
| 151 | |||
| 152 | // prepare the task |
||
| 153 | $pharTask = $this->taskPackPhar($archiveName) |
||
| 154 | ->compress() |
||
| 155 | ->stub('stub.php'); |
||
| 156 | |||
| 157 | // load a list with all the source files |
||
| 158 | $finder = Finder::create() |
||
| 159 | ->name('*.php') |
||
| 160 | ->in($targetDir . DIRECTORY_SEPARATOR . 'src'); |
||
| 161 | |||
| 162 | // iterate over the source files and add them to the PHAR archive |
||
| 163 | foreach ($finder as $file) { |
||
| 164 | $pharTask->addFile('src/' . $file->getRelativePathname(), $file->getRealPath()); |
||
| 165 | } |
||
| 166 | |||
| 167 | // load a list with all the source files from the vendor directory |
||
| 168 | $finder = Finder::create()->files() |
||
| 169 | ->name('*.php') |
||
| 170 | ->name('services.xml') |
||
| 171 | ->name('services-1.0.xsd') |
||
| 172 | ->name('techdivision-import.json') |
||
| 173 | ->in($targetDir . DIRECTORY_SEPARATOR . 'vendor'); |
||
| 174 | |||
| 175 | // iterate over the source files of the vendor directory and add them to the PHAR archive |
||
| 176 | foreach ($finder as $file) { |
||
| 177 | $pharTask->addFile('vendor/' . $file->getRelativePathname(), $file->getRealPath()); |
||
| 178 | } |
||
| 179 | |||
| 180 | // load a list with all the DI configuration files from the etc directory |
||
| 181 | $finder = Finder::create()->files() |
||
| 182 | ->name('*.xml') |
||
| 183 | ->in($targetDir . DIRECTORY_SEPARATOR . 'etc'); |
||
| 184 | |||
| 185 | // iterate over the DI configuration files of the etc directory and add them to the PHAR archive |
||
| 186 | foreach ($finder as $file) { |
||
| 187 | $pharTask->addFile('etc/' . $file->getRelativePathname(), $file->getRealPath()); |
||
| 188 | } |
||
| 189 | |||
| 190 | // add the semver file and create the PHAR archive |
||
| 191 | $pharTask->addFile('.semver', realpath($targetDir. DIRECTORY_SEPARATOR. '.semver')); |
||
| 192 | $pharTask->run(); |
||
| 193 | |||
| 194 | // verify PHAR archive is packed correctly |
||
| 195 | $this->_exec(sprintf('php %s', $archiveName)); |
||
| 196 | |||
| 197 | // prepare the PHAR archive distribution name |
||
| 198 | $distArchiveName = sprintf('%s/%s.phar', $this->properties['dist.dir'], $this->properties['webapp.name']); |
||
| 199 | |||
| 200 | // clean up the dist directory |
||
| 201 | $this->taskCleanDir($this->properties['dist.dir'])->run(); |
||
| 202 | |||
| 203 | // copy the latest PHAR archive to the dist directory |
||
| 204 | $this->taskFilesystemStack()->copy($archiveName, $distArchiveName)->run(); |
||
| 205 | } |
||
| 206 | |||
| 306 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.