<commit_before><?php namespace Foil\Section;

use Foil\Contracts\SectionInterface;

/**
 * @author <NAME> <<EMAIL>>
 * @package foil\foil
 * @license http://opensource.org/licenses/MIT MIT
 */
class Section implements SectionInterface
{
    private $content = '';
    private $mode;
    private $default_mode;
    private static $modes = [self::MODE_APPEND, self::MODE_OUTPUT, self::MODE_REPLACE];

    public function __construct($output_mode = false, $default_mode = null)
    {
        if ($output_mode !== false && ! in_array($output_mode, self::$modes, true)) {
            $output_mode = self::MODE_OUTPUT;
        }
        $this->mode = $output_mode;
        if (in_array($default_mode, self::$modes, true)) {
            $this->default_mode = $default_mode;
        }
    }

    public function start()
    {
        ob_start();
    }

    /**
     * Close a section collecting buffer content.
     * If mode is not set, set to replace. If mode is output echo buffer.
     */
    public function replace()
    {
        if (empty($this->mode)) {
            $this->mode = self::MODE_REPLACE;
        }
        $this->content = ob_get_clean();
        if ($this->mode & self::MODE_OUTPUT) {
            echo $this->content();
        }
    }

    /**
     * Close a section collecting buffer content.
     * If in replace mode ignore buffer otherwise append buffer to current content.
     * If mode is not set, set to append.
     * If mode is output echo content.
     */
    public function append()
    {
        if (empty($this->mode)) {
            $this->mode = self::MODE_APPEND;
        }
        $buffer = ob_get_clean();
        $this->content = ($this->mode & self::MODE_REPLACE) ? $this->content : $buffer.$this->content;
        if ($this->mode & self::MODE_OUTPUT) {
            echo $this->content();
        }
    }

    /**
     * Close a section collecting buffer content.
     * If in replace mode ignore buffer otherwise append buffer to current content.
     * If mode is not set, set to append.
     * If mode is output echo content.
     */
    public function stop()
    {
        $this->default_mode === self::MODE_REPLACE ? $this->replace() : $this->append();
    }

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

    public function setMode($mode, $merge = false)
    {
        if (! in_array($mode, self::$modes, true)) {
            $mode = self::MODE_OUTPUT;
        }
        $this->mode = $merge ? ($this->mode | $mode) : $mode;
    }

    public function mode()
    {
        return $this->mode;
    }
}
<commit_msg>Check a section started before ending it.<commit_after><?php namespace Foil\Section;

use Foil\Contracts\SectionInterface;
use LogicException;

/**
 * @author <NAME> <<EMAIL>>
 * @package foil\foil
 * @license http://opensource.org/licenses/MIT MIT
 */
class Section implements SectionInterface
{
    private $content = '';
    private $mode;
    private $default_mode;
    private $started = false;
    private static $modes = [self::MODE_APPEND, self::MODE_OUTPUT, self::MODE_REPLACE];

    public function __construct($output_mode = false, $default_mode = null)
    {
        if ($output_mode !== false && ! in_array($output_mode, self::$modes, true)) {
            $output_mode = self::MODE_OUTPUT;
        }
        $this->mode = $output_mode;
        if (in_array($default_mode, self::$modes, true)) {
            $this->default_mode = $default_mode;
        }
    }

    public function start()
    {
        $this->started = true;
        ob_start();
    }

    /**
     * Close a section collecting buffer content.
     * If mode is not set, set to replace. If mode is output echo buffer.
     */
    public function replace()
    {
        if (!$this->started()) {
            throw new LogicException('You need to start a section before to end it.');
        }
        if (empty($this->mode)) {
            $this->mode = self::MODE_REPLACE;
        }
        $this->content = ob_get_clean();
        if ($this->mode & self::MODE_OUTPUT) {
            echo $this->content();
        }
    }

    /**
     * Close a section collecting buffer content.
     * If in replace mode ignore buffer otherwise append buffer to current content.
     * If mode is not set, set to append.
     * If mode is output echo content.
     */
    public function append()
    {
        if (!$this->started()) {
            throw new LogicException('You need to start a section before to end it.');
        }
        if (empty($this->mode)) {
            $this->mode = self::MODE_APPEND;
        }
        $buffer = ob_get_clean();
        $this->content = ($this->mode & self::MODE_REPLACE) ? $this->content : $buffer.$this->content;
        if ($this->mode & self::MODE_OUTPUT) {
            echo $this->content();
        }
    }

    /**
     * Close a section collecting buffer content.
     * If in replace mode ignore buffer otherwise append buffer to current content.
     * If mode is not set, set to append.
     * If mode is output echo content.
     */
    public function stop()
    {
        $this->default_mode === self::MODE_REPLACE ? $this->replace() : $this->append();
    }

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

    public function setMode($mode, $merge = false)
    {
        if (! in_array($mode, self::$modes, true)) {
            $mode = self::MODE_OUTPUT;
        }
        $this->mode = $merge ? ($this->mode | $mode) : $mode;
    }

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

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

{'fraction_non_alphanumeric': 0.13397470158560484, 'fraction_numerical': 0.0, 'mean_word_length': 2.1663846587704456, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 57, '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': '5865584', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1620, 'n_words': 456}