<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 Composer\Command\CreateProjectCommand;
use Composer\IO\IOInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Tenside\Core\Task\Task;
use Tenside\Core\Task\TaskOutput;

/**
 * This class holds the information for an upgrade of some or all packages.
 */
class InstallTask extends Task
{
    /**
     * Constant for the package name key.
     */
    const SETTING_PACKAGE = 'package';

    /**
     * Constant for the package version key.
     */
    const SETTING_VERSION = 'version';

    /**
     * Constant for the destination dir key.
     */
    const SETTING_DESTINATION_DIR = 'dest-dir';

    /**
     * Constant for the repository url.
     */
    const SETTING_REPOSITORY_URL = 'repository-url';

    /**
     * The temporary directory to use.
     *
     * @var string
     */
    private $tempDir;

    /**
     * The environment variable storage.
     *
     * @var string|null
     */
    private $previousEnvVariable;

    /**
     * The previous working directory.
     *
     * @var string
     */
    private $previousWorkingDir;

    /**
     * The list of folders to remove after the installation was complete.
     *
     * @var string[]
     */
    private $folders;

    /**
     * {@inheritDoc}
     */
    public function getType()
    {
        return 'install';
    }

    /**
     * {@inheritDoc}
     *
     * @throws \RuntimeException When the project directory is not empty or when the installation was not successful.
     */
    public function doPerform()
    {
        if (!$this->mayInstall()) {
            throw new \RuntimeException('Project directory not empty.');
        }

        // Will throw exception upon error.
        $this->prepareTmpDir();

        $this->preserveEnvironment();

        try {
            $this->fetchProject();
            $this->moveFiles();
        } catch (\Exception $exception) {
            $this->restoreEnvironment();
            throw new \RuntimeException('Project could not be created.', 1, $exception);
        } finally {
            $this->restoreEnvironment();
        }
        // FIXME: delete recursively?
        rmdir($this->tempDir);
    }

    /**
     * Prepare a temporary directory.
     *
     * @return void
     *
     * @throws \RuntimeException When an error occurred.
     */<commit_msg>Remove obsolete fixme<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 Composer\Command\CreateProjectCommand;
use Composer\IO\IOInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Tenside\Core\Task\Task;
use Tenside\Core\Task\TaskOutput;

/**
 * This class holds the information for an upgrade of some or all packages.
 */
class InstallTask extends Task
{
    /**
     * Constant for the package name key.
     */
    const SETTING_PACKAGE = 'package';

    /**
     * Constant for the package version key.
     */
    const SETTING_VERSION = 'version';

    /**
     * Constant for the destination dir key.
     */
    const SETTING_DESTINATION_DIR = 'dest-dir';

    /**
     * Constant for the repository url.
     */
    const SETTING_REPOSITORY_URL = 'repository-url';

    /**
     * The temporary directory to use.
     *
     * @var string
     */
    private $tempDir;

    /**
     * The environment variable storage.
     *
     * @var string|null
     */
    private $previousEnvVariable;

    /**
     * The previous working directory.
     *
     * @var string
     */
    private $previousWorkingDir;

    /**
     * The list of folders to remove after the installation was complete.
     *
     * @var string[]
     */
    private $folders;

    /**
     * {@inheritDoc}
     */
    public function getType()
    {
        return 'install';
    }

    /**
     * {@inheritDoc}
     *
     * @throws \RuntimeException When the project directory is not empty or when the installation was not successful.
     */
    public function doPerform()
    {
        if (!$this->mayInstall()) {
            throw new \RuntimeException('Project directory not empty.');
        }

        // Will throw exception upon error.
        $this->prepareTmpDir();

        $this->preserveEnvironment();

        try {
            $this->fetchProject();
            $this->moveFiles();
        } catch (\Exception $exception) {
            $this->restoreEnvironment();
            throw new \RuntimeException('Project could not be created.', 1, $exception);
        } finally {
            $this->restoreEnvironment();
        }

        rmdir($this->tempDir);
    }

    /**
     * Prepare a temporary directory.
     *
     * @return void
     *
     * @throws \RuntimeException When an error occurred.
     */
{'fraction_non_alphanumeric': 0.11596667233463696, 'fraction_numerical': 0.0017003910899506887, 'mean_word_length': 2.1898047722342735, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, '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': '5375328', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1647, 'n_words': 481}