<commit_before><?php 
/**
 * HUBzero CMS
 *
 * Copyright 2005-2017 HUBzero Foundation, LLC.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */

namespace Components\Installer\Admin\Helpers;
use Composer\IO\NullIO;
use Composer\Json\JsonFile;
use Composer\Json\JsonManipulator;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Installer;
use Composer\Factory;

/**
 * Composer helper class
 */
class ComposerHelper
{
	private static $composer = null;
	private static $factory = null;
	private static $repositoryManager = null;
	private static $localRepository = null;
	private static $remoteRepositories = null;
	private static $io = null;
	private static $installer = null;
	private static $dispatcher = null;

	private static function _init()
	{
		//Set environment up for composer
		if (getenv('COMPOSER_HOME') != PATH_APP)
		{
			putenv("COMPOSER_HOME=" . PATH_APP);
		}
		if (getcwd() != PATH_APP)
		{
			chdir(PATH_APP);
		}
		// Assume no need for output from composer
		if (!self::$io)
		{
			self::$io = new NullIO();
		}

		// Set up a composer object
		if (!self::$factory)
		{
			self::$factory = new Factory();
		}

		if (!self::$composer)
		{
			self::$composer = self::$factory->createComposer(self::$io, PATH_APP . '/composer.json', false, PATH_APP, true);
		}
		return true;
	}

	private static function _getFactory()
	{
		self::_init();
		return self::$factory;
	}

	private static function _getComposer()
	{
		self::_init();
		return self::$composer;
	}

	private static function _resetComposer()
	{
		self::$composer = null;
		self::$factory = null;
		self::$repositoryManager = null;
		self::$localRepository = null;
		self::$remoteRepositories = null;
		self::$io = null;
		self::$installer = null;
		self::$dispatcher = null;
		return self::_init();
	}

	private static function _getIO()
	{
		self::_init();
		return self::$io;
	}

	private static function _getRepositoryManager()
	{
		self::_init();
		if (!self::$repositoryManager)
		{
			self::$repositoryManager = self::$composer->getRepositoryManager();
		}
		return self::$repositoryManager;
	}

	private static function _getLocalRepository()
	{
		self::_init();
		if (!self::$localRepository)
		{
			self::$localRepository = self::_getRepositoryManager()->getLocalRepository();
		}
		return self::$localRepository;
	}

	private static function _getRemoteRepositories()
	{
		self::_init();
		if (!self::$remoteRepositories)
		{
			self::$remoteRepositories = self::_getRepositoryManager()->getRepositories();
		}
		return self::$remoteRepositories;
	}

	private static function _getInstaller()
	{
		self::_init();
		if (!self::$installer)
		{
			self::$installer = Installer::create(self::_getIO(), self::_getComposer());
		}
		return self::$installer;
	}

	private static function _getDispatcher()
	{
		self::_init();
		if (!self::$dispatcher)
		{
			self::$dispatcher = self::_getComposer()->getEventDispatcher();
		}
		return self::$dispatcher;
	}

	private static function _dispatch($command)
	{
		$dispatcher = self::_getDispatcher();
		$commandEvent = new CommandEvent(PluginEvents::COMMAND, $command, self::_getIO(), self::_getIO());
		$dispatcher->dispatch($commandEvent->getName(), $commandEvent);
	}

	private static function _requirePackage($packageName, $constraint = 'dev-master')
	{
		if (empty($packageName))<commit_msg>[fix] Correcting a namespace issue<commit_after><?php 
/**
 * HUBzero CMS
 *
 * Copyright 2005-2017 HUBzero Foundation, LLC.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */

namespace Components\Installer\Admin\Helpers;
use Composer\IO\NullIO;
use Composer\Json\JsonFile;
use Composer\Json\JsonManipulator;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;

/**
 * Composer helper class
 */
class ComposerHelper
{
	private static $composer = null;
	private static $factory = null;
	private static $repositoryManager = null;
	private static $localRepository = null;
	private static $remoteRepositories = null;
	private static $io = null;
	private static $installer = null;
	private static $dispatcher = null;

	private static function _init()
	{
		//Set environment up for composer
		if (getenv('COMPOSER_HOME') != PATH_APP)
		{
			putenv("COMPOSER_HOME=" . PATH_APP);
		}
		if (getcwd() != PATH_APP)
		{
			chdir(PATH_APP);
		}
		// Assume no need for output from composer
		if (!self::$io)
		{
			self::$io = new NullIO();
		}

		// Set up a composer object
		if (!self::$factory)
		{
			self::$factory = new \Composer\Factory();
		}

		if (!self::$composer)
		{
			self::$composer = self::$factory->createComposer(self::$io, PATH_APP . '/composer.json', false, PATH_APP, true);
		}
		return true;
	}

	private static function _getFactory()
	{
		self::_init();
		return self::$factory;
	}

	private static function _getComposer()
	{
		self::_init();
		return self::$composer;
	}

	private static function _resetComposer()
	{
		self::$composer = null;
		self::$factory = null;
		self::$repositoryManager = null;
		self::$localRepository = null;
		self::$remoteRepositories = null;
		self::$io = null;
		self::$installer = null;
		self::$dispatcher = null;
		return self::_init();
	}

	private static function _getIO()
	{
		self::_init();
		return self::$io;
	}

	private static function _getRepositoryManager()
	{
		self::_init();
		if (!self::$repositoryManager)
		{
			self::$repositoryManager = self::$composer->getRepositoryManager();
		}
		return self::$repositoryManager;
	}

	private static function _getLocalRepository()
	{
		self::_init();
		if (!self::$localRepository)
		{
			self::$localRepository = self::_getRepositoryManager()->getLocalRepository();
		}
		return self::$localRepository;
	}

	private static function _getRemoteRepositories()
	{
		self::_init();
		if (!self::$remoteRepositories)
		{
			self::$remoteRepositories = self::_getRepositoryManager()->getRepositories();
		}
		return self::$remoteRepositories;
	}

	private static function _getInstaller()
	{
		self::_init();
		if (!self::$installer)
		{
			self::$installer = \Composer\Installer::create(self::_getIO(), self::_getComposer());
		}
		return self::$installer;
	}

	private static function _getDispatcher()
	{
		self::_init();
		if (!self::$dispatcher)
		{
			self::$dispatcher = self::_getComposer()->getEventDispatcher();
		}
		return self::$dispatcher;
	}

	private static function _dispatch($command)
	{
		$dispatcher = self::_getDispatcher();
		$commandEvent = new CommandEvent(PluginEvents::COMMAND, $command, self::_getIO(), self::_getIO());
		$dispatcher->dispatch($commandEvent->getName(), $commandEvent);
	}

	private static function _requirePackage($packageName, $constraint = 'dev-master')
	{
		if (empty($packageName))
{'fraction_non_alphanumeric': 0.1242263003583451, 'fraction_numerical': 0.0034748615484851775, 'mean_word_length': 4.5248950209958005, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '4889204', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2791, 'n_words': 833}