<commit_before><?php
/*
 * This file is part of the project RMT
 *
 * Copyright (c) 2013, Liip AG, http://www.liip.ch
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Liip\RMT\Action;

use Phar;
use FilesystemIterator;

use Liip\RMT\Context;

/**
 * Builds a Phar package of the current project.
 */
class BuildPharPackageAction extends BaseAction
{

    public function __construct($options)
    {
        $this->options = array_merge(array(
            'package-name' => 'rmt-package',
            'destination' => '/tmp/',
            'excluded-paths' => ''
        ), $options);
    }

    public function execute()
    {
        $this->create();
        $this->confirmSuccess();
    }

    /**
     * Handles the creation of the package.
     */
    protected function create()
    {
        $output = $this->getDestination() . '/' . $this->getFilename();

        $phar = new Phar($output, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME);

        $phar->buildFromDirectory(Context::getParam('project-root'), $this->options['excluded-paths']);

        $phar->setStub($phar->createDefaultStub("index.php")); // TODO: improve stub
    }

    /**
     * Determines the package filename based on the next version and the 'package-name' option.
     *
     * @return string
     */
    protected function getFilename()
    {
        $currentVersion = Context::get('version-persister')->getCurrentVersion();
        $nextVersion = Context::get('version-generator')->generateNextVersion($currentVersion);

        return $this->options['package-name'] . '-' . $nextVersion . '.phar';
    }<commit_msg>Do not fail on first release<commit_after><?php
/*
 * This file is part of the project RMT
 *
 * Copyright (c) 2013, Liip AG, http://www.liip.ch
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Liip\RMT\Action;

use Phar;
use FilesystemIterator;

use Liip\RMT\Context;

/**
 * Builds a Phar package of the current project.
 */
class BuildPharPackageAction extends BaseAction
{

    public function __construct($options)
    {
        $this->options = array_merge(array(
            'package-name' => 'rmt-package',
            'destination' => '/tmp/',
            'excluded-paths' => ''
        ), $options);
    }

    public function execute()
    {
        $this->create();
        $this->confirmSuccess();
    }

    /**
     * Handles the creation of the package.
     */
    protected function create()
    {
        $output = $this->getDestination() . '/' . $this->getFilename();

        $phar = new Phar($output, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME);

        $phar->buildFromDirectory(Context::getParam('project-root'), $this->options['excluded-paths']);

        $phar->setStub($phar->createDefaultStub("index.php")); // TODO: improve stub
    }

    /**
     * Determines the package filename based on the next version and the 'package-name' option.
     *
     * @return string
     */
    protected function getFilename()
    {
        try {
            $currentVersion = Context::get('version-persister')->getCurrentVersion();
        } catch (\Exception $e) {
            $currentVersion = Context::get('version-generator')->getInitialVersion();
        }

        $nextVersion = Context::get('version-generator')->generateNextVersion($currentVersion);

        return $this->options['package-name'] . '-' . $nextVersion . '.phar';
    }
{'fraction_non_alphanumeric': 0.1408839779005525, 'fraction_numerical': 0.0022099447513812156, 'mean_word_length': 2.7679500520291365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5620565', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1017, 'n_words': 249}