<commit_before><?php

declare(strict_types=1);

namespace Ray\Di\MultiBinding;

use Ray\Di\AbstractModule;
use Ray\Di\Bind;
use Ray\Di\Container;

final class MultiBinder
{
    /** @var Container */
    private $container;

    /** @var array<string, array<int|string, Lazy>> */
    private $lazyCollection = [];

    /** @var string */
    private $interface;

    private function __construct(AbstractModule $module, string $interface)
    {
        $this->container = $module->getContainer();
        $this->interface = $interface;
    }

    public static function newInstance(AbstractModule $module, string $interface): self
    {
        return new self($module, $interface);
    }

    /**
     * @param class-string $class
     */
    public function add(string $class, ?string $key = null): void
    {
        $this->bind($class, $key);
        $bind = (new Bind($this->container, LazyCollection::class))->toInstance(new LazyCollection($this->lazyCollection));
        $this->container->add($bind);
    }

    public function set(string $class, ?string $key = null): void
    {
        unset($this->lazyCollection[$this->interface]);
        $this->add($class, $key);<commit_msg>fixup! Create MultiBinder::set() method<commit_after><?php

declare(strict_types=1);

namespace Ray\Di\MultiBinding;

use Ray\Di\AbstractModule;
use Ray\Di\Bind;
use Ray\Di\Container;

final class MultiBinder
{
    /** @var Container */
    private $container;

    /** @var array<string, array<int|string, Lazy>> */
    private $lazyCollection = [];

    /** @var string */
    private $interface;

    private function __construct(AbstractModule $module, string $interface)
    {
        $this->container = $module->getContainer();
        $this->interface = $interface;
    }

    public static function newInstance(AbstractModule $module, string $interface): self
    {
        return new self($module, $interface);
    }

    /**
     * @param class-string $class
     */
    public function add(string $class, ?string $key = null): void
    {
        $this->bind($class, $key);
        $bind = (new Bind($this->container, LazyCollection::class))->toInstance(new LazyCollection($this->lazyCollection));
        $this->container->add($bind);
    }

    /**
     * @param class-string $class
     */
    public function set(string $class, ?string $key = null): void
    {
        unset($this->lazyCollection[$this->interface]);
        $this->add($class, $key);
{'fraction_non_alphanumeric': 0.1533442088091354, 'fraction_numerical': 0.0008156606851549756, 'mean_word_length': 3.08153078202995, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5377800', 'n_tokens_mistral': 727, 'n_tokens_neox': 716, 'n_words': 163}