<commit_before><?php

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

namespace Ecommit\UtilBundle\Helper;

use Symfony\Component\DependencyInjection\ContainerInterface;

class UtilHelper
{
    /**
     * ContainerInterface and not directly services: Because some services need request
     * (e.g.: "templating.helper.assets") and throw InactiveScopeException
     * 
     * @var ContainerInterface 
     */
    protected $container = null;
    
    /**
     * Constructor
     * 
     * @param ContainerInterface $container 
     */
    public function __construct(ContainerInterface $container) 
    {
        $this->container = $container;
    }
    
    /**
     * Gets a service.
     * WARNING ! Use this method only is required. NOT ABUSE.
     * 
     * @See ContainerInterface:get
     */
    public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
    {
        return $this->container->get($id, $invalidBehavior);
    }
    
    /**
     * Constructs an html tag
     * 
     * @param string $name Tag name
     * @param array $options Tag options
     * @param string $content Content
     * @param bool $open True to leave tag open
     * @return string 
     */
    public function tag($name, Array $options = array(), $content = null, $open = false)
    {
        if (!$name)
        {
            return '';
        }
        $options_html = '';
        foreach ($options as $key => $value)
        {
            $options_html .= ' '.$key.'="'.\htmlspecialchars($value, \ENT_COMPAT).'"';
        }
        if($content !== null)
        {
            return '<'.$name.$options_html.'>'.$content.'</'.$name.'>';
        }
        else
        {
            return '<'.$name.$options_html.(($open) ? '>' : ' />');
        }
    }
    
    /**
     * Escapes text for Javascript
     * 
     * @param string $javascript Input Text
     * @return string 
     */
    public function escape_javascript($javascript = '')
    {
      $javascript = preg_replace('/\r\n|\n|\r/', "\\n", $javascript);
      $javascript = preg_replace('/(["\'])/', '\\\\\1', $javascript);

      return $javascript;
    }
    
    /**
     * Translates text
     * 
     * @param string $text Input text
     * @return string 
     */
    public function translate($text)
    {
        $translator = $this->container->get('translator', ContainerInterface::NULL_ON_INVALID_REFERENCE);
        if(is_null($translator))
        {
            return $text;
        }
        return $translator->trans($text);
    }
    
    /**
     * Returns the public path.
     *
     * Absolute paths (i.e. http://...) are returned unmodified.
     *
     * @param string $path        A public path
     * @param string $packageName The name of the asset package to use
     *
     * @return string A public path which takes into account the base path and URL path
     */
    public function getAssetUrl($path, $packageName = null)
    {
        return $this->container->get('templating.helper.assets')->getUrl($path, $packageName);
    }
    
    public function table($values, $size, $table_options = array(),  $tr_options = array(), $td_options = array())
    {
        $count_values = \count($values);
        if(!is_array($values) || $count_values == 0)
        {
            return '';
        }
        for($i=0; $i < $count_values % $size; $i++)
        {
            $values[] = '';
        }
        
        $table_content = '';
        foreach(\array_chunk($values, $size) as $tr)
        {
            $tr_content = '';
            foreach($tr as $td)
            {
                $tr_content .= $this->tag('td', $td_options, $td);
            }
            $table_content .= $this->tag('tr', $tr_options, $tr_content);
        }
        return $this->tag('table', $table_options, $table_content);
    }
}<commit_msg>Correction fonction twig "table" qui ne renvoyait pas le nombre de cellules correct<commit_after><?php

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

namespace Ecommit\UtilBundle\Helper;

use Symfony\Component\DependencyInjection\ContainerInterface;

class UtilHelper
{
    /**
     * ContainerInterface and not directly services: Because some services need request
     * (e.g.: "templating.helper.assets") and throw InactiveScopeException
     * 
     * @var ContainerInterface 
     */
    protected $container = null;
    
    /**
     * Constructor
     * 
     * @param ContainerInterface $container 
     */
    public function __construct(ContainerInterface $container) 
    {
        $this->container = $container;
    }
    
    /**
     * Gets a service.
     * WARNING ! Use this method only is required. NOT ABUSE.
     * 
     * @See ContainerInterface:get
     */
    public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
    {
        return $this->container->get($id, $invalidBehavior);
    }
    
    /**
     * Constructs an html tag
     * 
     * @param string $name Tag name
     * @param array $options Tag options
     * @param string $content Content
     * @param bool $open True to leave tag open
     * @return string 
     */
    public function tag($name, Array $options = array(), $content = null, $open = false)
    {
        if (!$name)
        {
            return '';
        }
        $options_html = '';
        foreach ($options as $key => $value)
        {
            $options_html .= ' '.$key.'="'.\htmlspecialchars($value, \ENT_COMPAT).'"';
        }
        if($content !== null)
        {
            return '<'.$name.$options_html.'>'.$content.'</'.$name.'>';
        }
        else
        {
            return '<'.$name.$options_html.(($open) ? '>' : ' />');
        }
    }
    
    /**
     * Escapes text for Javascript
     * 
     * @param string $javascript Input Text
     * @return string 
     */
    public function escape_javascript($javascript = '')
    {
      $javascript = preg_replace('/\r\n|\n|\r/', "\\n", $javascript);
      $javascript = preg_replace('/(["\'])/', '\\\\\1', $javascript);

      return $javascript;
    }
    
    /**
     * Translates text
     * 
     * @param string $text Input text
     * @return string 
     */
    public function translate($text)
    {
        $translator = $this->container->get('translator', ContainerInterface::NULL_ON_INVALID_REFERENCE);
        if(is_null($translator))
        {
            return $text;
        }
        return $translator->trans($text);
    }
    
    /**
     * Returns the public path.
     *
     * Absolute paths (i.e. http://...) are returned unmodified.
     *
     * @param string $path        A public path
     * @param string $packageName The name of the asset package to use
     *
     * @return string A public path which takes into account the base path and URL path
     */
    public function getAssetUrl($path, $packageName = null)
    {
        return $this->container->get('templating.helper.assets')->getUrl($path, $packageName);
    }
    
    public function table($values, $size, $table_options = array(),  $tr_options = array(), $td_options = array())
    {
        $count_values = \count($values);
        if(!is_array($values) || $count_values == 0)
        {
            return '';
        }
        if($count_values % $size > 0)
        {
            for($i=0; $i < ($size - $count_values % $size); $i++)
            {
                $values[] = '';
            }
        }
        
        $table_content = '';
        foreach(\array_chunk($values, $size) as $tr)
        {
            $tr_content = '';
            foreach($tr as $td)
            {
                $tr_content .= $this->tag('td', $td_options, $td);
            }
            $table_content .= $this->tag('tr', $tr_options, $tr_content);
        }
        return $this->tag('table', $table_options, $table_content);
    }
}
{'fraction_non_alphanumeric': 0.14041514041514042, 'fraction_numerical': 0.0008547008547008547, 'mean_word_length': 1.9709829524845848, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 42, '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': '7421394', 'n_tokens_mistral': 2365, 'n_tokens_neox': 2327, 'n_words': 584}