<commit_before><?php
declare(strict_types=1);

namespace WoohooLabs\Zen;

use Closure;
use Psr\Container\ContainerInterface;
use WoohooLabs\Zen\Exception\NotFoundException;

abstract class AbstractCompiledContainer implements ContainerInterface
{
    /**
     * @var array
     */
    protected $singletonEntries = [];

    /**
     * @var string[]
     */
    protected static $entryPoints = [];

    public function has($id): bool
    {
        return isset(static::$entryPoints[$id]);
    }

    public function get($id)
    {
        if (isset($this->singletonEntries[$id])) {
            return $this->singletonEntries[$id];
        }

        if (isset(static::$entryPoints[$id]) === false) {
            throw new NotFoundException($id);
        }

        return $this->{static::$entryPoints[$id]}();
    }

    protected function setProperties($object, array $properties): void
    {
        Closure::bind(
            function () use ($object, $properties) {
                foreach ($properties as $name => $value) {
                    $object->$name = $value;
                }
            },
            null,
            $object
        )->__invoke();
    }
}
<commit_msg>Optimize the $container->get() calls<commit_after><?php
declare(strict_types=1);

namespace WoohooLabs\Zen;

use Closure;
use Psr\Container\ContainerInterface;
use WoohooLabs\Zen\Exception\NotFoundException;

abstract class AbstractCompiledContainer implements ContainerInterface
{
    /**
     * @var array
     */
    protected $singletonEntries = [];

    /**
     * @var string[]
     */
    protected static $entryPoints = [];

    public function has($id): bool
    {
        return isset(static::$entryPoints[$id]);
    }

    public function get($id)
    {
        return $this->singletonEntries[$id] ?? ($this->{static::$entryPoints[$id]}() ?? $this->throwNotFoundException($id));
    }

    private function throwNotFoundException(string $id): void
    {
        throw new NotFoundException($id);
    }

    protected function setProperties($object, array $properties): void
    {
        Closure::bind(
            function () use ($object, $properties) {
                foreach ($properties as $name => $value) {
                    $object->$name = $value;
                }
            },
            null,
            $object
        )->__invoke();
    }
}

{'fraction_non_alphanumeric': 0.13686440677966102, 'fraction_numerical': 0.000847457627118644, 'mean_word_length': 2.247592847317744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '5088176', 'n_tokens_mistral': 664, 'n_tokens_neox': 647, 'n_words': 135}