Conditions | 3 |
Paths | 4 |
Total Lines | 85 |
Code Lines | 47 |
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 | ) |
||
142 | )->run(); |
||
143 | |||
144 | // install the composer dependencies |
||
145 | $this->taskComposerInstall() |
||
146 | ->dir($targetDir) |
||
147 | ->noDev() |
||
148 | ->optimizeAutoloader() |
||
149 | ->run(); |
||
150 | |||
151 | // prepare the task |
||
152 | $pharTask = $this->taskPackPhar($archiveName) |
||
153 | ->compress() |
||
154 | ->stub('stub.php'); |
||
155 | |||
156 | // load a list with all the source files |
||
157 | $finder = Finder::create() |
||
158 | ->name('*.php') |
||
159 | ->in($targetDir . DIRECTORY_SEPARATOR . 'src'); |
||
160 | |||
161 | // iterate over the source files and add them to the PHAR archive |
||
162 | foreach ($finder as $file) { |
||
163 | $pharTask->addFile('src/' . $file->getRelativePathname(), $file->getRealPath()); |
||
164 | } |
||
165 | |||
166 | // load a list with all the source files from the vendor directory |
||
167 | $finder = Finder::create()->files() |
||
168 | ->name('*.php') |
||
169 | ->name('services.xml') |
||
170 | ->name('services-1.0.xsd') |
||
171 | ->name('techdivision-import.json') |
||
172 | ->in($targetDir . DIRECTORY_SEPARATOR . 'vendor'); |
||
173 | |||
174 | // iterate over the source files of the vendor directory and add them to the PHAR archive |
||
175 | foreach ($finder as $file) { |
||
176 | $pharTask->addFile('vendor/' . $file->getRelativePathname(), $file->getRealPath()); |
||
177 | } |
||
178 | |||
179 | // add the semver file and create the PHAR archive |
||
180 | $pharTask->addFile('.semver', realpath($targetDir. DIRECTORY_SEPARATOR. '.semver')); |
||
181 | $pharTask->run(); |
||
182 | |||
183 | // verify PHAR archive is packed correctly |
||
184 | $this->_exec(sprintf('php %s', $archiveName)); |
||
185 | |||
186 | // prepare the PHAR archive distribution name |
||
187 | $distArchiveName = sprintf('%s/%s.phar', $this->properties['dist.dir'], $this->properties['webapp.name']); |
||
188 | |||
189 | // clean up the dist directory |
||
190 | $this->taskCleanDir($this->properties['dist.dir'])->run(); |
||
191 | |||
192 | // copy the latest PHAR archive to the dist directory |
||
193 | $this->taskFilesystemStack()->copy($archiveName, $distArchiveName)->run(); |
||
194 | } |
||
195 | |||
294 |
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.