<commit_before><?php

namespace AydinHassan\MagentoConnectPlugin;

use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\InstallerEvents;
use Composer\Composer;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\IO\IOInterface;
use Composer\Installer\InstallerEvent;
use Composer\Package\Link;
use Composer\Package\Package;
use Composer\Package\Version\VersionParser;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Plugin\PluginInterface;
use Composer\Repository\ArrayRepository;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\RepositoryManager;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;

/**
 * Class Plugin
 * @package AydinHassan\MagentoConnectPlugin
 * @author <NAME> <<EMAIL>>
 */
class Plugin implements PluginInterface
{

    /**
     * @var string
     */
    protected $releasesUrlFormat = 'http://connect20.magentocommerce.com/community/%s/releases.xml';

    /**
     * @var string
     */
    protected $distUrlFormat = 'http://connect20.magentocommerce.com/community/%s/%s/%s-%s.tgz';

    /**
     * @param Composer $composer
     * @param IOInterface $io
     */
    public function activate(Composer $composer, IOInterface $io)
    {
        $name = '\nosto_\tagging';

        $newName = '';
        $arr = str_split($name);
        while ($elem = array_shift($arr)) {
            if ($elem === '\\') {
                $newName .= strtoupper(array_shift($arr));
            } else {
                $newName .= $elem;
            }
        }







        $repositoryManager = $composer->getRepositoryManager();
        $extra             = $composer->getPackage()->getExtra();

        if (!isset($extra['connect-packages'])) {
            return;
        }

        $versionParser = new VersionParser;

        $links = [];
        foreach ($extra['connect-packages'] as $connectPackage => $version) {
            $releases   = $this->getVersionsForPackage($connectPackage);
            $repository = $this->addPackages($releases, $connectPackage);
            $repositoryManager->addRepository($repository);

            $constraint = $versionParser->parseConstraints($version);
            $links[] = new Link($composer->getPackage()->getName(), $connectPackage, $constraint);
        }

        if (!empty($links)) {
            $requires = $composer->getPackage()->getRequires();
            $requires = array_merge($requires, $links);
            $composer->getPackage()->setRequires($requires);
        }
    }

    /**
     * @param array $releases
     * @param string $connectPackage
     * @return RepositoryInterface
     */
    private function addPackages(array $releases, $connectPackage)
    {
        return new ArrayRepository(array_map(function ($release) use ($connectPackage) {
            $distUrl = sprintf($this->distUrlFormat, $connectPackage, $release, $connectPackage, $release);

            $package = new Package(strtolower($connectPackage), $release, $release);
            $package->setDistUrl($distUrl);
            $package->setDistType('tar');
            $package->setType('magento-module');
            $package->setExtra([
                'package-xml' => "package.xml",
            ]);

            return $package;
        }, $releases));
    }

    /**
     * @param string $package
     * @return array
     */
    private function getVersionsForPackage($package)
    {
        $url = sprintf($this->releasesUrlFormat, $package);
        $xml = file_get_contents($url);

        if (!$xml) {
            throw new \InvalidArgumentException(sprintf('URL: "%s" returned nothing', $xml));
        }

        libxml_use_internal_errors(true);
        $xmlObj = simplexml_load_string($xml);
        if ($xmlObj=== false) {
            $message = sprintf(
                "XML Parsing Failed. Errors: '%s'",
                implode(
                    "', '",
                    array_map(function (\LibXMLError $xmlError) {
                        return trim($xmlError->message);
                    }, libxml_get_errors())
                )
            );
            throw new \UnexpectedValueException($message);
        }

        $releases = [];
        foreach ($xmlObj->xpath('r') as $release) {
            if (isset($release->v)) {
                $releases[] = (string) $release->v;
            }
        }
        return $releases;
    }


    private function parseFromRequires()
    {

        //TODO: How to denote an uppercase letter?
        $name = '\nosto_\tagging';
        $newName = '';
        $arr = str_split($name);
        while ($elem = array_shift($arr)) {
            if ($elem === '\\') {
                $newName .= strtoupper(array_shift($arr));
            } else {
                $newName .= $elem;
            }
        }

    }
}
<commit_msg>Print message about needing to composer update after installing module<commit_after><?php

namespace AydinHassan\MagentoConnectPlugin;

use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer;
use Composer\Composer;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\IO\IOInterface;
use Composer\Package\Link;
use Composer\Package\Package;
use Composer\Package\Version\VersionParser;
use Composer\Plugin\PluginInterface;
use Composer\Repository\ArrayRepository;
use Composer\Repository\RepositoryInterface;

/**
 * Class Plugin
 * @package AydinHassan\MagentoConnectPlugin
 * @author <NAME> <<EMAIL>>
 */
class Plugin implements PluginInterface, EventSubscriberInterface
{

    /**
     * @var string
     */
    protected $releasesUrlFormat = 'http://connect20.magentocommerce.com/community/%s/releases.xml';

    /**
     * @var string
     */
    protected $distUrlFormat = 'http://connect20.magentocommerce.com/community/%s/%s/%s-%s.tgz';

    /**
     * @var string
     */
    protected static $packageName = 'aydin-hassan/magento-connect-plugin';

    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return [
            PackageEvents::POST_PACKAGE_INSTALL => [
                ['postPackageInstall', 0]
            ],
        ];
    }

    /**
     * @param PackageEvent $event
     */
    public function postPackageInstall(PackageEvent $event)
    {
        $operation = $event->getOperation();
        if (!$operation instanceof InstallOperation) {
            return;
        }

        $package = $operation->getPackage();

        if ($package->getName() !== static::$packageName) {
            return;
        }

        $extra = $event->getComposer()->getPackage()->getExtra();
        if (!isset($extra['connect-packages']) || !count($extra['connect-packages'])) {
            return;
        }

        //skip if we are installing from lock file
        if ($event->getComposer()->getLocker()->isLocked()) {
            return;
        }

        $packages = implode('", "', array_keys($extra['connect-packages']));
        $message  = '<comment>The package(s): "%s" will be installed the next time you run ';
        $message .= 'composer update</comment>';
        $event->getIO()->write(sprintf($message, $packages));
    }

    /**
     * @param Composer $composer
     * @param IOInterface $io
     */
    public function activate(Composer $composer, IOInterface $io)
    {
        $repositoryManager = $composer->getRepositoryManager();
        $extra             = $composer->getPackage()->getExtra();

        if (!isset($extra['connect-packages'])) {
            return;
        }

        $versionParser = new VersionParser;

        $links = [];
        foreach ($extra['connect-packages'] as $connectPackage => $version) {
            $releases   = $this->getVersionsForPackage($connectPackage);
            $repository = $this->addPackages($releases, $connectPackage);
            $repositoryManager->addRepository($repository);

            $constraint = $versionParser->parseConstraints($version);
            $links[] = new Link($composer->getPackage()->getName(), $connectPackage, $constraint);
        }

        if (!empty($links)) {
            $requires = $composer->getPackage()->getRequires();
            $requires = array_merge($requires, $links);
            $composer->getPackage()->setRequires($requires);
        }
    }

    /**
     * @param array $releases
     * @param string $connectPackage
     * @return RepositoryInterface
     */
    private function addPackages(array $releases, $connectPackage)
    {
        return new ArrayRepository(array_map(function ($release) use ($connectPackage) {
            $distUrl = sprintf($this->distUrlFormat, $connectPackage, $release, $connectPackage, $release);

            $package = new Package(strtolower($connectPackage), $release, $release);
            $package->setDistUrl($distUrl);
            $package->setDistType('tar');
            $package->setType('magento-module');
            $package->setExtra([
                'package-xml' => "package.xml",
            ]);

            return $package;
        }, $releases));
    }

    /**
     * @param string $package
     * @return array
     */
    private function getVersionsForPackage($package)
    {
        $url = sprintf($this->releasesUrlFormat, $package);
        $xml = file_get_contents($url);

        if (!$xml) {
            throw new \InvalidArgumentException(sprintf('URL: "%s" returned nothing', $xml));
        }

        libxml_use_internal_errors(true);
        $xmlObj = simplexml_load_string($xml);
        if ($xmlObj=== false) {
            $message = sprintf(
                "XML Parsing Failed. Errors: '%s'",
                implode(
                    "', '",
                    array_map(function (\LibXMLError $xmlError) {
                        return trim($xmlError->message);
                    }, libxml_get_errors())
                )
            );
            throw new \UnexpectedValueException($message);
        }

        $releases = [];
        foreach ($xmlObj->xpath('r') as $release) {
            if (isset($release->v)) {
                $releases[] = (string) $release->v;
            }
        }
        return $releases;
    }
}

{'fraction_non_alphanumeric': 0.13820268430266486, 'fraction_numerical': 0.0008753160863645205, 'mean_word_length': 2.268595041322314, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 30}, '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': '2431759', 'n_tokens_mistral': 2880, 'n_tokens_neox': 2750, 'n_words': 523}