<commit_before><?php
namespace watoki\qrator;

use watoki\factory\Factory;
use watoki\qrator\representer\generic\GenericActionRepresenter;
use watoki\qrator\representer\generic\GenericEntityRepresenter;
use watoki\qrator\Representer;
use watoki\qrator\representer\MethodActionRepresenter;

class RepresenterRegistry {

    /** @var array|Representer[] */
    private $representers = [];

    /** @var Factory */
    private $factory;

    /**
     * @param Factory $factory <-
     */
    public function __construct(Factory $factory) {
        $this->factory = $factory;
        $factory->setSingleton(get_class($this), $this);

        $this->register((new GenericActionRepresenter(RootAction::class, $factory))
            ->setHandler(function () {
                return new RootEntity();
            })
            ->setName('Home'));

        $this->register((new GenericEntityRepresenter(RootEntity::class))
            ->setName('Qrator'));

        $this->register((new GenericEntityRepresenter(\DateTime::class))
            ->setStringifier(function (\DateTime $d) {
                return $d->format('Y-m-d H:i:s');
            }));
    }

    /**
     * @param string $class
     * @return bool
     */
    public function isRegistered($class) {
        return array_key_exists($class, $this->representers);
    }

    /**
     * @param Representer $representer
     * @return \watoki\qrator\Representer
     */
    public function register(Representer $representer) {
        $this->representers[$representer->getClass()] = $representer;
        return $representer;
    }

    /**
     * @param string $class Full name of the class
     * @param string $method Name of the method<commit_msg>Representer for DateTimeImmutable<commit_after><?php
namespace watoki\qrator;

use watoki\factory\Factory;
use watoki\qrator\representer\generic\GenericActionRepresenter;
use watoki\qrator\representer\generic\GenericEntityRepresenter;
use watoki\qrator\Representer;
use watoki\qrator\representer\MethodActionRepresenter;

class RepresenterRegistry {

    /** @var array|Representer[] */
    private $representers = [];

    /** @var Factory */
    private $factory;

    /**
     * @param Factory $factory <-
     */
    public function __construct(Factory $factory) {
        $this->factory = $factory;
        $factory->setSingleton(get_class($this), $this);

        $this->register((new GenericActionRepresenter(RootAction::class, $factory))
            ->setHandler(function () {
                return new RootEntity();
            })
            ->setName('Home'));

        $this->register((new GenericEntityRepresenter(RootEntity::class))
            ->setName('Qrator'));

        $printDateTime = function (\DateTimeInterface $d) {
            return $d->format('Y-m-d H:i:s');
        };
        $this->register((new GenericEntityRepresenter(\DateTime::class))
            ->setStringifier($printDateTime));

        $this->register((new GenericEntityRepresenter(\DateTimeImmutable::class))
            ->setStringifier($printDateTime));
    }

    /**
     * @param string $class
     * @return bool
     */
    public function isRegistered($class) {
        return array_key_exists($class, $this->representers);
    }

    /**
     * @param Representer $representer
     * @return \watoki\qrator\Representer
     */
    public function register(Representer $representer) {
        $this->representers[$representer->getClass()] = $representer;
        return $representer;
    }

    /**
     * @param string $class Full name of the class
     * @param string $method Name of the method
{'fraction_non_alphanumeric': 0.13422074320576816, 'fraction_numerical': 0.0, 'mean_word_length': 2.792849631966351, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, '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': '4428942', 'n_tokens_mistral': 1059, 'n_tokens_neox': 981, 'n_words': 190}