<commit_before><?php

namespace CubicMushroom\Hexagonal\Command;

use CubicMushroom\Hexagonal\Event\CommandFailedEventInterface;
use CubicMushroom\Hexagonal\Event\CommandSucceededEventInterface;
use CubicMushroom\Hexagonal\Exception\Command\InvalidCommandException;
use League\Event\EmitterInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;

/**
 * Class AbstractCommandHandler
 *
 * @package CubicMushroom\Hexagonal
 *
 * @see \spec\CubicMushroom\Hexagonal\Command\AbstractCommandHandlerSpec
 */
abstract class AbstractCommandHandler implements CommandHandlerInterface
{
    // -----------------------------------------------------------------------------------------------------------------
    // Static factory methods
    // -----------------------------------------------------------------------------------------------------------------

    /**
     * @param ValidatorInterface $validator
     * @param EmitterInterface   $emitter
     *
     * @return static
     */
    public static function createBasic(ValidatorInterface $validator, EmitterInterface $emitter)
    {
        $abstractCommandHandler = new static();

        $abstractCommandHandler->validator = $validator;
        $abstractCommandHandler->emitter = $emitter;

        return $abstractCommandHandler;
    }

    // -----------------------------------------------------------------------------------------------------------------
    // Properties
    // -----------------------------------------------------------------------------------------------------------------
    /**
     * @var ValidatorInterface
     */
    private $validator;

    /**
     * @var EmitterInterface
     */
    private $emitter;


    /**
     * Use factory methods to create
     */
    private function __construct()
    {
    }


    /**
     * Processes the associated command
     *
     * @param CommandInterface $command
     *
     * @throws \Exception if _handler() throws an error
     */
    final public function handle(CommandInterface $command)
    {
        $this->checkCommandType($command);

        $this->validator->validate($command);

        try {
            $this->_handle($command);
        } catch (\Exception $exception) {
            $failureEvent = $this->getFailureEvent($exception);
            $this->emitter->emit($failureEvent);
            throw $exception;
        }

        $event = $this->getSuccessEvent($command);
<commit_msg>Made properties protected, as couldn't set form static createBasic() method<commit_after><?php

namespace CubicMushroom\Hexagonal\Command;

use CubicMushroom\Hexagonal\Event\CommandFailedEventInterface;
use CubicMushroom\Hexagonal\Event\CommandSucceededEventInterface;
use CubicMushroom\Hexagonal\Exception\Command\InvalidCommandException;
use League\Event\EmitterInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;

/**
 * Class AbstractCommandHandler
 *
 * @package CubicMushroom\Hexagonal
 *
 * @see \spec\CubicMushroom\Hexagonal\Command\AbstractCommandHandlerSpec
 */
abstract class AbstractCommandHandler implements CommandHandlerInterface
{
    // -----------------------------------------------------------------------------------------------------------------
    // Static factory methods
    // -----------------------------------------------------------------------------------------------------------------

    /**
     * @param ValidatorInterface $validator
     * @param EmitterInterface   $emitter
     *
     * @return static
     */
    public static function createBasic(ValidatorInterface $validator, EmitterInterface $emitter)
    {
        $abstractCommandHandler = new static();

        $abstractCommandHandler->validator = $validator;
        $abstractCommandHandler->emitter = $emitter;

        return $abstractCommandHandler;
    }

    // -----------------------------------------------------------------------------------------------------------------
    // Properties
    // -----------------------------------------------------------------------------------------------------------------
    /**
     * @var ValidatorInterface
     */
    protected $validator;

    /**
     * @var EmitterInterface
     */
    protected $emitter;


    /**
     * Use factory methods to create
     */
    protected function __construct()
    {
    }


    /**
     * Processes the associated command
     *
     * @param CommandInterface $command
     *
     * @throws \Exception if _handler() throws an error
     */
    final public function handle(CommandInterface $command)
    {
        $this->checkCommandType($command);

        $this->validator->validate($command);

        try {
            $this->_handle($command);
        } catch (\Exception $exception) {
            $failureEvent = $this->getFailureEvent($exception);
            $this->emitter->emit($failureEvent);
            throw $exception;
        }

        $event = $this->getSuccessEvent($command);

{'fraction_non_alphanumeric': 0.2670431625655506, 'fraction_numerical': 0.0, 'mean_word_length': 1.4994959677419355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '6631530', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1061, 'n_words': 211}