<commit_before><?php

namespace ZfcTwig\Service;

use RuntimeException;
use Twig_Environment;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcTwig\Twig\Func\ViewHelper;

class TwigEnvironmentFactory implements FactoryInterface
{
    /**
     * Create service
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @return mixed
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config  = $serviceLocator->get('Configuration');
        $config  = $config['zfctwig'];
        $env     = new Twig_Environment(null, (array) $config['environment_options']);

        if ($config['enable_fallback_functions']) {
            $helperPluginManager = $serviceLocator->get('ViewHelperManager');
            $env->registerUndefinedFunctionCallback(function($name) use ($helperPluginManager) {
                if ($helperPluginManager->has($name)) {
                    return new ViewHelper($name);
                }
                return null;
            });
        }

        if (!$serviceLocator->has($config['environment_loader'])) {
            throw new RuntimeException(sprintf(
                'Loader with alias "%s" could not be found!',
                $config['loader']
            ));
        }

        $env->setLoader($serviceLocator->get($config['environment_loader']));

        // Extensions are loaded later to avoid circular dependencies (for example, if an extension needs Renderer).
        return $env;
    }
}<commit_msg>Return false for undefined functions, not null<commit_after><?php

namespace ZfcTwig\Service;

use RuntimeException;
use Twig_Environment;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcTwig\Twig\Func\ViewHelper;

class TwigEnvironmentFactory implements FactoryInterface
{
    /**
     * Create service
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @return mixed
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config  = $serviceLocator->get('Configuration');
        $config  = $config['zfctwig'];
        $env     = new Twig_Environment(null, (array) $config['environment_options']);

        if ($config['enable_fallback_functions']) {
            $helperPluginManager = $serviceLocator->get('ViewHelperManager');
            $env->registerUndefinedFunctionCallback(function($name) use ($helperPluginManager) {
                if ($helperPluginManager->has($name)) {
                    return new ViewHelper($name);
                }
                return false;
            });
        }

        if (!$serviceLocator->has($config['environment_loader'])) {
            throw new RuntimeException(sprintf(
                'Loader with alias "%s" could not be found!',
                $config['loader']
            ));
        }

        $env->setLoader($serviceLocator->get($config['environment_loader']));

        // Extensions are loaded later to avoid circular dependencies (for example, if an extension needs Renderer).
        return $env;
    }
}
{'fraction_non_alphanumeric': 0.11093350383631713, 'fraction_numerical': 0.0, 'mean_word_length': 2.6942148760330578, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6030031', 'n_tokens_mistral': 802, 'n_tokens_neox': 782, 'n_words': 172}