@param Package|string $package
@param Version        $version

@return array
321541
protected function getLoadPackagePathes($package, Version $version)
    {
        $packageName = $package instanceof Package ? $package->getName() : $package;
        $basePath = 'vendor' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, explode('/', $packageName));
        $paths = array('directories' => array(), 'files' => array());
        foreach ($version->getAutoload() as $type => $map) {
            switch ($type) {
                case 'classmap':
                    $paths['directories'] = array_merge($paths['directories'], (array)$map);
                    break;
                case 'psr-0':
                    foreach ($map as $ns => $src) {
                        $nsPath = implode(DIRECTORY_SEPARATOR, explode('\\', str_replace('\\\\', '\\', $ns)));
                        foreach ((array)$src as $path) {
                            $paths['directories'][] = rtrim($path, '/') . DIRECTORY_SEPARATOR . $nsPath;
                        }
                    }
                    break;
                case 'psr-4':
                    foreach ($map as $ns => $src) {
                        foreach ((array)$src as $path) {
                            $paths['directories'][] = implode(DIRECTORY_SEPARATOR, explode('/', rtrim($path, '/')));
                        }
                    }
                    break;
                case 'files':
                    $paths['files'] = array_merge($paths['files'], (array)$map);
            }
        }

        $pathsToExclude = $this->excludeFilesInPath($basePath);
        $pathsToExclude = array_map(function ($p) use ($basePath) {
            return realpath($basePath . DIRECTORY_SEPARATOR . $p);
        }, $pathsToExclude);
        $pathsToExclude = array_filter($pathsToExclude, function ($p) {
            return $p !== false;
        });

        foreach ($paths as &$maps) {
            $maps = array_unique(array_values($maps));
            $maps = array_map(function ($p) use ($basePath) {
                return realpath($basePath . DIRECTORY_SEPARATOR . $p);
            }, $maps);
            foreach ($pathsToExclude as $p) {
                foreach ($maps as $index => $map) {
                    if (strpos($map, $p) === 0) {
                        unset($maps[$index]);
                    }
                }
            }
        }

        return $paths;
    }
650408
public static function getStaticMasteries( string $locale = 'en_US', string $version = null ) : array
	{
		$url = self::getStaticDataFileUrl(self::STATIC_MASTERIES, null, $locale, $version);
		return self::loadStaticData($url);
	}
43393
public function getAvailablePackageStats(Package $package)
    {
        $result = [];
        $languagesDir = $package->getPackagePath() . '/' . DIRNAME_LANGUAGES;
        if ($this->fs->isDirectory($languagesDir)) {
            foreach ($this->fs->directories($languagesDir) as $localeDirectory) {
                $localeID = basename($localeDirectory);
                if (preg_match('/^[a-z]{2,3}($|_)/', $localeID)) {
                    $mo = $languagesDir . '/' . $localeID . '/LC_MESSAGES/messages.mo';
                    if ($this->fs->isFile($mo)) {
                        $result[$localeID] = $this->getMoFileStats($mo);
                    }
                }
            }
        }

        return $result;
    }
1011777
protected function getNewFileVersions($code, $version = null)
    {
        if ($version === null) {
            $version = self::NO_VERSION_VALUE;
        }

        $versions = $this->getFileVersions($code);
        $position = array_search($version, array_keys($versions));
        return array_slice($versions, ++$position);
    }
1130722
protected function readVersionFromLocation(string $location, string $package) : ?string
    {
        // Get the installed packages
        $installed = $this->getInstalledPackages($location);
        if(empty($installed)){
            return null;
        }

        // Search for package
        foreach ($installed as $installedPackage){
            $version = $this->readFromSource($installedPackage, $package);
            if(isset($version)){
                return $version;
            }
        }

        // Nothing found in this package
        return null;
    }
839847
private function buildVersion(SimpleXMLElement $version): array
    {
        $apis = [];
        $guides = [];
        foreach ($version->children() as $child) {
            switch ($child->getName()) {
                case 'api':
                    $apis[] = $this->buildApi($child);
                    break;
                case 'guide':
                    $guides[] = $this->buildGuide($child);
                    break;
                default:
                    break;
            }
        }

        $version = [
            'folder' => (string) $version->folder,
        ];

        if (count($apis) > 0) {
            $version['api'] = $apis;
        }

        if (count($guides) > 0) {
            $version['guide'] = $guides;
        }

        return $version;
    }
91890
protected function matchesCakeVersion($matcher, $version)
    {
        if (class_exists('Composer\Semver\Constraint\MultiConstraint')) {
            $multiClass = 'Composer\Semver\Constraint\MultiConstraint';
            $constraintClass = 'Composer\Semver\Constraint\Constraint';
        } else {
            $multiClass = 'Composer\Package\LinkConstraint\MultiConstraint';
            $constraintClass = 'Composer\Package\LinkConstraint\VersionConstraint';
        }

        $repositoryManager = $this->composer->getRepositoryManager();
        if ($repositoryManager) {
            $repos = $repositoryManager->getLocalRepository();
            if (!$repos) {
                return false;
            }
            $cake3 = new $multiClass(array(
                new $constraintClass($matcher, $version),
                new $constraintClass('!=', '9999999-dev'),
            ));
            $pool = new Pool('dev');
            $pool->addRepository($repos);
            $packages = $pool->whatProvides('cakephp/cakephp');
            foreach ($packages as $package) {
                $installed = new $constraintClass('=', $package->getVersion());
                if ($cake3->matches($installed)) {
                    return true;
                }
            }
        }
        return false;
    }
751652
public function getLink(String $key, String $version = 'latest')
    {
        $return = $this->getLinks()[$key] ?? false;

        if( $version !== 'latest' )
        {
            return $this->versionModifier($version, $return);
        }

        return $return;
    }
311387
protected static function extractVersion(string $version, string $expression): ?string
    {
        if (preg_match($expression, $version, $result)) {
            return Arr::first($result);
        }

        return null;
    }
218266
public function findElementVersion(Element $element, $version)
    {
        $elementVersion = $this->elementVersionManager->find($element, $version);

        return $elementVersion;
    }
822147
private function getDescSortedVersions(array $packages): array
    {
        usort($packages, function (PackageInterface $a, PackageInterface $b) {
            return version_compare($b->getVersion(), $a->getVersion());
        });

        return $packages;
    }
399982
public static function create(Package $package, $version)
    {
        $result = new static();
        $result->package = $package;
        $result->version = (string) $version;
        $result->createdOn = new DateTime();
        $result->updatedOn = new DateTime();

        return $result;
    }
165945
public function recordInstall($package, $version)
    {
        $url = sprintf($this->extendSite . $this->urls['install'], $package, $version);

        try {
            $this->client->head($url);
        } catch (RequestException $e) {
            $this->loggerSystem->critical($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
        }
    }
1286889
public function createPackageResults(array $package)
    {
        $created = array();

        if (isset($package['maintainers']) && $package['maintainers']) {
            foreach ($package['maintainers'] as $key => $maintainer) {
                $package['maintainers'][$key] = $this->createResult('Packagist\Api\Result\Package\Maintainer', $maintainer);
            }
        }

        if (isset($package['downloads']) && $package['downloads']) {
            $package['downloads'] = $this->createResult('Packagist\Api\Result\Package\Downloads', $package['downloads']);
        }

        foreach ($package['versions'] as $branch => $version) {
            if (isset($version['authors']) && $version['authors']) {
                foreach ($version['authors'] as $key => $author) {
                    $version['authors'][$key] = $this->createResult('Packagist\Api\Result\Package\Author', $author);
                }
            }
            if ($version['source']) {
                $version['source'] = $this->createResult('Packagist\Api\Result\Package\Source', $version['source']);
            }
            if (isset($version['dist']) && $version['dist']) {
                $version['dist'] = $this->createResult('Packagist\Api\Result\Package\Dist', $version['dist']);
            }

            $package['versions'][$branch] = $this->createResult('Packagist\Api\Result\Package\Version', $version);
        }

        $created = new Package();
        $created->fromArray($package);

        return $created;
    }
1023190
public function update($package = null, $version = null, $dryRun = false)
    {
        if ($dryRun) {
            $this->setDryRun(true);
        }

        $package = !empty($version) ? $package . ':' . $version : $package;

        return $this->runCommand(self::UPDATE, $package, self::ROOT_REQS . self::DEFAULT_ARGS);
    }
1284566
public function sortPackageVersionEntities($packageVersions, $descending = false)
    {
        $keys = [];
        foreach ($packageVersions as $pv) {
            $keys[$pv->getVersion()] = $pv;
        }
        $sortedKeys = $this->sortPackageVersions(array_keys($keys), $descending);
        $result = [];
        foreach ($sortedKeys as $sortedKey) {
            $result[] = $keys[$sortedKey];
        }

        return $result;
    }
498408
public static function toComponents(Version $version)
    {
        return array(
            Parser::MAJOR => $version->getMajor(),
            Parser::MINOR => $version->getMinor(),
            Parser::PATCH => $version->getPatch(),
            Parser::PRE_RELEASE => $version->getPreRelease(),
            Parser::BUILD => $version->getBuild()
        );
    }