filesystem = $filesystem; $this->localRepository = $localRepository; $this->io = $io; $this->installationManager = $installationManager; $this->composerFilesystem = $composerFilesystem; $this->configurationFile = $configurationFile; } public function install() : void { $oldGeneratedConfigFileHash = null; if ($this->filesystem->isFile($this->configurationFile)) { $oldGeneratedConfigFileHash = $this->filesystem->hashFile($this->configurationFile); } $installedPackages = []; $data = []; foreach ($this->localRepository->getPackages() as $package) { if ($this->shouldSkip($package)) { continue; } $absoluteInstallPath = $this->installationManager->getInstallPath($package); $data[$package->getName()] = ['install_path' => $absoluteInstallPath, 'relative_install_path' => $this->composerFilesystem->findShortestPath(\dirname($this->configurationFile), $absoluteInstallPath, \true), 'extra' => $package->getExtra()[self::RECTOR_EXTRA_KEY] ?? null, 'version' => $package->getFullPrettyVersion()]; $installedPackages[$package->getName()] = \true; } \ksort($data); \ksort($installedPackages); $generatedConfigFileContents = \sprintf(self::$generatedFileTemplate, \var_export($data, \true), \true); if ($this->filesystem->hashEquals((string) $oldGeneratedConfigFileHash, $generatedConfigFileContents)) { return; } $this->filesystem->writeFile($this->configurationFile, $generatedConfigFileContents); $this->io->write('rector/rector-installer: Extensions installed'); foreach (\array_keys($installedPackages) as $name) { $this->io->write(\sprintf('> %s: installed', $name)); } } private function shouldSkip(PackageInterface $package) : bool { if ($package->getType() === self::RECTOR_EXTENSION_TYPE) { return \false; } if (isset($package->getExtra()[self::RECTOR_EXTRA_KEY])) { return \false; } return \true; } }