| Conditions | 10 |
| Paths | 12 |
| Total Lines | 140 |
| Code Lines | 103 |
| 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 |
||
| 34 | public function main() |
||
| 35 | { |
||
| 36 | require_once('PEAR/PackageFileManager2.php'); |
||
| 37 | require_once('PEAR/Exception.php'); |
||
| 38 | PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'PEAR_ErrorToPEAR_Exception'); |
||
| 39 | if (!$this->baseDir || !file_exists($this->baseDir)) { |
||
| 40 | throw new BuildException('Base directory is not defined or does not exist.'); |
||
| 41 | } |
||
| 42 | |||
| 43 | if (!$this->buildDir || !file_exists($this->buildDir)) { |
||
| 44 | throw new BuildException('Build directory is not defined or does not exist.'); |
||
| 45 | } |
||
| 46 | |||
| 47 | set_time_limit(0); |
||
| 48 | |||
| 49 | $this->log("Adding .keep files to empty directories", PROJECT_MSG_INFO); |
||
| 50 | |||
| 51 | foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath('samples')), RecursiveIteratorIterator::CHILD_FIRST) as $dir) { |
||
| 52 | if ($dir->isDir()) { |
||
| 53 | foreach (new DirectoryIterator($dir->getPathname()) as $d) { |
||
| 54 | if (!in_array($d->getFilename(), array('.', '..'))) { |
||
| 55 | continue 2; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | touch($dir->getPathname() . '/.keep'); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | $this->log("Building package contents in: {$this->dir}", PROJECT_MSG_INFO); |
||
| 63 | |||
| 64 | $version = $this->project->getProperty('agavi.pear.version'); |
||
| 65 | $status = $this->project->getProperty('agavi.status'); |
||
| 66 | |||
| 67 | // Modify short description. Try to keep under 80 chars width |
||
| 68 | $shortDesc = <<<EOD |
||
| 69 | PHP5 MVC Application Framework |
||
| 70 | EOD; |
||
| 71 | |||
| 72 | // Modify long description. Try to keep under 80 chars width |
||
| 73 | $longDesc = <<<EOD |
||
| 74 | Agavi is a full-featured MVC-style framework for PHP5 with a strong focus on structure, code reusability and flexibility. |
||
| 75 | EOD; |
||
| 76 | |||
| 77 | $p2 = new PEAR_PackageFileManager2; |
||
| 78 | $p2->setOptions(array( |
||
| 79 | 'filelistgenerator' => 'file', |
||
| 80 | 'outputdirectory' => $this->baseDir, |
||
| 81 | 'packagedirectory' => $this->buildDir, |
||
| 82 | 'baseinstalldir' => 'agavi', |
||
| 83 | 'ignore' => array( |
||
| 84 | '.svn/', |
||
| 85 | ), |
||
| 86 | 'addhiddenfiles' => true, |
||
| 87 | 'dir_roles' => array( |
||
| 88 | '/' => 'php', |
||
| 89 | 'bin' => 'script', |
||
| 90 | 'samples' => 'data', |
||
| 91 | ), |
||
| 92 | 'installexceptions' => array( |
||
| 93 | 'bin/agavi-dist' => '/', |
||
| 94 | 'bin/agavi.bat-dist' => '/', |
||
| 95 | ), |
||
| 96 | 'exceptions' => array( |
||
| 97 | 'API_CHANGELOG' => 'doc', |
||
| 98 | 'CHANGELOG' => 'doc', |
||
| 99 | 'COPYRIGHT' => 'doc', |
||
| 100 | 'INSTALL' => 'doc', |
||
| 101 | 'LICENSE' => 'doc', |
||
| 102 | 'LICENSE-AGAVI' => 'doc', |
||
| 103 | 'LICENSE-ICU' => 'doc', |
||
| 104 | 'LICENSE-SCHEMATRON' => 'doc', |
||
| 105 | 'LICENSE-UNICODE_CLDR' => 'doc', |
||
| 106 | 'RELEASE_NOTES' => 'doc', |
||
| 107 | 'UPGRADING' => 'doc', |
||
| 108 | ), |
||
| 109 | )); |
||
| 110 | $p2->setPackageType('php'); |
||
| 111 | $p2->setPackage('agavi'); |
||
| 112 | $p2->addMaintainer('lead', 'david', 'David Zülke', '[email protected]'); |
||
| 113 | $p2->addMaintainer('developer', 'dominik', 'Dominik del Bondio', '[email protected]'); |
||
| 114 | $p2->addMaintainer('developer', 'felix', 'Felix Gilcher', '[email protected]'); |
||
| 115 | $p2->addMaintainer('developer', 'impl', 'Noah Fontes', '[email protected]'); |
||
| 116 | $p2->addMaintainer('developer', 'v-dogg', 'Veikko Mäkinen', '[email protected]'); |
||
| 117 | $p2->setChannel('pear.agavi.org'); |
||
| 118 | $p2->setReleaseVersion($version); |
||
| 119 | $p2->setAPIVersion($version); |
||
| 120 | $p2->setReleaseStability($status); |
||
| 121 | $p2->setAPIStability($status); |
||
| 122 | $p2->setSummary($shortDesc); |
||
| 123 | $p2->setDescription($longDesc); |
||
| 124 | $p2->setNotes("To see what's new, please refer to the RELEASE_NOTES. Also, the CHANGELOG contains a full list of changes.\n\nFor installation instructions, consult INSTALL. Information on how to migrate applications written using previous releases can be found in UPGRADING."); |
||
| 125 | |||
| 126 | // this must be the most stupid syntax I've ever seen. |
||
| 127 | $p2->addRelease(); |
||
| 128 | $p2->setOSInstallCondition('windows'); |
||
| 129 | $p2->addInstallAs('bin/agavi.bat-dist', 'agavi.bat'); |
||
| 130 | $p2->addIgnoreToRelease('bin/agavi-dist'); |
||
| 131 | |||
| 132 | // and the next release... very cool, eh? how utterly stupid is that |
||
| 133 | $p2->addRelease(); |
||
| 134 | $p2->addInstallAs('bin/agavi-dist', 'agavi'); |
||
| 135 | $p2->addIgnoreToRelease('bin/agavi.bat-dist'); |
||
| 136 | |||
| 137 | $p2->addPackageDepWithChannel('required', 'phing', 'pear.phing.info', '2.4.0'); |
||
| 138 | $p2->addPackageDepWithChannel('optional', 'PHPUnit', 'pear.phpunit.de', '3.7.0'); |
||
| 139 | |||
| 140 | $p2->addConflictingPackageDepWithChannel('phing', 'pear.php.net'); |
||
| 141 | |||
| 142 | $p2->setPhpDep('5.2.0'); |
||
| 143 | |||
| 144 | $p2->addExtensionDep('required', 'dom'); |
||
| 145 | $p2->addExtensionDep('required', 'libxml'); |
||
| 146 | $p2->addExtensionDep('required', 'SPL'); |
||
| 147 | $p2->addExtensionDep('required', 'Reflection'); |
||
| 148 | $p2->addExtensionDep('required', 'pcre'); |
||
| 149 | $p2->addExtensionDep('optional', 'xsl'); |
||
| 150 | $p2->addExtensionDep('optional', 'tokenizer'); |
||
| 151 | $p2->addExtensionDep('optional', 'session'); |
||
| 152 | $p2->addExtensionDep('optional', 'xmlrpc'); |
||
| 153 | $p2->addExtensionDep('optional', 'PDO'); |
||
| 154 | $p2->addExtensionDep('optional', 'iconv'); |
||
| 155 | $p2->addExtensionDep('optional', 'gettext'); |
||
| 156 | |||
| 157 | $p2->setPearinstallerDep('1.4.0'); |
||
| 158 | |||
| 159 | $p2->setLicense('LGPL', 'http://www.gnu.org/copyleft/lesser.html'); |
||
| 160 | |||
| 161 | $p2->addReplacement('bin/agavi-dist', 'pear-config', '@PEAR-DIR@', 'php_dir'); |
||
| 162 | $p2->addReplacement('bin/agavi-dist', 'pear-config', '@PHP-BIN@', 'php_bin'); |
||
| 163 | $p2->addReplacement('bin/agavi.bat-dist', 'pear-config', '@PEAR-DIR@', 'php_dir'); |
||
| 164 | $p2->addReplacement('bin/agavi.bat-dist', 'pear-config', '@PHP-BIN@', 'php_bin'); |
||
| 165 | $p2->addReplacement('src/build/build.xml', 'pear-config', '@PEAR-DIR@', 'php_dir'); |
||
| 166 | $p2->generateContents(); |
||
| 167 | |||
| 168 | try { |
||
| 169 | $p2->writePackageFile(); |
||
| 170 | } catch (PEAR_Exception $e) { |
||
| 171 | $this->log("Oops! Caught PEAR Exception: ".$e->getMessage()); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | } |
||
| 183 |
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.