Check all installed packages (including the root package) against
the installed paths from PHP_CodeSniffer and add the missing ones.

@return bool True if changes where made, false otherwise

@throws \InvalidArgumentException
@throws \RuntimeException
184021
private function updateInstalledPaths()
    {
        $changes = false;

        $searchPaths = array($this->cwd);
        $codingStandardPackages = $this->getPHPCodingStandardPackages();
        foreach ($codingStandardPackages as $package) {
            $installPath = $this->composer->getInstallationManager()->getInstallPath($package);
            if ($this->filesystem->isAbsolutePath($installPath) === false) {
                $installPath = $this->filesystem->normalizePath(
                    $this->cwd . DIRECTORY_SEPARATOR . $installPath
                );
            }
            $searchPaths[] = $installPath;
        }

        $finder = new Finder();
        $finder->files()
            ->depth('<= ' . $this->getMaxDepth())
            ->depth('>= ' . $this->getMinDepth())
            ->ignoreUnreadableDirs()
            ->ignoreVCS(true)
            ->in($searchPaths)
            ->name('ruleset.xml');

        // Process each found possible ruleset.
        foreach ($finder as $ruleset) {
            $standardsPath = $ruleset->getPath();

            // Pick the directory above the directory containing the standard, unless this is the project root.
            if ($standardsPath !== $this->cwd) {
                $standardsPath = dirname($standardsPath);
            }

            // Use relative paths for local project repositories.
            if ($this->isRunningGlobally() === false) {
                $standardsPath = $this->filesystem->findShortestPath(
                    $this->getPHPCodeSnifferInstallPath(),
                    $standardsPath,
                    true
                );
            }

            // De-duplicate and add when directory is not configured.
            if (in_array($standardsPath, $this->installedPaths, true) === false) {
                $this->installedPaths[] = $standardsPath;
                $changes = true;
            }
        }

        return $changes;
    }
210254
public function isInstalled()
    {
        if ($this->installed === null) {
            if (!$this->isShared('config')) {
                throw new Exception('Attempting to check install status before application initialization.');
            }

            $this->installed = $this->make('config')->get('concrete.installed');
        }

        return $this->installed;
    }
740993
protected function validateEditInstall()
    {
        $this->setSubmitted('settings');
        $this->setSubmitted('store.host', $this->server->httpHost());
        $this->setSubmitted('store.language', $this->install_language);
        $this->setSubmitted('store.basepath', trim($this->request->base(true), '/'));

        $this->validateComponent('install');

        return !$this->hasErrors(false);
    }
502798
protected function isInstalled()
    {
        $disk = Storage::createLocalDriver([
            'driver' => 'local',
            'root'   => app_path(),
        ]);
        
        foreach ($this->files['required'] as $required) {
            if (! $disk->exists(str_replace(['.stub', app_path()], ['.php', ''], $required))) {
                return false;
            }
        }
        
        return true;
    }
625956
public function installed()
    {
        try {
            return $this->json($this->manager()->getAllPackages());
        } catch (\Exception $e) {
            return $this->getJsonException($e);
        }
    }
1351701
protected function isInstalled()
    {
        $disk = Storage::createLocalDriver([
            'driver' => 'local',
            'root'   => app_path(),
        ]);
        
        foreach (TwoStreamServiceProvider::pathsToPublish(strtolower(TwoStream::PACKAGE), 'required') as $required) {
            if (! $disk->exists(str_replace(['.stub', app_path()], ['.php', ''], $required))) {
                return false;
            }
        }
        
        return true;
    }
676288
public function isInstalled()
    {
        try {
            $sugarConfig = $this->getSugarConfig();
            if (array_key_exists('installer_locked', $sugarConfig)) {
                return $sugarConfig['installer_locked'];
            }
        } catch (SugarException $e) {
        }

        return false;
    }
531085
public function compile(): bool
    {
        // Delete old twig cache files
        if (file_exists($this->cachePath)) {
            $this->removeDirectory($this->cachePath);
        }

        if (!file_exists($this->cachePath)) {
            mkdir($this->cachePath);
        }

        // Iterate over all your templates and force compilation
        $this->twig->disableDebug();
        $this->twig->enableAutoReload();

        if (!$this->twig->getCache()) {
            throw new RuntimeException('The Twig cache must be enabled!');
        }

        $loader = $this->twig->getLoader();

        if ($loader instanceof FilesystemLoader) {
            $paths = $loader->getPaths();

            foreach ($paths as $path) {
                $this->compileFiles($path);
            }
        }

        return true;
    }
580077
public function findAll(): array
    {
        $rootPackage = $this->composer->getPackage();
        $dependencies = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();

        $packagesWithDuplicates = array_merge([$rootPackage], $dependencies);

        return $this->removeDuplicates($packagesWithDuplicates);
    }
1316304
protected function getBuildRoot() {

    $extra = $this->package->getExtra();
    $paths = isset($extra['installer-paths']) ? $extra['installer-paths'] : [];
    foreach ($paths as $path => $types) {
      if (in_array("type:drupal-core", $types)) {
        return str_replace('/core', '', $path);
      }
    }

    throw new InstallerPathsNotFoundException();
  }
1325743
public function isIndirect()
    {
        $erroringFile = $erroringPackage = null;
        foreach ($this->trace as $line) {
            if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
                continue;
            }
            if (!isset($line['file'])) {
                continue;
            }
            $file = $line['file'];
            if ('-' === $file || 'Standard input code' === $file || !realpath($file)) {
                continue;
            }
            if (!$this->pathOriginatesFromVendor($file)) {
                return false;
            }
            if (null !== $erroringFile && null !== $erroringPackage) {
                $package = $this->getPackage($file);
                if ('composer' !== $package && $package !== $erroringPackage) {
                    return true;
                }
                continue;
            }
            $erroringFile = $file;
            $erroringPackage = $this->getPackage($file);
        }

        return false;
    }
989300
public static function check_composer_updates() {
	$composer_json  = file_get_contents(ROOT_DIR.'/composer.json');
	$composer_json = json_decode($composer_json, true);
	if (empty($composer_json['require'])) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('there are no required packages to check');
	}
	
	$composer_lock = file_get_contents(ROOT_DIR.'/composer.lock');
	$composer_lock = json_decode($composer_lock, true);
	if (empty($composer_lock['packages'])) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('lock file is missing its packages');
	}
	
	$composer_executable = 'composer';
	if (file_exists(ROOT_DIR.'composer.phar')) {
		$composer_executable = 'php composer.phar';
	}
	
	$required_packages  = $composer_json['require'];
	$installed_packages = $composer_lock['packages'];
	$update_packages    = [];
	
	foreach ($installed_packages as $installed_package) {
		$package_name      = $installed_package['name'];
		$installed_version = preg_replace('/v([0-9].*)/', '$1', $installed_package['version']);
		$version_regex     = '/versions\s*:.+v?([0-9]+\.[0-9]+(\.[0-9]+)?)(,|$)/U';
		
		// skip dependencies of dependencies
		if (empty($required_packages[$package_name])) {
			continue;
		}
		
		// check commit hash for dev-* versions
		if (strpos($installed_version, 'dev-') === 0) {
			$installed_version = $installed_package['source']['reference'];
			$version_regex     = '/source\s*:.+ ([a-f0-9]{40})$/m';
		}
		
		// find out the newest release
		$package_info = shell_exec($composer_executable.' show -a '.escapeshellarg($package_name));
		preg_match($version_regex, $package_info, $possible_version);
		if (empty($possible_version)) {
			$exception = bootstrap::get_library('exception');
			throw new $exception('can not find out newest release for '.$package_name);
		}
		
		if (ENVIRONMENT == 'development') {
			echo 'installed '.$package_name.' at '.$installed_version.', possible version is '.$possible_version[1].PHP_EOL;
		}
		
		if ($possible_version[1] == $installed_version) {
			continue;
		}
		
		$update_packages[$package_name] = [
			'required'  => $required_packages[$package_name],
			'installed' => $installed_version,
			'possible'  => $possible_version[1],
		];
	}
	
	return $update_packages;
}
88197
public function isAvailable(): bool
    {
        $projectEnvFileExists = false;
        foreach (self::ENV_FILES as $envFile) {
            if (file_exists("{$this->projectRootDir}/{$envFile}")) {
                $projectEnvFileExists = true;
            }
        }

        if (!$projectEnvFileExists) {
            return false;
        }

        $sourceFile = "{$this->packageInstallDir}/.installer/%s/.env";
        foreach ($this->projectType->getProjectDirs() as $projectDir) {
            $envFile = sprintf($sourceFile, $projectDir);
            if (is_file($envFile)) {
                return true;
            }
        }

        return false;
    }
846466
protected function validateInstallerInstall()
    {
        $field = 'installer';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if (empty($value)) {
            $this->setSubmitted('installer', 'default');
            return null;
        }

        $installer = $this->install->getHandler($value);

        if (empty($installer)) {
            $this->setErrorInvalid('installer', $this->translation->text('Installer'));
            return false;
        }

        return true;
    }
514721
protected static function checkSupports()
    {
        if (is_callable('runkit_lint_file')) {
            self::$support[self::SUPPORT_RUNKIT_SANDBOX] = true;
        }

        if (is_callable('runkit_function_add')) {
            self::$support[self::SUPPORT_RUNKIT_MODIFY] = true;
        }

        if (is_callable('runkit_import')) {
            self::$support[self::SUPPORT_RUNKIT_IMPORT] = true;
        }

        if (self::supported(self::SUPPORT_RUNKIT_MODIFY) && ini_get('runkit.internal_override')) {
            self::$support[self::SUPPORT_RUNKIT_INTERNAL_MODIFY] = true;
        }
    }
684898
public function postInstall()
    {
        if (!$this->initialized) {
            $this->initialize();
        }

        // This method is called twice. Run it only once.
        if (!$this->runPostInstall) {
            return;
        }

        $this->runPostInstall = false;

        $this->io->write('<info>Synchronizing Puli with Composer</info>');

        $rootPackage = $this->composer->getPackage();
        $composerPackages = $this->loadComposerPackages();
        $prodPackageNames = $this->filterProdPackageNames($composerPackages, $rootPackage);
        $env = $this->isDev ? PuliPackage::ENV_DEV : PuliPackage::ENV_PROD;

        try {
            $puliPackages = $this->loadPuliPackages();
        } catch (PuliRunnerException $e) {
            $this->printWarning('Could not load Puli packages', $e);

            return;
        }

        // Don't remove non-existing packages in production environment
        // Removed packages could be dev dependencies (i.e. "require-dev"
        // of the root package or "require" of another dev dependency), and
        // we can't find out whether they are since Composer doesn't load them
        if (PuliPackage::ENV_PROD !== $env) {
            $this->removeRemovedPackages($composerPackages, $puliPackages);
        }

        $this->installNewPackages($composerPackages, $prodPackageNames, $puliPackages);

        // Don't print warnings for non-existing packages in production
        if (PuliPackage::ENV_PROD !== $env) {
            $this->checkForNotFoundErrors($puliPackages);
        }

        $this->checkForNotLoadableErrors($puliPackages);
        $this->adoptComposerName($puliPackages);
        $this->removePuliDir();
        $this->buildPuli();
    }
498905
protected function oci_package_installed() {
        $sql = "SELECT 1
                FROM user_objects
                WHERE object_type = 'PACKAGE BODY'
                  AND object_name = 'MOODLELIB'
                  AND status = 'VALID'";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $stmt = $this->parse_query($sql);
        $result = oci_execute($stmt, $this->commit_status);
        $this->query_end($result, $stmt);
        $records = null;
        oci_fetch_all($stmt, $records, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
        oci_free_statement($stmt);
        return isset($records[0]) && reset($records[0]) ? true : false;
    }