<commit_before><?php
namespace Fumocker;

class MockGenerator
{
    /**
     * @throws \LogicException if the function has already been created by a user in the given namespace
     * @throws \LogicException if the function has already been mocked in the given namespace
     *
     * @param Proxy $proxy
     *
     * @return void
     */
    public function generate($functionName, $namespace)
    {
        if (\function_exists("$namespace\\$functionName") && false == $this->isMocked($functionName, $namespace)) {
            throw new \LogicException(sprintf(
                'The function `%s` in the namespace `%s` has already been defined by a user',
                $functionName,
                $namespace
            ));
        }
        if ($this->isMocked($functionName, $namespace)) {
            throw new \LogicException(sprintf(
                'The function `%s` in the namespace `%s` has been already mocked',
                $functionName,
                $namespace
            ));
        }

        $constantName = $this->generateConstant($functionName);
        $identifier = "$namespace\\$functionName";

        $code =
"
namespace {$namespace};

const {$constantName} = '{$identifier}';

function {$functionName}()
{
    \$callable = \\Fumocker\\CallbackRegistry::getInstance()->get('{$identifier}');

    return \\call_user_func_array(\$callable, \\func_get_args());
}
";
        eval($code);

        return $identifier;
    }

    /**
     * @param Proxy $proxy
     *
     * @return bool
     */
    public function isMocked($functionName, $namespace)
    {
        return defined($namespace . '\\' . $this->generateConstant($functionName));
    }

    /**
     * @param Proxy $proxy
     *
     * @return string
     */
    protected function generateConstant($functionName)
    {
        return '__FUMOCKER_'.strtoupper($functionName);
    }
}<commit_msg>[generator] rename method `generateConstant` to `generateConstantName`<commit_after><?php
namespace Fumocker;

class MockGenerator
{
    /**
     * @throws \LogicException if the function has already been created by a user in the given namespace
     * @throws \LogicException if the function has already been mocked in the given namespace
     *
     * @param Proxy $proxy
     *
     * @return void
     */
    public function generate($functionName, $namespace)
    {
        if (\function_exists("$namespace\\$functionName") && false == $this->isMocked($functionName, $namespace)) {
            throw new \LogicException(sprintf(
                'The function `%s` in the namespace `%s` has already been defined by a user',
                $functionName,
                $namespace
            ));
        }
        if ($this->isMocked($functionName, $namespace)) {
            throw new \LogicException(sprintf(
                'The function `%s` in the namespace `%s` has been already mocked',
                $functionName,
                $namespace
            ));
        }

        $constantName = $this->generateConstantName($functionName);
        $identifier = "$namespace\\$functionName";

        $code =
"
namespace {$namespace};

const {$constantName} = '{$identifier}';

function {$functionName}()
{
    \$callable = \\Fumocker\\CallbackRegistry::getInstance()->get('{$identifier}');

    return \\call_user_func_array(\$callable, \\func_get_args());
}
";
        eval($code);

        return $identifier;
    }

    /**
     * @param Proxy $proxy
     *
     * @return bool
     */
    public function isMocked($functionName, $namespace)
    {
        return defined($namespace . '\\' . $this->generateConstantName($functionName));
    }

    /**
     * @param Proxy $proxy
     *
     * @return string
     */
    protected function generateConstantName($functionName)
    {
        return '__FUMOCKER_'.strtoupper($functionName);
    }
}
{'fraction_non_alphanumeric': 0.1293842556508184, 'fraction_numerical': 0.0, 'mean_word_length': 2.30188679245283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2989349', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1037, 'n_words': 261}