<commit_before><?php

namespace Bolt\Composer\Action;

use Bolt\Exception\PackageManagerException;
use Composer\Installer;
use Silex\Application;

/**
 * Composer update package class
 *
 * @author <NAME> <<EMAIL>>
 */
final class UpdatePackage
{
    /**
     * @var \Silex\Application
     */
    private $app;

    /**
     * @param $app \Silex\Application
     */
    public function __construct(Application $app)
    {
        $this->app = $app;
    }

    /**
     * Update packages
     *
     * @param  $packages array Indexed array of package names to update
     * @param  $options  array [Optional] changed option set
     *
     * @return int 0 on success or a positive error code on failure
     * @throws \Bolt\Exception\PackageManagerException
     */
    public function execute(array $packages = array(), array $options = array())
    {
        /** @var $composer \Composer\Composer */
        $composer = $this->app['extend.manager']->getComposer();
        $io = $this->app['extend.manager']->getIO();
        $packageManagerOptions = $this->app['extend.manager']->getOptions();

        // Handle passed in options
        if (!$options) {
            $options = array_replace_recursive($packageManagerOptions, $options);
        } else {
            $options = $packageManagerOptions;
        }

        $install = Installer::create($io, $composer);
        $config = $composer->getConfig();
        $optimize = $config->get('optimize-autoloader');

        // Set preferred install method
        $preferSource = false; // Forces installation from package sources when possible, including VCS information.
        $preferDist = false;

        switch ($config->get('preferred-install')) {
            case 'source':
                $preferSource = true;
                break;
            case 'dist':
                $preferDist = true;
                break;
            case 'auto':
            default:
                break;
        }

        try {
            $install
                ->setDryRun($options['dryrun'])
                ->setVerbose($options['verbose'])
                ->setPreferSource($preferSource)
                ->setPreferDist($preferDist)
                ->setDevMode(!$options['nodev'])
                ->setDumpAutoloader(!$options['noautoloader'])
                ->setRunScripts(!$options['noscripts'])
                ->setOptimizeAutoloader($optimize)
                ->setUpdate(true)
                ->setUpdateWhitelist($packages)
                ->setWhitelistDependencies($options['withdependencies'])
                ->setIgnorePlatformRequirements($options['ignoreplatformreqs'])
                ->setPreferStable($options['preferstable'])
                ->setPreferLowest($options['preferlowest'])
                ->disablePlugins();

            return $install->run();
        } catch (\Exception $e) {
            $msg = __CLASS__ . '::' . __FUNCTION__ . ' recieved an error from Composer: ' . $e->getMessage() . ' in ' . $e->getFile() . '::' . $e->getLine();
            $this->app['logger.system']->critical($msg, array('event' => 'exception', 'exception' => $e));

            throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
        }
    }
}
<commit_msg>Revert array_replace_recursive usage, since it clobers multidimensional arrays<commit_after><?php

namespace Bolt\Composer\Action;

use Bolt\Exception\PackageManagerException;
use Bolt\Helpers\Arr;
use Composer\Installer;
use Silex\Application;

/**
 * Composer update package class
 *
 * @author <NAME> <<EMAIL>>
 */
final class UpdatePackage
{
    /**
     * @var \Silex\Application
     */
    private $app;

    /**
     * @param $app \Silex\Application
     */
    public function __construct(Application $app)
    {
        $this->app = $app;
    }

    /**
     * Update packages
     *
     * @param  $packages array Indexed array of package names to update
     * @param  $options  array [Optional] changed option set
     *
     * @return int 0 on success or a positive error code on failure
     * @throws \Bolt\Exception\PackageManagerException
     */
    public function execute(array $packages = array(), array $options = array())
    {
        /** @var $composer \Composer\Composer */
        $composer = $this->app['extend.manager']->getComposer();
        $io = $this->app['extend.manager']->getIO();
        $packageManagerOptions = $this->app['extend.manager']->getOptions();

        // Handle passed in options
        if (!$options) {
            $options = Arr::mergeRecursiveDistinct($packageManagerOptions, $options);
        } else {
            $options = $packageManagerOptions;
        }

        $install = Installer::create($io, $composer);
        $config = $composer->getConfig();
        $optimize = $config->get('optimize-autoloader');

        // Set preferred install method
        $preferSource = false; // Forces installation from package sources when possible, including VCS information.
        $preferDist = false;

        switch ($config->get('preferred-install')) {
            case 'source':
                $preferSource = true;
                break;
            case 'dist':
                $preferDist = true;
                break;
            case 'auto':
            default:
                break;
        }

        try {
            $install
                ->setDryRun($options['dryrun'])
                ->setVerbose($options['verbose'])
                ->setPreferSource($preferSource)
                ->setPreferDist($preferDist)
                ->setDevMode(!$options['nodev'])
                ->setDumpAutoloader(!$options['noautoloader'])
                ->setRunScripts(!$options['noscripts'])
                ->setOptimizeAutoloader($optimize)
                ->setUpdate(true)
                ->setUpdateWhitelist($packages)
                ->setWhitelistDependencies($options['withdependencies'])
                ->setIgnorePlatformRequirements($options['ignoreplatformreqs'])
                ->setPreferStable($options['preferstable'])
                ->setPreferLowest($options['preferlowest'])
                ->disablePlugins();

            return $install->run();
        } catch (\Exception $e) {
            $msg = __CLASS__ . '::' . __FUNCTION__ . ' recieved an error from Composer: ' . $e->getMessage() . ' in ' . $e->getFile() . '::' . $e->getLine();
            $this->app['logger.system']->critical($msg, array('event' => 'exception', 'exception' => $e));

            throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
        }
    }
}

{'fraction_non_alphanumeric': 0.14049461386739492, 'fraction_numerical': 0.00030344409042633893, 'mean_word_length': 2.0832553788587465, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 79, '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': '959256', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1775, 'n_words': 367}