<commit_before><?php

namespace Everzet\Behat\Loader;

use Symfony\Component\Finder\Finder;

use Everzet\Gherkin\Element\StepElement;
use Everzet\Gherkin\Element\Inline\PyStringElement;
use Everzet\Gherkin\Element\Inline\TableElement;

use Everzet\Behat\Definition\StepDefinition;
use Everzet\Behat\Environment\EnvironmentInterface;
use Everzet\Behat\Exception\Redundant;
use Everzet\Behat\Exception\Ambiguous;
use Everzet\Behat\Exception\Undefined;

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

/**
 * Steps Container
 *
 * @package     behat
 * @subpackage  Behat
 * @author      <NAME> <<EMAIL>>
 */
class StepsLoader
{
    protected $steps = array();

    /**
     * Creates steps container & load step definitions
     *
     * @param   \Iterator   $definitionFiles    step definition files
     * @param   World       $world              world object instance
     */
    public function __construct($path, EnvironmentInterface $world = null)
    {
        $steps = $this;

        $finder = new Finder();
        foreach ($finder->files()->name('*.php')->in($path) as $definitionFile) {
            require $definitionFile;
        }
    }

    /**
     * Define a step with ->Given('/regex/', callback)
     *
     * @param   string  $type       step type (Given/When/Then/And or localized one)
     * @param   string  $arguments  step regex & callback
     * 
     * @throws  \Everzet\Behat\Exceptions\Redundant if step definition is already exists
     */
    public function __call($type, $arguments)
    {
        $debug = debug_backtrace();
        $debug = $debug[1];

        $definition = new StepDefinition(
            $type, $arguments[0], $arguments[1], $debug['file'], $debug['line']
        );

        if (isset($this->steps[$definition->getRegex()])) {
            throw new Redundant(
                $definition, $this->steps[$definition->getRegex()]
            );
        }

        $this->steps[$definition->getRegex()] = $definition;

        return $this;
    }

    /**
     * Translates step description into definition
     *
     * @param   Step    $step   step instance
     * @param   string  $text   step test
     * 
     * @return  string          definition
     */
    public function proposeDefinition(StepElement $step)
    {
        $text   = $step->getText();
        $args   = $step->getArguments();

        $regexp = preg_replace(
            array('/\"([^\"]*)\"/', '/(\d+)/'), array("\"([^\"]*)\"", "(\\d+)"), $text, -1, $count
        );

        $args = array();
        for ($i = 0; $i < $count; $i++) {
            $args[] = "\$arg".($i + 1);
        }

        foreach ($args as $argument) {
            if ($argument instanceof PyStringElement) {
                $args[] = "\$string";
            } elseif ($argument instanceof TableElement) {<commit_msg>fixed propose to include PyStrings & Tables in snippets<commit_after><?php

namespace Everzet\Behat\Loader;

use Symfony\Component\Finder\Finder;

use Everzet\Gherkin\Element\StepElement;
use Everzet\Gherkin\Element\Inline\PyStringElement;
use Everzet\Gherkin\Element\Inline\TableElement;

use Everzet\Behat\Definition\StepDefinition;
use Everzet\Behat\Environment\EnvironmentInterface;
use Everzet\Behat\Exception\Redundant;
use Everzet\Behat\Exception\Ambiguous;
use Everzet\Behat\Exception\Undefined;

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

/**
 * Steps Container
 *
 * @package     behat
 * @subpackage  Behat
 * @author      <NAME> <<EMAIL>>
 */
class StepsLoader
{
    protected $steps = array();

    /**
     * Creates steps container & load step definitions
     *
     * @param   \Iterator   $definitionFiles    step definition files
     * @param   World       $world              world object instance
     */
    public function __construct($path, EnvironmentInterface $world = null)
    {
        $steps = $this;

        $finder = new Finder();
        foreach ($finder->files()->name('*.php')->in($path) as $definitionFile) {
            require $definitionFile;
        }
    }

    /**
     * Define a step with ->Given('/regex/', callback)
     *
     * @param   string  $type       step type (Given/When/Then/And or localized one)
     * @param   string  $arguments  step regex & callback
     * 
     * @throws  \Everzet\Behat\Exceptions\Redundant if step definition is already exists
     */
    public function __call($type, $arguments)
    {
        $debug = debug_backtrace();
        $debug = $debug[1];

        $definition = new StepDefinition(
            $type, $arguments[0], $arguments[1], $debug['file'], $debug['line']
        );

        if (isset($this->steps[$definition->getRegex()])) {
            throw new Redundant(
                $definition, $this->steps[$definition->getRegex()]
            );
        }

        $this->steps[$definition->getRegex()] = $definition;

        return $this;
    }

    /**
     * Translates step description into definition
     *
     * @param   Step    $step   step instance
     * @param   string  $text   step test
     * 
     * @return  string          definition
     */
    public function proposeDefinition(StepElement $step)
    {
        $text = $step->getText();

        $regexp = preg_replace(
            array('/\"([^\"]*)\"/', '/(\d+)/'), array("\"([^\"]*)\"", "(\\d+)"), $text, -1, $count
        );

        $args = array();
        for ($i = 0; $i < $count; $i++) {
            $args[] = "\$arg".($i + 1);
        }

        foreach ($step->getArguments() as $argument) {
            if ($argument instanceof PyStringElement) {
                $args[] = "\$string";
            } elseif ($argument instanceof TableElement) {
{'fraction_non_alphanumeric': 0.14290500921427374, 'fraction_numerical': 0.0033506449991623386, 'mean_word_length': 2.28021978021978, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, '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': '5616044', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1715, 'n_words': 439}