Detect if other project use the dependency by using the "packages.json" file

@param PackageInterface $package

@return bool
325684
protected function isSourceDirUnused(PackageInterface $package)
    {
        $usageData = $this->packageDataManager->getPackageUsage($package);

        return sizeof($usageData) <= 1;
    }
404807
public function parse(PackageInterface $package)
    {
        $extraFiles = [];
        $extra = $package->getExtra();
        if (!empty($extra['extra-files'])) {
            foreach ((array) $extra['extra-files'] as $id => $extraFile) {
                $file = new ExtraFile(
                    $package,
                    $id,
                    $extraFile['url'],
                    $this->parseDistType($extraFile['url']),
                    $extraFile['path']
                );
                $extraFiles[] = $file;
            }
        }

        return $extraFiles;
    }
689097
public function isNeedUpdate($package)
    {
        $packageBower = $this->config->getPackageBowerFileContent($package);
        $semver = new version($packageBower['version']);

        return !$semver->satisfies(new expression($package->getRequiredVersion()));
    }
643594
protected function checkPackageCompatibility(Package $package, Package $dependentPackage, $requirements)
    {
        $result = null;
        $version = $dependentPackage->getPackageVersion();
        if ($requirements === false) {
            $result = new IncompatiblePackagesException($package, $dependentPackage);
        } elseif (is_string($requirements)) {
            if (version_compare($version, $requirements) < 0) {
                $result = new VersionMismatchException($package, $dependentPackage, $requirements);
            }
        } elseif (is_array($requirements)) {
            if (version_compare($version, $requirements[0]) < 0 || version_compare($version, $requirements[1]) > 0) {
                $result = new VersionMismatchException($package, $dependentPackage, $requirements);
            }
        }

        return $result;
    }
93826
protected function _removeAutoloader(PackageInterface $package)
    {
        $path = $this->_getAutoloaderPath($package);

        if(file_exists($path))
        {
            $contents = file_get_contents($path);

            if (strpos($contents, 'This file has been generated automatically by Composer.') !== false) {
                unlink($path);
            }
        }
    }
1257797
def is_dependant(package, project_name):
    """"""
    for requirement in package.requires():
        # perform case-insensitive matching
        if requirement.project_name.lower() == project_name.lower():
            return True
    return False
99979
private function matchPackage(CompletePackageInterface $package, $token)
	{
		$score = 0;
	
		if (false !== stripos($package->getName(), $token)) {
			$score += 5;
		}
	
		if (!$this->onlyName && false !== stripos(join(',', $package->getKeywords() ?: array()), $token)) {
			$score += 3;
		}
	
		if (!$this->onlyName && false !== stripos($package->getDescription(), $token)) {
			$score += 1;
		}
	
		return $score;
	}
420149
public function getInstallPath(PackageInterface $package)
    {
        $prettyName = $package->getPrettyName();
        DebugPrinter::log(
            'Getting install path for `%s` package',
            array($prettyName,)
        );
        if (isset($this->installDirCache[$prettyName])) {
            return $this->installDirCache[$prettyName];
        }
        $installDir = null;
        if ($this->composer->getPackage()) {
            $rootExtra = $this->composer->getPackage()->getExtra();
            if (!empty($rootExtra['opencart-install-dir'])) {
                $installDir = $rootExtra['opencart-install-dir'];
            }
        }
        if (!$installDir) {
            $extra = $package->getExtra();
            if (!empty($extra['opencart-install-dir'])) {
                $installDir = $extra['opencart-install-dir'];
            }
        }
        if (is_array($installDir)) {
            if (isset($installDir[$prettyName])) {
                $this->installDirCache[$prettyName] = $installDir[$prettyName];
                return $installDir[$prettyName];
            }
            $this->installDirCache[$prettyName] = $this->defaultInstallDir;
            return $this->defaultInstallDir;
        }
        $installDir = $installDir ? $installDir : $this->defaultInstallDir;
        DebugPrinter::log(
            'Computed install dir for package `%s`: `%s`',
            array($prettyName, $installDir,)
        );
        $this->installDirCache[$prettyName] = $installDir;
        return $installDir;
    }
1203067
protected function getInstallerConfig(PackageInterface $package)
    {
        if ($this->installerConfig !== null) {
            return $this->installerConfig;
        }

        $type       = $package->getType();
        $prettyName = $package->getPrettyName();

        if (strpos($prettyName, '/') !== false) {
            list($vendor, $name) = explode('/', $prettyName);
        } else {
            $vendor = '';
            $name   = $prettyName;
        }

        $extra = $package->getExtra();

        if (!empty($extra['installer-name'])) {
            $name = $extra['installer-name'];
        }

        $loader = 'mu-plugins/' . $name . '.php';

        if (!empty($extra['installer-loader'])) {
            $loader = $extra['installer-loader'];
        }

        return compact('name', 'vendor', 'type', 'loader');
    }
504290
protected function normalizeBranchAlias(PackageInterface $package)
    {
        $stability = VersionParser::parseStability($this->versionParser->normalize($this->rootPackageVersion));
        $aliasNormalized = 'dev-'.$this->rootPackageVersion;

        if (BasePackage::STABILITY_STABLE === BasePackage::$stabilities[$stability]
            && null === $this->findPackage($package->getName(), $this->rootPackageVersion)) {
            $aliasNormalized = $this->versionParser->normalize($this->rootPackageVersion);
        }

        return $aliasNormalized;
    }
397052
protected function isPackageSupported($package)
    {
        $extra = $package->getExtra();
        if (!empty($extra['drupal']['security-coverage']['status'])
          && $extra['drupal']['security-coverage']['status'] == 'not-covered') {
            return false;
        }
        return true;
    }
1304814
public function linkDropins(PackageInterface $package)
    {
        $this->filesystem->ensureDirectoryExists($this->getContentPath());

        $content_dir = realpath($this->getContentPath());
        $dropins_dir = realpath($this->getInstallPath($package) . '/dropins/');

        // Link dropins not yet added.
        foreach (new \DirectoryIterator($dropins_dir) as $dropin) {
            if ($dropin->isDot()) {
                continue;
            }

            $src  = $content_dir . '/' . $dropin->getFilename();
            $dest = $dropins_dir . '/' . $dropin->getFilename();

            if (file_exists($src)) {
                $this->io->write('<info>Unlinking ' . $this->filesystem->findShortestPath($src, $dest) . '</info>');
                unlink($src);
            }

            $this->io->write('<info>Linking ' . $this->filesystem->findShortestPath($src, $dest) . '</info>');
            $this->filesystem->relativeSymlink($dest, $src);
        }
    }
180014
protected function findBundleFiles(PackageInterface $package)
    {
        $installPath = $this->composer->getInstallationManager()->getInstallPath($package);

        $autoload = $package->getAutoload();
        if (isset($autoload['psr-0'])) {
            $installPath .= '/' . current($autoload['psr-0']);
        }
        if (isset($autoload['psr-4'])) {
            $installPath .= '/' . current($autoload['psr-4']);
        }

        return glob(rtrim($installPath, '/') . '/*Bundle.php');
    }
312834
protected function isDrupalPackage($package)
    {
        if (isset($package) && $package instanceof PackageInterface && strstr($package->getName(), 'drupal/')) {
            return true;
        }
        return false;
    }
956606
private function findSubPackages(PackageInterface $package): Generator
    {
        $readMes = new \Symfony\Component\Finder\Finder();
        $readMes->files()
                ->in($package->getPaths())
                ->depth(1)
                ->name('readme.md');

        // If no sub-folders have a readme, there aren't any sub-packages here.
        if (!$readMes->count()) {
            return;
        }
        yield from $this->scanNamespaceForPackages($package, $package);
    }
1016339
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        if ($this->isSourceDirUnused($package) && $this->io->askConfirmation(
                "The package version <info>" . $package->getPrettyName() . "</info> "
                . "(<fg=yellow>" . $package->getPrettyVersion() . "</fg=yellow>) seems to be unused."
                . PHP_EOL
                . 'Do you want to <fg=red>delete the source folder</fg=red> ? [y/n] (default: no) : ',
                false
            )) {
            $this->packageDataManager->setPackageInstallationSource($package);

            parent::uninstall($repo, $package);
        } else {
            $this->binaryInstaller->removeBinaries($package);
            $repo->removePackage($package);
        }

        $this->packageDataManager->removePackageUsage($package);
        $this->removePackageVendorSymlink($package);
    }
1167276
public function getLoaderFilePackagePath(PackageInterface $package)
    {
        $installPath = $this->getInstallPath($package);

        if ($installPath === false) {
            return false;
        }

        $config      = $this->getInstallerConfig($package);
        $packagePath = $installPath . $config['loader'];

        return $packagePath;
    }