<commit_before><?php

/*
 * This file is part of Composer.
 *
 * (c) <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Package\Loader;

use Composer\Package;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class ArrayLoader
{
    protected $supportedLinkTypes = array(
        'require'   => 'requires',
        'conflict'  => 'conflicts',
        'provide'   => 'provides',
        'replace'   => 'replaces',
        'recommend' => 'recommends',
        'suggest'   => 'suggests',
    );

    protected $versionParser;

    public function __construct($parser = null)
    {
        $this->versionParser = $parser;
        if (!$parser) {
            $this->versionParser = new Package\Version\VersionParser;
        }
    }

    public function load($config)
    {
        $this->validateConfig($config);

        $version = $this->versionParser->normalize($config['version']);
        $package = new Package\MemoryPackage($config['name'], $version);

        $package->setType(isset($config['type']) ? $config['type'] : 'library');

        if (isset($config['extra'])) {
            $package->setExtra($config['extra']);
        }

        if (isset($config['license'])) {
            $package->setLicense($config['license']);
        }

        if (isset($config['source'])) {
            if (!isset($config['source']['type']) || !isset($config['source']['url'])) {
                throw new \UnexpectedValueException(sprintf(
                    "package source should be specified as {\"type\": ..., \"url\": ...},\n%s given",
                    json_encode($config['source'])
                ));
            }
            $package->setSourceType($config['source']['type']);
            $package->setSourceUrl($config['source']['url']);
            $package->setSourceReference($config['source']['reference']);
        }

        if (isset($config['dist'])) {
            if (!isset($config['dist']['type'])
             || !isset($config['dist']['url'])
             || !isset($config['dist']['shasum'])) {
                throw new \UnexpectedValueException(sprintf(
                    "package dist should be specified as ".
                    "{\"type\": ..., \"url\": ..., \"shasum\": ...},\n%s given",
                    json_encode($config['source'])
                ));
            }
            $package->setDistType($config['dist']['type']);
            $package->setDistUrl($config['dist']['url']);
            $package->setDistReference($config['dist']['reference']);
            $package->setDistSha1Checksum($config['dist']['shasum']);
        }

        foreach ($this->supportedLinkTypes as $type => $description) {
            if (isset($config[$type])) {
                $method = 'set'.ucfirst($description);
                $package->{$method}(
                    $this->loadLinksFromConfig($package->getName(), $description, $config[$type])
                );
            }
        }

        return $package;
    }

    private function loadLinksFromConfig($srcPackageName, $description, array $linksSpecs)
    {
        $links = array();
        foreach ($linksSpecs as $packageName => $constraint) {
            $name = strtolower($packageName);

            $constraint = $this->versionParser->parseConstraints($constraint);
            $links[]    = new Package\Link($srcPackageName, $packageName, $constraint, $description);
        }

        return $links;
    }

    private function validateConfig(array $config)
    {
        if (!isset($config['name'])) {
            throw new \UnexpectedValueException('name is required for package');
        }
        if (!isset($config['version'])) {
            throw new \UnexpectedValueException('version is required for package');
        }
    }<commit_msg>Remove validation for now since it's doing more harm than good<commit_after><?php

/*
 * This file is part of Composer.
 *
 * (c) <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Package\Loader;

use Composer\Package;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class ArrayLoader
{
    protected $supportedLinkTypes = array(
        'require'   => 'requires',
        'conflict'  => 'conflicts',
        'provide'   => 'provides',
        'replace'   => 'replaces',
        'recommend' => 'recommends',
        'suggest'   => 'suggests',
    );

    protected $versionParser;

    public function __construct($parser = null)
    {
        $this->versionParser = $parser;
        if (!$parser) {
            $this->versionParser = new Package\Version\VersionParser;
        }
    }

    public function load($config)
    {
        $version = $this->versionParser->normalize(isset($config['version']) ? $config['version'] : '0.0.0');
        $package = new Package\MemoryPackage(isset($config['name']) ? $config['name'] : '__app__', $version);

        $package->setType(isset($config['type']) ? $config['type'] : 'library');

        if (isset($config['extra'])) {
            $package->setExtra($config['extra']);
        }

        if (isset($config['license'])) {
            $package->setLicense($config['license']);
        }

        if (isset($config['source'])) {
            if (!isset($config['source']['type']) || !isset($config['source']['url'])) {
                throw new \UnexpectedValueException(sprintf(
                    "package source should be specified as {\"type\": ..., \"url\": ...},\n%s given",
                    json_encode($config['source'])
                ));
            }
            $package->setSourceType($config['source']['type']);
            $package->setSourceUrl($config['source']['url']);
            $package->setSourceReference($config['source']['reference']);
        }

        if (isset($config['dist'])) {
            if (!isset($config['dist']['type'])
             || !isset($config['dist']['url'])
             || !isset($config['dist']['shasum'])) {
                throw new \UnexpectedValueException(sprintf(
                    "package dist should be specified as ".
                    "{\"type\": ..., \"url\": ..., \"shasum\": ...},\n%s given",
                    json_encode($config['source'])
                ));
            }
            $package->setDistType($config['dist']['type']);
            $package->setDistUrl($config['dist']['url']);
            $package->setDistReference($config['dist']['reference']);
            $package->setDistSha1Checksum($config['dist']['shasum']);
        }

        foreach ($this->supportedLinkTypes as $type => $description) {
            if (isset($config[$type])) {
                $method = 'set'.ucfirst($description);
                $package->{$method}(
                    $this->loadLinksFromConfig($package->getName(), $description, $config[$type])
                );
            }
        }

        return $package;
    }

    private function loadLinksFromConfig($srcPackageName, $description, array $linksSpecs)
    {
        $links = array();
        foreach ($linksSpecs as $packageName => $constraint) {
            $name = strtolower($packageName);

            $constraint = $this->versionParser->parseConstraints($constraint);
            $links[]    = new Package\Link($srcPackageName, $packageName, $constraint, $description);
        }

        return $links;
    }
{'fraction_non_alphanumeric': 0.1780568407138136, 'fraction_numerical': 0.0006609385327164573, 'mean_word_length': 2.2319521571977785, 'pattern_counts': {'":': 10, '<': 29, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2483581', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1945, 'n_words': 389}