<commit_before><?php

namespace Behat\Behat\Tester;

/*
 * This file is part of the Behat.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use Behat\Behat\Callee\Event\ExecuteCalleeEvent;
use Behat\Behat\Context\Pool\ContextPoolInterface;
use Behat\Behat\Definition\Event\DefinitionCarrierEvent;
use Behat\Behat\Definition\Event\ExecuteDefinitionEvent;
use Behat\Behat\Event\EventInterface;
use Behat\Behat\Event\StepEvent;
use Behat\Behat\EventDispatcher\DispatchingService;
use Behat\Behat\Exception\PendingException;
use Behat\Behat\Exception\UndefinedException;
use Behat\Behat\Snippet\Event\SnippetCarrierEvent;
use Behat\Behat\Snippet\SnippetInterface;
use Behat\Behat\Suite\SuiteInterface;
use Behat\Gherkin\Node\ScenarioNode;
use Behat\Gherkin\Node\StepNode;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Step DispatchingTester.
 *
 * @author <NAME> <<EMAIL>>
 */
class StepTester extends DispatchingService
{
    /**
     * Tests step.
     *
     * @param SuiteInterface       $suite
     * @param ContextPoolInterface $contexts
     * @param StepNode             $step
     * @param ScenarioNode         $scenario
     *
     * @return integer
     */
    public function test(
        SuiteInterface $suite,
        ContextPoolInterface $contexts,
        StepNode $step,
        ScenarioNode $scenario
    )
    {
        $event = new StepEvent($suite, $contexts, $scenario, $step);
        $this->dispatch(EventInterface::BEFORE_STEP, $event);

        $result = StepEvent::PASSED;
        $execution = $exception = $snippet = null;

        try {
            $execution = $this->getExecutionEvent($suite, $step, $contexts);
            $this->dispatch(EventInterface::EXECUTE_DEFINITION, $execution);
        } catch (PendingException $e) {
            $result = StepEvent::PENDING;
            $exception = $e;
        } catch (UndefinedException $e) {
            $result = StepEvent::UNDEFINED;
            $exception = $e;
            $snippet = $this->getDefinitionSnippet($suite, $step, $contexts);
        } catch (\Exception $e) {
            $result = StepEvent::FAILED;
            $exception = $e;
        }

        $definition = null;
        if ($execution) {
            $definition = $execution->getCallee();
        }

        $event = new StepEvent(
            $suite, $contexts, $scenario, $step, $result, $exception, $definition, $snippet
        );
        $this->dispatch(EventInterface::AFTER_STEP, $event);

        return $result;
    }

    /**
     * Returns execution event.
     *
     * @param SuiteInterface       $suite
     * @param StepNode             $step
     * @param ContextPoolInterface $contexts
     *
     * @throws UndefinedException
     *
     * @return ExecuteCalleeEvent
     */
    protected function getExecutionEvent(
        SuiteInterface $suite,
        StepNode $step,
        ContextPoolInterface $contexts
    )
    {
        $definitionProvider = new DefinitionCarrierEvent($suite, $contexts, $step);
        $this->dispatch(EventInterface::FIND_DEFINITION, $definitionProvider);

        if (!$definitionProvider->hasDefinition()) {<commit_msg>Clean StepTester a bit more<commit_after><?php

namespace Behat\Behat\Tester;

/*
 * This file is part of the Behat.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use Behat\Behat\Callee\Event\ExecuteCalleeEvent;
use Behat\Behat\Context\Pool\ContextPoolInterface;
use Behat\Behat\Definition\Event\DefinitionCarrierEvent;
use Behat\Behat\Definition\Event\ExecuteDefinitionEvent;
use Behat\Behat\Event\EventInterface;
use Behat\Behat\Event\StepEvent;
use Behat\Behat\EventDispatcher\DispatchingService;
use Behat\Behat\Exception\PendingException;
use Behat\Behat\Exception\UndefinedException;
use Behat\Behat\Snippet\Event\SnippetCarrierEvent;
use Behat\Behat\Snippet\SnippetInterface;
use Behat\Behat\Suite\SuiteInterface;
use Behat\Gherkin\Node\ScenarioNode;
use Behat\Gherkin\Node\StepNode;
use Exception;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Step DispatchingTester.
 *
 * @author <NAME> <<EMAIL>>
 */
class StepTester extends DispatchingService
{
    /**
     * Tests step.
     *
     * @param SuiteInterface       $suite
     * @param ContextPoolInterface $contexts
     * @param StepNode             $step
     * @param ScenarioNode         $scenario
     *
     * @return integer
     */
    public function test(
        SuiteInterface $suite,
        ContextPoolInterface $contexts,
        StepNode $step,
        ScenarioNode $scenario
    )
    {
        $event = new StepEvent($suite, $contexts, $scenario, $step);
        $this->dispatch(EventInterface::BEFORE_STEP, $event);

        $result = StepEvent::PASSED;
        $execution = $exception = $snippet = null;

        try {
            $execution = $this->getExecutionEvent($suite, $step, $contexts);
            $this->dispatch(EventInterface::EXECUTE_DEFINITION, $execution);
        } catch (PendingException $e) {
            $result = StepEvent::PENDING;
            $exception = $e;
        } catch (UndefinedException $e) {
            $result = StepEvent::UNDEFINED;
            $exception = $e;
            $snippet = $this->getDefinitionSnippet($suite, $step, $contexts);
        } catch (Exception $e) {
            $result = StepEvent::FAILED;
            $exception = $e;
        }

        $definition = $execution ? $execution->getCallee() : null;

        $event = new StepEvent(
            $suite, $contexts, $scenario, $step, $result, $exception, $definition, $snippet
        );
        $this->dispatch(EventInterface::AFTER_STEP, $event);

        return $result;
    }

    /**
     * Returns execution event.
     *
     * @param SuiteInterface       $suite
     * @param StepNode             $step
     * @param ContextPoolInterface $contexts
     *
     * @throws UndefinedException
     *
     * @return ExecuteCalleeEvent
     */
    protected function getExecutionEvent(
        SuiteInterface $suite,
        StepNode $step,
        ContextPoolInterface $contexts
    )
    {
        $definitionProvider = new DefinitionCarrierEvent($suite, $contexts, $step);
        $this->dispatch(EventInterface::FIND_DEFINITION, $definitionProvider);

        if (!$definitionProvider->hasDefinition()) {
{'fraction_non_alphanumeric': 0.11232665639445301, 'fraction_numerical': 0.0, 'mean_word_length': 2.75854082223509, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 31, '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': '4025733', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1879, 'n_words': 402}