<commit_before><?php namespace EventSourcing\Laravel\Commands;

use EventSourcing\EventDispatcher\EventDispatcher;
use EventSourcing\Serialization\Deserializer;
use Illuminate\Console\Command;

class RebuildProjectionsCommand extends Command
{
    use Deserializer;

    /**
     * @var
     */
    private $app;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = "event-sourcing:rebuild-projections";

    /**
     * The console command description
     *
     * @var string
     */
    protected $description = 'Rebuild all the projections by cleaning migrations and replaying events.';

    public function __construct($app)
    {
        parent::__construct();

        $this->app = $app;
        $this->dispatcher = $this->app->make(EventDispatcher::class);
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->info($this->fillWith("Reset and re-run all migrations", "="));
        $this->call("migrate:refresh");

        $this->info($this->fillWith("Loading events from EventStore"));
        $events = $this->getAllEvents();

        $this->output->progressStart(count($events));

        foreach ($events as $event) {
            $event = $this->deserialize(json_decode($event->payload, true));

//            $this->dispatcher->dispatch($event);

            $this->output->progressAdvance();
        }

        $this->output->progressFinish();
    }

    private function getAllEvents()
    {
        return $this->app['db']
                ->connection('eventstore')
                ->table('eventstore')
                ->select(['uuid', 'version', 'payload', 'type', 'recorded_on'])
                ->get();
    }

    public function fillWith($string, $fillWith = "=", $width = 80)
    {
        if (! ((strlen($string) + 4) <= $width)) {
            return $string;
        }

        $string = " " . $string . " ";
        $count = strlen($string);
        $halve = floor(($width - $count) / 2);

        $newString = str_repeat($fillWith, $halve) . $string . str_repeat($fillWith, $halve);

        if (strlen($newString) <= $width) {
            $newString .= str_repeat($fillWith, $width - strlen($newString));
        }

        return $newString;
    }
}<commit_msg>Adding Steps<commit_after><?php namespace EventSourcing\Laravel\Commands;

use EventSourcing\EventDispatcher\EventDispatcher;
use EventSourcing\Serialization\Deserializer;
use Illuminate\Console\Command;

class RebuildProjectionsCommand extends Command
{
    use Deserializer;

    /**
     * @var
     */
    private $app;

    private $steps = 1;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = "event-sourcing:rebuild-projections";

    /**
     * The console command description
     *
     * @var string
     */
    protected $description = 'Rebuild all the projections by cleaning migrations and replaying events.';

    public function __construct($app)
    {
        parent::__construct();

        $this->app = $app;
        $this->dispatcher = $this->app->make(EventDispatcher::class);
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->stepTitle("Reset and re-run all migrations");
        $this->call("migrate:refresh");

        $this->stepTitle("Loading events from EventStore");
        $events = $this->getAllEvents();

        $this->output->progressStart(count($events));

        foreach ($events as $event) {
            $event = $this->deserialize(json_decode($event->payload, true));

//            $this->dispatcher->dispatch($event);

            $this->output->progressAdvance();
        }

        $this->output->progressFinish();
    }

    private function getAllEvents()
    {
        return $this->app['db']
                ->connection('eventstore')
                ->table('eventstore')
                ->select(['uuid', 'version', 'payload', 'type', 'recorded_on'])
                ->get();
    }

    private function stepTitle($string, $fillWith = "=", $width = 80)
    {
        $this->info($this->fillWith("Step " . $this->steps . ") " . $string, $fillWith, $width));

        $this->steps++;
    }

    private function fillWith($string, $fillWith = "=", $width = 80)
    {
        if (! ((strlen($string) + 6) <= $width)) {
            return $string;
        }

        $string = "  " . $string . "  ";
        $count = strlen($string);
        $halve = floor(($width - $count) / 2);

        $newString = str_repeat($fillWith, $halve) . $string . str_repeat($fillWith, $halve);

        if (strlen($newString) <= $width) {
            $newString .= str_repeat($fillWith, $width - strlen($newString));
        }

        return PHP_EOL . $newString . PHP_EOL . PHP_EOL;
    }
}
{'fraction_non_alphanumeric': 0.1541429731925264, 'fraction_numerical': 0.0022339561332250205, 'mean_word_length': 2.246539222148978, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 55, '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': '1685961', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1399, 'n_words': 293}