<commit_before><?php

namespace Exylon\Fuse\Console;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

class SubscriberMakeCommand extends GeneratorCommand
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'make:subscriber';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a new events subscriber class';

    /**
     * The type of class being generated.
     *
     * @var string
     */
    protected $type = 'Subscriber';


    protected $methodSnippet = 'public function onDummyEvent(DummyEvent $event)
    {
        //
    }
    
    //METHOD_BLOCK';

    protected $listenSnippet = '$events->listen(\'DummyFullEvent\', \'DummyNamespace\DummyClass@onDummyEvent\');
        //LISTEN_BLOCK';

    protected $fullEventSnippet = 'use DummyFullEvent;
//USE_BLOCK';

    /**
     * Build the class with the given name.
     *
     * @param  string $name
     *
     * @return string
     */
    protected function buildClass($name)
    {
        $events = $this->option('event');
        $stub = $stub = $this->files->get($this->getStub());;
        foreach ($events as $event) {
            $event = $this->resolveEvent($event);


            $stub = str_replace_assoc([
                '//METHOD_BLOCK' => $this->methodSnippet,
                '//LISTEN_BLOCK' => $this->listenSnippet,
                '//USE_BLOCK' => $this->fullEventSnippet,
            ], $stub);
            $stub = str_replace(
                'DummyEvent', class_basename($event), $stub
            );
            $stub = str_replace(
                'DummyFullEvent', $event, $stub
            );
        }

        $stub = str_replace_assoc([
            '//METHOD_BLOCK' => '',
            '//LISTEN_BLOCK' => ''
        ], $stub);
        return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name);

    }

    protected function resolveEvent($event)
    {
        if (!Str::startsWith($event, [
            $this->laravel->getNamespace(),
            'Illuminate',
            '\\',
        ])) {
            $event = $this->laravel->getNamespace() . 'Events\\' . $event;
        }
        return $event;
    }

    /**
     * Get the stub file for the generator.
     *
     * @return string
     */
    protected function getStub()
    {
        return $this->option('event')
            ? __DIR__ . '/stubs/subscriber.stub'
            : __DIR__ . '/stubs/subscriber-duck.stub';
    }<commit_msg>Changed full event class to shorthand class inside listen<commit_after><?php

namespace Exylon\Fuse\Console;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

class SubscriberMakeCommand extends GeneratorCommand
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'make:subscriber';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a new events subscriber class';

    /**
     * The type of class being generated.
     *
     * @var string
     */
    protected $type = 'Subscriber';


    protected $methodSnippet = 'public function onDummyEvent(DummyEvent $event)
    {
        //
    }
    
    //METHOD_BLOCK';

    protected $listenSnippet = '$events->listen(DummyEvent::class, \'DummyNamespace\DummyClass@onDummyEvent\');
        //LISTEN_BLOCK';

    protected $fullEventSnippet = 'use DummyFullEvent;
//USE_BLOCK';

    /**
     * Build the class with the given name.
     *
     * @param  string $name
     *
     * @return string
     */
    protected function buildClass($name)
    {
        $events = $this->option('event');
        $stub = $stub = $this->files->get($this->getStub());;
        foreach ($events as $event) {
            $event = $this->resolveEvent($event);


            $stub = str_replace_assoc([
                '//METHOD_BLOCK' => $this->methodSnippet,
                '//LISTEN_BLOCK' => $this->listenSnippet,
                '//USE_BLOCK' => $this->fullEventSnippet,
            ], $stub);
            $stub = str_replace(
                'DummyEvent', class_basename($event), $stub
            );
            $stub = str_replace(
                'DummyFullEvent', $event, $stub
            );
        }

        $stub = str_replace_assoc([
            '//METHOD_BLOCK' => '',
            '//LISTEN_BLOCK' => '',
            '//USE_BLOCK'   =>  ''
        ], $stub);
        return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name);

    }

    protected function resolveEvent($event)
    {
        if (!Str::startsWith($event, [
            $this->laravel->getNamespace(),
            'Illuminate',
            '\\',
        ])) {
            $event = $this->laravel->getNamespace() . 'Events\\' . $event;
        }
        return $event;
    }

    /**
     * Get the stub file for the generator.
     *
     * @return string
     */
    protected function getStub()
    {
        return $this->option('event')
            ? __DIR__ . '/stubs/subscriber.stub'
            : __DIR__ . '/stubs/subscriber-duck.stub';
    }
{'fraction_non_alphanumeric': 0.14198589670287784, 'fraction_numerical': 0.0, 'mean_word_length': 1.8756164383561644, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '2749074', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1545, 'n_words': 307}