<commit_before><?php
/**
 * This file is part of the Flownode package
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Flownode\Scribe\Decorator;
/**
 * Abstract class for handling styles
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class Decorator
{
  /**
   * Contain all styles definitions
   * key   : string   style name
   * value : Closure  function to apply
   * @var array
   */
  protected $rules = array();

  /**
   *
   * @param string $rule
   * @param \Closure $decorator
   */
  public function set($name, \Closure $rule)
  {
    $this->rules[$name] = $rule;
  }

  /**
   * Get one or sevral rules
   *
   * @param string | array $rules
   * @return array         Array of Closures
   */
  function get($rules)
  {
    if(null !== $rules)
    {
      if(is_array($rules))
      {
        $_rules = array();
        foreach($rules as $name => $rule)
        {
          if(isset($this->rules[$rule]))
          {
            $_rules[$name] = $this->rules[$rule];
          }
        }

        return $_rules;
      }

      return array($rules => $this->rules[$rules]);
    }

    return array($rules => $this->rules['default']);
  }

  /**
   *
   * @param mixed $rules
   * @param mixed $arg1
   * @param mixed $arg2
   * @param mixed $arg3
   * @param mixed $arg4
   */
  public function execute($writer, $rules, &$arg1 = null, &$arg2 = null, &$arg3 = null, &$arg4 = null)
  {
    $closures = $this->get($rules);

    foreach($closures as $name => $closure)
    {
      $closure($writer, $arg1, $arg2, $arg3, $arg4);
    }
  }
}<commit_msg>Decorator rule can be a Closure<commit_after><?php
/**
 * This file is part of the Flownode package
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Flownode\Scribe\Decorator;
/**
 * Abstract class for handling styles
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class Decorator
{
  /**
   * Contain all styles definitions
   * key   : string   style name
   * value : Closure  function to apply
   * @var array
   */
  protected $rules = array();

  /**
   *
   * @param string $rule
   * @param \Closure $decorator
   */
  public function set($name, \Closure $rule)
  {
    $this->rules[$name] = $rule;
  }

  /**
   * Get one or sevral rules
   *
   * @param string | array $rules
   * @return array         Array of Closures
   */
  function get($rules)
  {
    if(null !== $rules)
    {
      if(is_array($rules))
      {
        $_rules = array();
        foreach($rules as $name => $rule)
        {
          if(isset($this->rules[$rule]))
          {
            $_rules[$name] = $this->rules[$rule];
          }
        }

        return $_rules;
      }

      return array($rules => $this->rules[$rules]);
    }

    return array($rules => $this->rules['default']);
  }

  /**
   * Execute the decorator(s)
   *
   * Rules can be string or hash of strings for easier reuse
   * In some cases, we don't want the Closure to be registered, so we can give a Closure as argument
   *
   * @param Writer  $writer
   * @param mixed   $rules  Can be a string or a hash of string, or a Closure
   * @param mixed   $arg1
   * @param mixed   $arg2
   * @param mixed   $arg3
   * @param mixed   $arg4
   */
  public function execute($writer, $rules, &$arg1 = null, &$arg2 = null, &$arg3 = null, &$arg4 = null)
  {
    if(!is_callable($rules))
    {
      $closures = $this->get($rules);

      foreach($closures as $closure)
      {
        $closure($writer, $arg1, $arg2, $arg3, $arg4);
      }
    }
    else
    {
      $rules($writer, $arg1, $arg2, $arg3, $arg4);
    }

  }
}
{'fraction_non_alphanumeric': 0.14943136736313145, 'fraction_numerical': 0.007405448294102089, 'mean_word_length': 2.2491408934707904, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 34, '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': '2755814', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1235, 'n_words': 357}