<commit_before><?php

/**
 * This file is part of tenside/core.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * This project is provided in good faith and hope to be usable by anyone.
 *
 * @package    tenside/core
 * @author     <NAME> <<EMAIL>>
 * @copyright  2015 <NAME> <<EMAIL>>
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
 * @link       https://github.com/tenside/core
 * @filesource
 */

namespace Tenside\Core\Task\Composer;

use Tenside\Core\Task\TaskFactoryInterface;
use Tenside\Core\Util\JsonArray;
use Tenside\Core\Util\HomePathDeterminator;

/**
 * This class provides loading of the tenside core configuration.
 */
class ComposerTaskFactory implements TaskFactoryInterface
{
    /**
     * The home path.
     *
     * @var HomePathDeterminator
     */
    private $home;

    /**
     * Create a new instance.
     *
     * @param HomePathDeterminator $home The home path to use.
     */
    public function __construct(HomePathDeterminator $home)
    {
        $this->home = $home;
    }

    /**
     * {@inheritdoc}
     */
    public function isTypeSupported($taskType)
    {
        return in_array($taskType, ['install', 'upgrade', 'require-package', 'remove-package']);
    }

    /**
     * {@inheritdoc}
     *
     * @throws \InvalidArgumentException For unsupported task types.
     */
    public function createInstance($taskType, JsonArray $metaData)
    {
        switch ($taskType) {
            case 'install':
                return new InstallTask($metaData);
            case 'upgrade':
                $this->ensureHomePath($metaData);
                if (!$metaData->has(UpgradeTask::SETTING_DATA_DIR)) {
                    $metaData->set(UpgradeTask::SETTING_DATA_DIR, $this->home->tensideDataDir());
                }
                return new UpgradeTask($metaData);
            case 'require-package':
                $this->ensureHomePath($metaData);
                return new RequirePackageTask($metaData);
            case 'remove-package':
                $this->ensureHomePath($metaData);
                return new RemovePackageTask($metaData);
            default:
        }

        throw new \InvalidArgumentException('Do not know how to create task.');
    }

    /**
     * Ensure the home path has been set in the passed meta data.
     *
     * @param JsonArray $metaData The meta data to examine.
     *
     * @return void
     */
    private function ensureHomePath(JsonArray $metaData)
    {
        if ($metaData->has(RequirePackageTask::SETTING_HOME)) {
            return;
        }
        $metaData->set(RequirePackageTask::SETTING_HOME, $this->home->homeDir());
    }
}<commit_msg>Use constant from AbstractPackageManipulatingTask<commit_after><?php

/**
 * This file is part of tenside/core.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * This project is provided in good faith and hope to be usable by anyone.
 *
 * @package    tenside/core
 * @author     <NAME> <<EMAIL>>
 * @copyright  2015 <NAME> <<EMAIL>>
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
 * @link       https://github.com/tenside/core
 * @filesource
 */

namespace Tenside\Core\Task\Composer;

use Tenside\Core\Task\TaskFactoryInterface;
use Tenside\Core\Util\JsonArray;
use Tenside\Core\Util\HomePathDeterminator;

/**
 * This class provides loading of the tenside core configuration.
 */
class ComposerTaskFactory implements TaskFactoryInterface
{
    /**
     * The home path.
     *
     * @var HomePathDeterminator
     */
    private $home;

    /**
     * Create a new instance.
     *
     * @param HomePathDeterminator $home The home path to use.
     */
    public function __construct(HomePathDeterminator $home)
    {
        $this->home = $home;
    }

    /**
     * {@inheritdoc}
     */
    public function isTypeSupported($taskType)
    {
        return in_array($taskType, ['install', 'upgrade', 'require-package', 'remove-package']);
    }

    /**
     * {@inheritdoc}
     *
     * @throws \InvalidArgumentException For unsupported task types.
     */
    public function createInstance($taskType, JsonArray $metaData)
    {
        switch ($taskType) {
            case 'install':
                return new InstallTask($metaData);
            case 'upgrade':
                $this->ensureHomePath($metaData);
                if (!$metaData->has(UpgradeTask::SETTING_DATA_DIR)) {
                    $metaData->set(UpgradeTask::SETTING_DATA_DIR, $this->home->tensideDataDir());
                }
                return new UpgradeTask($metaData);
            case 'require-package':
                $this->ensureHomePath($metaData);
                return new RequirePackageTask($metaData);
            case 'remove-package':
                $this->ensureHomePath($metaData);
                return new RemovePackageTask($metaData);
            default:
        }

        throw new \InvalidArgumentException('Do not know how to create task.');
    }

    /**
     * Ensure the home path has been set in the passed meta data.
     *
     * @param JsonArray $metaData The meta data to examine.
     *
     * @return void
     */
    private function ensureHomePath(JsonArray $metaData)
    {
        if ($metaData->has(AbstractPackageManipulatingTask::SETTING_HOME)) {
            return;
        }
        $metaData->set(AbstractPackageManipulatingTask::SETTING_HOME, $this->home->homeDir());
    }
}
{'fraction_non_alphanumeric': 0.11591634172279333, 'fraction_numerical': 0.0014179369018078695, 'mean_word_length': 2.3390532544378697, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 45, 'https://': 4, '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': '5514268', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1563, 'n_words': 395}