<commit_before><?php


namespace Nam\Commander;

use Illuminate\Support\Facades\App;
use Nam\Commander\Events\Contracts\Dispatcher;
use Nam\Commander\Exceptions\InvalidCommandArgumentException;
use ReflectionClass;


/**
 * Class BaseCommandHandler
 *
 * @author  <NAME> <<EMAIL>>
 * @package Nam\Commander
 *
 */
abstract class BaseCommandHandler implements CommandHandler
{
    /**
     * @var Dispatcher
     */
    protected $dispatcher;
    /**
     * @var array
     */
    protected $pendingEvents = [ ];

    /**
     * Raise a new event
     *
     * @param $event
     */
    public function raiseEvent($event)
    {
        $this->pendingEvents[] = $event;
    }

    /**
     * Return and reset all pending events
     *
     * @return array
     */
    public function releaseEvents()
    {
        $events = $this->pendingEvents;

        $this->pendingEvents = [ ];

        return $events;
    }

    /**
     * @return Dispatcher
     */
    public function getDispatcher()
    {
        if ( ! $this->dispatcher instanceof Dispatcher) {
            /** @noinspection PhpUndefinedMethodInspection */
            $this->dispatcher = App::make('Nam\Commander\Events\EventDispatcher');
        }

        return $this->dispatcher;
    }

    /**
     * @param Dispatcher $dispatcher
     */
    public function setDispatcher(Dispatcher $dispatcher)
    {
        $this->dispatcher = $dispatcher;
    }

    /**
     * @param BaseCommand $command
     */
    protected function checkValidCommand(BaseCommand $command)
    {
        $commandsNamespace = $this->getCommandsNamespace();

        $commandShortName = $this->getCommandShortName();

        $commandName = "$commandsNamespace\\$commandShortName";

        if ( ! $command instanceof $commandName) {
            throw new InvalidCommandArgumentException($command);
        }
    }

    /**
     * @return ReflectionClass
     */
    protected function getContainsNamespace()
    {
        $reflection = new ReflectionClass($this);

        return $reflection->getNamespaceName();
    }

    /**
     * @return array
     */
    protected function getCommandsNamespace()
    {
        $reflection = new ReflectionClass($this);

        $ns = $reflection->getNamespaceName();
        $segments = explode('\\', $ns);
        array_pop($segments);
        $cmdNs = $segments;

        return implode('\\', $cmdNs);
    }

    /**
     * @return string
     */
    protected function getCommandShortName()
    {
        $handlerShortName = (new ReflectionClass($this))->getShortName();
        $commandShortName = substr($handlerShortName, 0, strlen($handlerShortName) - 7);

        return $commandShortName;
    }

}<commit_msg>Do not need check command valid<commit_after><?php


namespace Nam\Commander;

use Illuminate\Support\Facades\App;
use Nam\Commander\Events\Contracts\Dispatcher;
use Nam\Commander\Exceptions\InvalidCommandArgumentException;
use ReflectionClass;


/**
 * Class BaseCommandHandler
 *
 * @author  <NAME> <<EMAIL>>
 * @package Nam\Commander
 *
 */
abstract class BaseCommandHandler implements CommandHandler
{
    /**
     * @var Dispatcher
     */
    protected $dispatcher;
    /**
     * @var array
     */
    protected $pendingEvents = [ ];

    /**
     * Raise a new event
     *
     * @param $event
     */
    public function raiseEvent($event)
    {
        $this->pendingEvents[] = $event;
    }

    /**
     * Return and reset all pending events
     *
     * @return array
     */
    public function releaseEvents()
    {
        $events = $this->pendingEvents;

        $this->pendingEvents = [ ];

        return $events;
    }

    /**
     * @return Dispatcher
     */
    public function getDispatcher()
    {
        if ( ! $this->dispatcher instanceof Dispatcher) {
            /** @noinspection PhpUndefinedMethodInspection */
            $this->dispatcher = App::make('Nam\Commander\Events\EventDispatcher');
        }

        return $this->dispatcher;
    }

    /**
     * @param Dispatcher $dispatcher
     */
    public function setDispatcher(Dispatcher $dispatcher)
    {
        $this->dispatcher = $dispatcher;
    }

}
{'fraction_non_alphanumeric': 0.12397491558128317, 'fraction_numerical': 0.000482392667631452, 'mean_word_length': 2.2808544303797467, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 28, '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': '4216107', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1154, 'n_words': 233}