<commit_before><?php

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

namespace endobox\core;

/**
 * A Box is a data structure that allows building larger things from smaller things.
 * It's a kind of fancy linked list that helps you build up your template-based web page.
 */
abstract class Box {

    protected $interior = [];

    protected $next = null;

    protected $prev = null;

    protected abstract function load();

    protected abstract function build($code);

    public function render()
    {
        $code = '';
        for ($b = $this->head(); $b !== null; $b = $b->next) {
            $code .= $b->render_inner();
        }
        return $code;
    }

    public function __toString()
    {
        return $this->render();
    }

    public function append(Box $b)
    {
        if ($this->next === null) {
            if ($b->prev === null) {
                $this->next = $b;
                $b->prev = $this;
                return $this;
            }
            return $this->append($b->prev);
        }
        return $this->next->append($b);
    }

    public function prepend(Box $b)
    {
        if ($this->prev === null) {
            if ($b->next === null) {
                $this->prev = $b;
                $b->next = $this;
                return $this;
            }
            return $this->prepend($b->next);
        }
        return $this->prev->prepend($b);
    }

    public function next()
    {
        return $this->next;
    }

    public function prev()
    {
        return $this->prev;
    }

    public function head()
    {
        for ($b = $this; $b->prev !== null; $b = $b->prev);
        return $b;
    }

    public function tail()
    {
        for ($b = $this; $b->next !== null; $b = $b->next);
        return $b;
    }

    protected function render_inner()
    {
        $code = '';
        $this->load();
        foreach ($this->interior as $r) {
            $code .= $r->render();
        }
        return $this->build($code);
    }

    protected function append_inner(Box $box)
    {
        $this->interior[] = $r;
        return $this;
    }

    protected function prepend_inner(Box $box)
    {
        \array_unshift($this->interior, $r);
        return $this;<commit_msg>Accept append/prepend type to be Renderable (instead of Box)<commit_after><?php

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

namespace endobox\core;

/**
 * A Box is a data structure that allows building larger things from smaller things.
 * It's a kind of fancy linked list that helps you build up your template-based web page.
 */
abstract class Box implements Renderable {

    protected $interior = [];

    protected $next = null;

    protected $prev = null;

    protected abstract function load();

    protected abstract function build($code);

    public function render()
    {
        $code = '';
        for ($b = $this->head(); $b !== null; $b = $b->next) {
            $code .= $b->render_inner();
        }
        return $code;
    }

    public function __toString()
    {
        return $this->render();
    }

    public function append(Box $b)
    {
        if ($this->next === null) {
            if ($b->prev === null) {
                $this->next = $b;
                $b->prev = $this;
                return $this;
            }
            return $this->append($b->prev);
        }
        return $this->next->append($b);
    }

    public function prepend(Box $b)
    {
        if ($this->prev === null) {
            if ($b->next === null) {
                $this->prev = $b;
                $b->next = $this;
                return $this;
            }
            return $this->prepend($b->next);
        }
        return $this->prev->prepend($b);
    }

    public function next()
    {
        return $this->next;
    }

    public function prev()
    {
        return $this->prev;
    }

    public function head()
    {
        for ($b = $this; $b->prev !== null; $b = $b->prev);
        return $b;
    }

    public function tail()
    {
        for ($b = $this; $b->next !== null; $b = $b->next);
        return $b;
    }

    protected function render_inner()
    {
        $code = '';
        $this->load();
        foreach ($this->interior as $r) {
            $code .= $r->render();
        }
        return $this->build($code);
    }

    protected function append_inner(Renderable $box)
    {
        $this->interior[] = $r;
        return $this;
    }

    protected function prepend_inner(Renderable $box)
    {
        \array_unshift($this->interior, $r);
        return $this;
{'fraction_non_alphanumeric': 0.14765513004300634, 'fraction_numerical': 0.0016383370878558263, 'mean_word_length': 1.6983425414364641, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 73, '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': '6134955', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1421, 'n_words': 417}