<commit_before><?php

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

namespace Gnugat\Redaktilo;

use Gnugat\Redaktilo\Exception\InvalidLineNumberException;

/**
 * Redaktilo's base entity representing a collection of lines: each line is
 * stripped from its line break character.
 * This character is centralized in a property.
 *
 * When Text is created, the current line number is set to 0.
 *
 * @api
 */
class Text
{
    /** @var array */
    protected $lines;

    /** @var int */
    protected $length;

    /** @var string */
    protected $lineBreak;

    /** @var int */
    protected $currentLineNumber = 0;

    /**
     * @param array  $lines
     * @param string $lineBreak
     */
    public function __construct(array $lines, $lineBreak = PHP_EOL)
    {
        $this->setLines($lines);
        $this->lineBreak = $lineBreak;
    }

    /**
     * @return array
     *
     * @api
     */
    public function getLines()
    {
        return $this->lines;
    }

    /**
     * @param array $lines
     *
     * @api
     */
    public function setLines(array $lines)
    {
        $this->lines = $lines;
        $this->length = count($lines);
    }

    /**
     * @return int
     *
     * @api
     */
    public function getLength()
    {
        return $this->length;
    }

    /**
     * @return string
     *
     * @api
     */
    public function getLineBreak()
    {
        return $this->lineBreak;
    }

    /**
     * @param string $lineBreak
     *
     * @api
     */
    public function setLineBreak($lineBreak)
    {
        $this->lineBreak = $lineBreak;
    }

    /**
     * @return int
     *
     * @api
     */
    public function getCurrentLineNumber()
    {
        return $this->currentLineNumber;
    }

    /**
     * @param int $lineNumber
     *
     * @throws InvalidLineNumberException if $lineNumber is not an integer
     * @throws InvalidLineNumberException if $lineNumber is negative
     * @throws InvalidLineNumberException if $lineNumber is greater or equal than the number of lines
     *
     * @api
     */
    public function setCurrentLineNumber($lineNumber)
    {
        $this->throwOnInvalidLineNumber($lineNumber);
        $this->currentLineNumber = $lineNumber;
    }

    /**
     * @param int $lineNumber
     *
     * @return string
     *
     * @throws InvalidLineNumberException if $lineNumber is not an integer
     * @throws InvalidLineNumberException if $lineNumber is negative
     * @throws InvalidLineNumberException if $lineNumber is greater or equal than the number of lines
     *
     * @api
     */
    public function getLine($lineNumber = null)
    {
        if (null === $lineNumber) {
            $lineNumber = $this->currentLineNumber;
        }
        $this->throwOnInvalidLineNumber($lineNumber);

        return $this->lines[$lineNumber];
    }

    /**
     * @param string $line
     * @param int    $lineNumber
     *
     * @throws InvalidLineNumberException if $lineNumber is not an integer
     * @throws InvalidLineNumberException if $lineNumber is negative
     * @throws InvalidLineNumberException if $lineNumber is greater or equal than the number of lines
     *
     * @api
     */
    public function setLine($line, $lineNumber = null)
    {
        if (null === $lineNumber) {
            $lineNumber = $this->currentLineNumber;
        }
        $this->throwOnInvalidLineNumber($lineNumber);
        $this->lines[$lineNumber] = $line;
    }

    /**
     * @param int $lines
     *
     * @throws InvalidLineNumberException if $lines is not an integer
     * @throws InvalidLineNumberException if $lines is negative
     * @throws InvalidLineNumberException if $lines is greater or equal than the number of lines
     * @throws InvalidLineNumberException if the result would be greater or equal than the number of lines
     *
     * @api
     */
    public function incrementCurrentLineNumber($lines)
    {
        $this->throwOnInvalidLineNumber($lines);
        $newCurrentLineNumber = $this->currentLineNumber + $lines;
        $this->throwOnInvalidLineNumber($newCurrentLineNumber);
        $this->currentLineNumber = $newCurrentLineNumber;
    }

    /**
     * @param int $lines
     *
     * @throws InvalidLineNumberException if $lines is not an integer
     * @throws InvalidLineNumberException if $lines is negative
     * @throws InvalidLineNumberException if $lines is greater or equal than the number of lines
     * @throws InvalidLineNumberException if the result would be negative
     *
     * @api
     */
    public function decrementCurrentLineNumber($lines)
    {
        $this->throwOnInvalidLineNumber($lines);
        $newCurrentLineNumber = $this->currentLineNumber - $lines;
        $this->throwOnInvalidLineNumber($newCurrentLineNumber);
        $this->currentLineNumber = $newCurrentLineNumber;
    }

    /**
     * @param int $lineNumber
     *
     * @throws InvalidLineNumberException if $lineNumber is not an integer
     * @throws InvalidLineNumberException if $lineNumber is negative
     * @throws InvalidLineNumberException if $lineNumber is greater or equal than the number of lines
     */
    protected function throwOnInvalidLineNumber($lineNumber)
    {
        if (!is_int($lineNumber)) {
            throw new InvalidLineNumberException($lineNumber, $this, 'The line number should be an integer');
        }<commit_msg>[TextIncrement] Renamed $lines to $number<commit_after><?php

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

namespace Gnugat\Redaktilo;

use Gnugat\Redaktilo\Exception\InvalidLineNumberException;

/**
 * Redaktilo's base entity representing a collection of lines: each line is
 * stripped from its line break character.
 * This character is centralized in a property.
 *
 * When Text is created, the current line number is set to 0.
 *
 * @api
 */
class Text
{
    /** @var array */
    protected $lines;

    /** @var int */
    protected $length;

    /** @var string */
    protected $lineBreak;

    /** @var int */
    protected $currentLineNumber = 0;

    /**
     * @param array  $lines
     * @param string $lineBreak
     */
    public function __construct(array $lines, $lineBreak = PHP_EOL)
    {
        $this->setLines($lines);
        $this->lineBreak = $lineBreak;
    }

    /**
     * @return array
     *
     * @api
     */
    public function getLines()
    {
        return $this->lines;
    }

    /**
     * @param array $lines
     *
     * @api
     */
    public function setLines(array $lines)
    {
        $this->lines = $lines;
        $this->length = count($lines);
    }

    /**
     * @return int
     *
     * @api
     */
    public function getLength()
    {
        return $this->length;
    }

    /**
     * @return string
     *
     * @api
     */
    public function getLineBreak()
    {
        return $this->lineBreak;
    }

    /**
     * @param string $lineBreak
     *
     * @api
     */
    public function setLineBreak($lineBreak)
    {
        $this->lineBreak = $lineBreak;
    }

    /**
     * @return int
     *
     * @api
     */
    public function getCurrentLineNumber()
    {
        return $this->currentLineNumber;
    }

    /**
     * @param int $lineNumber
     *
     * @throws InvalidLineNumberException if $lineNumber is not an integer
     * @throws InvalidLineNumberException if $lineNumber is negative
     * @throws InvalidLineNumberException if $lineNumber is greater or equal than the number of lines
     *
     * @api
     */
    public function setCurrentLineNumber($lineNumber)
    {
        $this->throwOnInvalidLineNumber($lineNumber);
        $this->currentLineNumber = $lineNumber;
    }

    /**
     * @param int $lineNumber
     *
     * @return string
     *
     * @throws InvalidLineNumberException if $lineNumber is not an integer
     * @throws InvalidLineNumberException if $lineNumber is negative
     * @throws InvalidLineNumberException if $lineNumber is greater or equal than the number of lines
     *
     * @api
     */
    public function getLine($lineNumber = null)
    {
        if (null === $lineNumber) {
            $lineNumber = $this->currentLineNumber;
        }
        $this->throwOnInvalidLineNumber($lineNumber);

        return $this->lines[$lineNumber];
    }

    /**
     * @param string $line
     * @param int    $lineNumber
     *
     * @throws InvalidLineNumberException if $lineNumber is not an integer
     * @throws InvalidLineNumberException if $lineNumber is negative
     * @throws InvalidLineNumberException if $lineNumber is greater or equal than the number of lines
     *
     * @api
     */
    public function setLine($line, $lineNumber = null)
    {
        if (null === $lineNumber) {
            $lineNumber = $this->currentLineNumber;
        }
        $this->throwOnInvalidLineNumber($lineNumber);
        $this->lines[$lineNumber] = $line;
    }

    /**
     * @param int $number
     *
     * @throws InvalidLineNumberException if $number is not an integer
     * @throws InvalidLineNumberException if $number is negative
     * @throws InvalidLineNumberException if $number is greater or equal than the number of lines
     * @throws InvalidLineNumberException if the result would be greater or equal than the number of lines
     *
     * @api
     */
    public function incrementCurrentLineNumber($number)
    {
        $this->throwOnInvalidLineNumber($number);
        $newCurrentLineNumber = $this->currentLineNumber + $number;
        $this->throwOnInvalidLineNumber($newCurrentLineNumber);
        $this->currentLineNumber = $newCurrentLineNumber;
    }

    /**
     * @param int $number
     *
     * @throws InvalidLineNumberException if $lines is not an integer
     * @throws InvalidLineNumberException if $lines is negative
     * @throws InvalidLineNumberException if $lines is greater or equal than the number of lines
     * @throws InvalidLineNumberException if the result would be negative
     *
     * @api
     */
    public function decrementCurrentLineNumber($number)
    {
        $this->throwOnInvalidLineNumber($number);
        $newCurrentLineNumber = $this->currentLineNumber - $number;
        $this->throwOnInvalidLineNumber($newCurrentLineNumber);
        $this->currentLineNumber = $newCurrentLineNumber;
    }

    /**
     * @param int $lineNumber
     *
     * @throws InvalidLineNumberException if $lineNumber is not an integer
     * @throws InvalidLineNumberException if $lineNumber is negative
     * @throws InvalidLineNumberException if $lineNumber is greater or equal than the number of lines
     */
    protected function throwOnInvalidLineNumber($lineNumber)
    {
        if (!is_int($lineNumber)) {
            throw new InvalidLineNumberException($lineNumber, $this, 'The line number should be an integer');
        }
{'fraction_non_alphanumeric': 0.0995409954099541, 'fraction_numerical': 0.00036000360003600034, 'mean_word_length': 2.439182915506035, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 59, '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': '7633628', 'n_tokens_mistral': 3070, 'n_tokens_neox': 3023, 'n_words': 882}