| Conditions | 16 |
| Paths | 6 |
| Total Lines | 55 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 2 | Features | 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 |
||
| 116 | public function onAfterBuild() |
||
| 117 | { |
||
| 118 | // Mock COMPOSER_HOME if it's not defined already. Composer requires one of the two to be set. |
||
| 119 | if (!Environment::getEnv('COMPOSER_HOME')) { |
||
| 120 | $home = Environment::getEnv('HOME'); |
||
| 121 | if (!$home || !is_dir($home) || !is_writable($home)) { |
||
| 122 | // Set our own directory |
||
| 123 | putenv('COMPOSER_HOME=' . sys_get_temp_dir()); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | $originalDir = getcwd(); |
||
| 128 | chdir(BASE_PATH); |
||
| 129 | /** @var Composer $composer */ |
||
| 130 | $composer = Factory::create($io = new NullIO()); |
||
| 131 | |||
| 132 | // Don't include inaccessible repositories. |
||
| 133 | $inaccessiblePackages = (array)UpdatePackageInfoTask::config()->get('inaccessible_packages'); |
||
| 134 | $inaccessibleHosts = (array)UpdatePackageInfoTask::config()->get('inaccessible_repository_hosts'); |
||
| 135 | if (!empty($doNotFetch) || !empty($doNotFetchHosts)) { |
||
| 136 | $oldManager = $composer->getRepositoryManager(); |
||
| 137 | $manager = new RepositoryManager( |
||
| 138 | $io, |
||
| 139 | $composer->getConfig(), |
||
| 140 | $composer->getEventDispatcher(), |
||
| 141 | Factory::createRemoteFilesystem($io, $composer->getConfig()) |
||
| 142 | ); |
||
| 143 | $manager->setLocalRepository($oldManager->getLocalRepository()); |
||
| 144 | foreach ($oldManager->getRepositories() as $repo) { |
||
| 145 | if ($repo instanceof VcsRepository) { |
||
| 146 | /** @var VcsDriverInterface $driver */ |
||
| 147 | $driver = DriverReflection::getDriverWithoutException($repo); |
||
| 148 | $sshUrl = DriverReflection::getSshUrl($driver); |
||
| 149 | $sourceURL = $driver->getUrl(); |
||
| 150 | $package = $this->findPackageByUrl($sourceURL); |
||
| 151 | if (!$package && $sshUrl) { |
||
| 152 | $package = $this->findPackageByUrl($sshUrl); |
||
| 153 | } |
||
| 154 | // Don't add the repository if we can confirm it's inaccessible. |
||
| 155 | // Otherwise the UpdateChecker will attempt to fetch packages using the VcsDriver. |
||
| 156 | if ( |
||
| 157 | ($package && in_array($package->name, $inaccessiblePackages)) |
||
| 158 | || in_array(parse_url($sourceURL, PHP_URL_HOST), $inaccessibleHosts) |
||
| 159 | || ($sshUrl && in_array(preg_replace('/^([^@]+@)?([^:]+):.*/', '$2', $sshUrl), $inaccessibleHosts)) |
||
| 160 | ) { |
||
| 161 | continue; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | $manager->addRepository($repo); |
||
| 165 | } |
||
| 166 | $composer->setRepositoryManager($manager); |
||
| 167 | } |
||
| 168 | |||
| 169 | $this->setComposer($composer); |
||
| 170 | chdir($originalDir); |
||
| 171 | } |
||
| 196 |