<commit_before><?php

namespace Bolt\Composer\Action;

use Bolt\Translation\Translator as Trans;
use Composer\Json\JsonFile;
use Silex\Application;

/**
 * Initialise Composer JSON file class.
 *
 * @author <NAME> <<EMAIL>>
 */
final class BoltExtendJson
{
    /**
     * @var array
     */
    private $options;

    /**
     * @var string[]
     */
    private $messages;

    /**
     * @param $options  array
     */
    public function __construct(array $options)
    {
        $this->options = $options;
    }

    /**
     * Convenience function to generalise the library.
     *
     * @param string $file
     * @param array  $data
     */
    public function execute($file, array $data = array())
    {
        $this->initJson($file, $data);
    }

    /**
     * Initialise a JSON file at given location with optional data input.
     *
     * @param string $file
     * @param array  $data
     */
    public function initJson($file, array $data = array())
    {
        $jsonFile = new JsonFile($file);
        $jsonFile->write($data);
    }

    /**
     * Set up Composer JSON file.
     *
     * @param Application $app
     *
     * @return array|null
     */
    public function updateJson(Application $app)
    {
        if (!is_file($this->options['composerjson'])) {
            $this->initJson($this->options['composerjson']);
        }

        $jsonFile = new JsonFile($this->options['composerjson']);
        if ($jsonFile->exists()) {
            $json = $jsonorig = $jsonFile->read();

            // Workaround Bolt 2.0 installs with "require": []
            if (isset($json['require']) && empty($json['require'])) {
                unset($json['require']);
            }
        } else {
            // Error
            $this->messages[] = Trans::__(
                "The Bolt extensions file '%composerjson%' isn't readable.",
                array('%composerjson%' => $this->options['composerjson'])
            );

            $app['extend.writeable'] = false;
            $app['extend.online'] = false;

            return null;
        }

        $pathToWeb = $app['resources']->findRelativePath($app['resources']->getPath('extensions'), $app['resources']->getPath('web'));

        // Enforce standard settings
        $json['repositories']['packagist'] = false;
        $json['repositories']['bolt'] = array(
            'type' => 'composer',
            'url'  => $app['extend.site'] . 'satis/'
        );
        $json['minimum-stability'] = $app['config']->get('general/extensions/stability', 'stable');
        $json['prefer-stable'] = true;
        $json['config'] = array(
            'discard-changes'   => true,
            'preferred-install' => 'dist'
        );
        $json['provide']['bolt/bolt'] = $app['bolt_version'];
        $json['extra'] = array('bolt-web-path' => $pathToWeb);
        $json['autoload']['psr-4']['Bolt\\Composer\\'] = '';
        $json['scripts'] = array(
            'post-package-install' => 'Bolt\\Composer\\ExtensionInstaller::handle',
            'post-package-update'  => 'Bolt\\Composer\\ExtensionInstaller::handle'<commit_msg>Only force the extra key for 'bolt-web-path'<commit_after><?php

namespace Bolt\Composer\Action;

use Bolt\Translation\Translator as Trans;
use Composer\Json\JsonFile;
use Silex\Application;

/**
 * Initialise Composer JSON file class.
 *
 * @author <NAME> <<EMAIL>>
 */
final class BoltExtendJson
{
    /**
     * @var array
     */
    private $options;

    /**
     * @var string[]
     */
    private $messages;

    /**
     * @param $options  array
     */
    public function __construct(array $options)
    {
        $this->options = $options;
    }

    /**
     * Convenience function to generalise the library.
     *
     * @param string $file
     * @param array  $data
     */
    public function execute($file, array $data = array())
    {
        $this->initJson($file, $data);
    }

    /**
     * Initialise a JSON file at given location with optional data input.
     *
     * @param string $file
     * @param array  $data
     */
    public function initJson($file, array $data = array())
    {
        $jsonFile = new JsonFile($file);
        $jsonFile->write($data);
    }

    /**
     * Set up Composer JSON file.
     *
     * @param Application $app
     *
     * @return array|null
     */
    public function updateJson(Application $app)
    {
        if (!is_file($this->options['composerjson'])) {
            $this->initJson($this->options['composerjson']);
        }

        $jsonFile = new JsonFile($this->options['composerjson']);
        if ($jsonFile->exists()) {
            $json = $jsonorig = $jsonFile->read();

            // Workaround Bolt 2.0 installs with "require": []
            if (isset($json['require']) && empty($json['require'])) {
                unset($json['require']);
            }
        } else {
            // Error
            $this->messages[] = Trans::__(
                "The Bolt extensions file '%composerjson%' isn't readable.",
                array('%composerjson%' => $this->options['composerjson'])
            );

            $app['extend.writeable'] = false;
            $app['extend.online'] = false;

            return null;
        }

        $pathToWeb = $app['resources']->findRelativePath($app['resources']->getPath('extensions'), $app['resources']->getPath('web'));

        // Enforce standard settings
        $json['repositories']['packagist'] = false;
        $json['repositories']['bolt'] = array(
            'type' => 'composer',
            'url'  => $app['extend.site'] . 'satis/'
        );
        $json['minimum-stability'] = $app['config']->get('general/extensions/stability', 'stable');
        $json['prefer-stable'] = true;
        $json['config'] = array(
            'discard-changes'   => true,
            'preferred-install' => 'dist'
        );
        $json['provide']['bolt/bolt'] = $app['bolt_version'];
        $json['extra']['bolt-web-path'] = $pathToWeb;
        $json['autoload']['psr-4']['Bolt\\Composer\\'] = '';
        $json['scripts'] = array(
            'post-package-install' => 'Bolt\\Composer\\ExtensionInstaller::handle',
            'post-package-update'  => 'Bolt\\Composer\\ExtensionInstaller::handle'
{'fraction_non_alphanumeric': 0.17275641025641025, 'fraction_numerical': 0.0009615384615384616, 'mean_word_length': 2.140915953699044, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 54, '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': '5201975', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1817, 'n_words': 360}