<commit_before><?php
namespace App\Shell;

use App\Lib\CakeboxUtility;
use Cake\Console\Shell;

/**
 * Shell class for managing software updates.
 */
class UpdateShell extends AppShell
{

    /**
     * Define available subcommands, arguments and options.
     *
     * @return parser
     */
    public function getOptionParser()
    {
        $parser = parent::getOptionParser();
        $parser->description([__('Manage updates.')]);

        $parser->addSubcommand('self', [
            'parser' => [
                'description' => [
                    __(
                        "Updates your Cakebox Dashboard and Cakebox Commands
                        to the most recent version."
                    )
                ]
            ]
        ]);
        return $parser;
    }

    /**
     * Self-updates the Cakebox Dashboard and Shell commands by updating the
     * cakebox-console Git repository and ALL underlying Composer libraries.
     *
     * @return void
     */
    public function self()
    {
        $this->logStart('Self-updating cakebox');

        // Update Composer
        if (!$this->_updateComposer()) {
            $this->exitBashError();
        }

        // Update Cakebox Commands and Dashboard
        if (!$this->_updateCakeboxConsole()) {
            $this->exitBashError();
        }

        // Execute box-image updates
        if (!$this->_updateCakephpCodeSniffer()) {
            $this->exitBashError();
        }

        $this->exitBashSuccess('Self-update completed successfully');
    }


    /**
     * Self-update global composer to prevent outdated warnings.
     *
     * @return boolean True on success
     */
     protected function _updateComposer()
     {
         $this->logInfo('Self-updating Composer');
         $command = 'composer self-update';
         if (!$this->Execute->shell($command, 'root')) {
             return false;
         }
         return true;
     }

    /**
     * Self-update cakebox-console projeect by self-updating Composer (to
     * prevent outdated warning), updating the git repository and finally
     * running composer update.
     *
     * @return boolean True on success
     */
     protected function _updateCakeboxConsole()
     {
         $this->logInfo('Updating Cakebox Commands and Dashboard');

         $this->logInfo('* Detecting branch');
         $command = 'cd /cakebox/console; git rev-parse --abbrev-ref HEAD';
         $branch = $this->Execute->getShellOutput($command, 'vagrant');
         if (!$branch) {
             return false;
         }
         $this->logDebug(" * Found branch $branch");

         $this->logInfo('* Updating git repository');
         $command = "cd /cakebox/console; git pull origin $branch";
         if (!$this->Execute->shell($command, 'vagrant')) {
             return false;
         }

         $this->logInfo('* Updating composer packages');
         $command = 'cd /cakebox/console; composer install --prefer-dist --no-dev';
         if (!$this->Execute->shell($command, 'vagrant')) {
             return false;
         }
         return true;
     }

    /**
     * Box-fix: composer update globally installed cakephp-codesniffer
     * by updating version in composer.json (if needed) and then running
     * composer update.
     *
     * @return boolean True on success
     */
    protected function _updateCakephpCodeSniffer()
    {
        $this->logInfo('Updating global CakePHP Code Sniffer');

        $path = '/opt/composer-libraries/php_codesniffer';
        $requiredVersion = '2.*';
        $result = CakeboxUtility::updateConfigFile(
            "$path/composer.json",
            [ '2.*@dev' => '2.*' ],
            true // update file as root
        );

        if (!$this->Execute->shell("composer update --working-dir $path", 'root')) {
            return false;
        }
        return true;
    }
}
<commit_msg>Now indeed updates cakephp-codesniffer (shame)<commit_after><?php
namespace App\Shell;

use App\Lib\CakeboxUtility;
use Cake\Console\Shell;

/**
 * Shell class for managing software updates.
 */
class UpdateShell extends AppShell
{

    /**
     * Define available subcommands, arguments and options.
     *
     * @return parser
     */
    public function getOptionParser()
    {
        $parser = parent::getOptionParser();
        $parser->description([__('Manage updates.')]);

        $parser->addSubcommand('self', [
            'parser' => [
                'description' => [
                    __(
                        "Updates your Cakebox Dashboard and Cakebox Commands
                        to the most recent version."
                    )
                ]
            ]
        ]);
        return $parser;
    }

    /**
     * Self-updates the Cakebox Dashboard and Shell commands by updating the
     * cakebox-console Git repository and ALL underlying Composer libraries.
     *
     * @return void
     */
    public function self()
    {
        $this->logStart('Self-updating cakebox');

        // Update Composer
        if (!$this->_updateComposer()) {
            $this->exitBashError();
        }

        // Update Cakebox Commands and Dashboard
        if (!$this->_updateCakeboxConsole()) {
            $this->exitBashError();
        }

        // Update CakePHP Code Sniffer
        if (!$this->_updateCakephpCodeSniffer()) {
            $this->exitBashError();
        }

        $this->exitBashSuccess('Self-update completed successfully');
    }


    /**
     * Self-update global composer to prevent outdated warnings.
     *
     * @return boolean True on success
     */
    protected function _updateComposer()
    {
         $this->logInfo('Self-updating Composer');
         $command = 'composer self-update';
        if (!$this->Execute->shell($command, 'root')) {
            return false;
        }
         return true;
    }

    /**
     * Self-update cakebox-console projeect by self-updating Composer (to
     * prevent outdated warning), updating the git repository and finally
     * running composer update.
     *
     * @return boolean True on success
     */
    protected function _updateCakeboxConsole()
    {
        $this->logInfo('Updating Cakebox Commands and Dashboard');

        $this->logInfo('* Detecting branch');
        $command = 'cd /cakebox/console; git rev-parse --abbrev-ref HEAD';
        $branch = $this->Execute->getShellOutput($command, 'vagrant');
        if (!$branch) {
            return false;
        }
        $this->logDebug(" * Found branch $branch");

        $this->logInfo('* Updating git repository');
        $command = "cd /cakebox/console; git pull origin $branch";
        if (!$this->Execute->shell($command, 'vagrant')) {
            return false;
        }

        $this->logInfo('* Updating composer packages');
        $command = 'cd /cakebox/console; composer install --prefer-dist --no-dev';
        if (!$this->Execute->shell($command, 'vagrant')) {
            return false;
        }
        return true;
    }

    /**
     * Box-fix: composer update globally installed cakephp-codesniffer
     * by updating version in composer.json (if needed) and then running
     * composer update.
     *
     * @return boolean True on success
     */
    protected function _updateCakephpCodeSniffer()
    {
        $this->logInfo('Updating global CakePHP Code Sniffer');

        // update package version in composer.json to 2.*
        $path = '/opt/composer-libraries/cakephp_codesniffer';
        $requiredVersion = '2.*';
        $result = CakeboxUtility::updateConfigFile(
            "$path/composer.json",
            [ '2.*@dev' => '2.*' ],
            true // update file as root
        );

        // composer update
        $this->logInfo('* Composer updating');
        $command = "composer update --no-dev --working-dir $path";
        if (!$this->Execute->shell($command, 'root')) {
            return false;
        }

    #        $this->logInfo('* Enabling Coding Standard');
    #        $csPath = $path . '/vendor/cakephp/cakephp-codesniffer';
    #        $command = "phpcs --config-set installed_paths $csPath";
    #        if (!$this->Execute->shell($command, 'root')) {
    #            return false;
    #        }

            // Repair broken standard CakePHP as default sniffer
    #        $this->logInfo('* Setting CakePHP as default Coding Standard');
    #        $command = "phpcs --config-set default_standard $path";
    #        if (!$this->Execute->shell($command, 'root')) {
    #            return false;
    #        }

        return true;
    }
}

{'fraction_non_alphanumeric': 0.12590263219194037, 'fraction_numerical': 0.000815280689494526, 'mean_word_length': 1.902974983096687, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 70, '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': '484874', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2292, 'n_words': 591}