<commit_before><?php

namespace Cesargb\Update\Commands;

use Cesargb\Update\Notifications\HasError;
use Cesargb\Update\Notifications\Updated;
use Illuminate\Console\Command;

class Update extends Command
{
    protected $signature = 'update:packages
                            {--notify} : Must notified the changes';
    protected $description = 'Updates of composer packages';

    const MARK = '  - Installing ';

    public function handle()
    {
        $composer_bin = config('update.composer_bin', 'composer');
        $no_dev = config('update.require-dev', false) ?: ' --no-dev';

        exec($composer_bin.' update '.$no_dev.' 2>&1', $out, $ret);

        if ($ret !== 0) {
            if ($this->option('notify')) {
                app(config('update.notifications.notifiable'))->notify(new HasError($out[0]));
            }
            throw ExceptionExecCommand::create(explode("\n", $this->signature)[0], $ret, $out[0]);
        } else {
            $packages_updated = [];
            foreach ($out as $line) {
                if (starts_with($line, self::MARK)) {
                    $package_updated = explode(' ', str_after($line, self::MARK));
                    if (count($package_updated) > 1) {
                        $packages_updated[] = [
                            'package'   => $package_updated[0],
                            'version'   => str_replace(['(', ')'], '', $package_updated[1]),
                        ];
                    }
                }
            }
            if (count($packages_updated) === 0) {
                $this->info('All is correct! No updates pending');
            } else {
                $this->info(count($packages_updated).' package(s) updated.', 'comment');
                foreach ($packages_updated as $update) {
                    $this->info(' - '.$update['package'].': '.$update['version']);
                }
                if ($this->option('notify')) {
                    app(config('update.notifications.notifiable'))->notify(new Updated($updates));
                }
            }
        }
    }
}<commit_msg>Update Update.php<commit_after><?php

namespace Cesargb\Update\Commands;

use Cesargb\Update\Notifications\HasError;
use Cesargb\Update\Notifications\Updated;
use Illuminate\Console\Command;

class Update extends Command
{
    protected $signature = 'update:packages
                            {--notify} : Must notified the changes';
    protected $description = 'Updates of composer packages';

    const MARK = '  - Installing ';

    public function handle()
    {
        $composer_bin = config('update.composer_bin', 'composer');
        $no_dev = config('update.require-dev', false) ?: ' --no-dev';

        exec($composer_bin.' update '.$no_dev.' 2>&1', $out, $ret);

        if ($ret !== 0) {
            if ($this->option('notify')) {
                app(config('update.notifications.notifiable'))->notify(new HasError($out[0]));
            }
            throw ExceptionExecCommand::create(explode("\n", $this->signature)[0], $ret, $out[0]);
        } else {
            $packages_updated = [];
            foreach ($out as $line) {
                if (starts_with($line, self::MARK)) {
                    $package_updated = explode(' ', str_after($line, self::MARK));
                    if (count($package_updated) > 1) {
                        $packages_updated[] = [
                            'package'   => $package_updated[0],
                            'version'   => str_replace(['(', ')'], '', $package_updated[1]),
                        ];
                    }
                }
            }
            if (count($packages_updated) === 0) {
                $this->info('All is correct! No updates pending');
            } else {
                $this->info(count($packages_updated).' package(s) updated.', 'comment');
                foreach ($packages_updated as $update) {
                    $this->info(' - '.$update['package'].': '.$update['version']);
                }
                if ($this->option('notify')) {
                    app(config('update.notifications.notifiable'))->notify(new Updated($packages_updated));
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.15744478746141058, 'fraction_numerical': 0.0047494656851104254, 'mean_word_length': 1.7547416612164815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '2608018', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1101, 'n_words': 211}