<commit_before><?php

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

namespace Spiechu\TimeSpan\TimeUnit;

use \Spiechu\TimeSpan\TimeSpanException;

abstract class AbstractTimeUnit {

    /**
     * @var bool marks if current unit is special
     */
    protected $_isSpecialUnit = false;
    protected $_units = array();
    protected $_specialUnits = array();
    protected $_trulyFullUnit = true;
    protected $_isHalved = false;
    protected $_unitCount;
    protected $_unitType;

    /**
     * @return bool 
     */
    public function isSpecialUnit() {
        return $this->_isSpecialUnit;
    }

    public function setTrulyFullUnit($tfu) {
        $this->_trulyFullUnit = $tfu;
        return $this;
    }

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

    public function setHalved($h) {
        $this->_isHalved = $h;
        return $this;
    }

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

    public function setUnitCount($uc) {
        $this->_unitCount = $uc;
        return $this;
    }

    public function getUnitCount() {
        return $this->_unitCount;
    }
    
    public function isApproximated() {
        return ($this->_isHalved || (! $this->_trulyFullUnit));
    }

    public function setUnitType($ut) {
        if (!in_array($ut, array('s', 'i', 'h', 'd', 'm', 'y')))
            throw new TimeSpanException("Unknown unit type: {$ut}");
        $this->_unitType = $ut;
        return $this;
    }

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

    /**
     * Returns proper time unit string according to number of units.
     * 
     * @return string
     */
    abstract public function getUnit();

    /**
     * Returns translated 'almost' prefix.
     * 
     * @return string
     */
    abstract public function getPrefix();

    /**
     * Returns translated 'and half' string.
     * 
     * @return string
     */
    abstract public function getHalf();

    /**
     * Returns translated 'and' string.
     * <commit_msg>add docblock<commit_after><?php

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

namespace Spiechu\TimeSpan\TimeUnit;

use \Spiechu\TimeSpan\TimeSpanException;

abstract class AbstractTimeUnit {

    /**
     * @var bool marks if current unit is special
     */
    protected $_isSpecialUnit = false;
    protected $_units = array();
    protected $_specialUnits = array();
    protected $_trulyFullUnit = true;
    protected $_isHalved = false;
    /**
     * @var int
     */
    protected $_unitCount;
    /**
     * @var string 
     */
    protected $_unitType;

    /**
     * Returns true when unit has been taken from $_specialUnits array.
     * 
     * @return bool 
     */
    public function isSpecialUnit() {
        return $this->_isSpecialUnit;
    }

    /**
     * Returns true when unit has not been approximated in any way.
     * 
     * @param bool $tfu
     * @return AbstractTimeUnit fluent interface 
     */
    public function setTrulyFullUnit($tfu) {
        $this->_trulyFullUnit = $tfu;
        return $this;
    }

    /**
     * @return bool
     */
    public function isTrulyFullUnit() {
        return $this->_trulyFullUnit;
    }

    /**
     * Should half unit need to be added apart from $_unitCount.
     * 
     * @param bool $h
     * @return AbstractTimeUnit fluent interface
     */
    public function setHalved($h) {
        $this->_isHalved = $h;
        return $this;
    }

    /**
     * @return bool
     */
    public function isHalved() {
        return $this->_isHalved;
    }

    /**
     * Set number of units.
     * 
     * @param int $uc
     * @return AbstractTimeUnit fluent interface
     */
    public function setUnitCount($uc) {
        $this->_unitCount = $uc;
        return $this;
    }

    /**
     * Get number of units.
     * 
     * @return int 
     */
    public function getUnitCount() {
        return $this->_unitCount;
    }
    
    /**
     * Returns true when unit count was approximated 
     * or 'and half' should be added.
     * 
     * @return bool
     */
    public function isApproximated() {
        return ($this->_isHalved || (! $this->_trulyFullUnit));
    }

    /**
     * Unit type setter.
     * 
     * @param string $ut
     * @return AbstractTimeUnit fluent interface
     * @throws TimeSpanException when $ut is not one of 's', 'i', 'h', 'd', 'm', 'y'
     */
    public function setUnitType($ut) {
        if (!in_array($ut, array('s', 'i', 'h', 'd', 'm', 'y')))
            throw new TimeSpanException("Unknown unit type: {$ut}");
        $this->_unitType = $ut;
        return $this;
    }

    /**
     * @return string
     */
    public function getUnitType() {
        return $this->_unitType;
    }

    /**
     * Returns proper time unit string according to number of units.
     * 
     * @return string
     */
    abstract public function getUnit();

    /**
     * Returns translated 'almost' prefix.
     * 
     * @return string
     */
    abstract public function getPrefix();

    /**
     * Returns translated 'and half' string.
     * 
     * @return string
     */
    abstract public function getHalf();

    /**
     * Returns translated 'and' string.
     * 
{'fraction_non_alphanumeric': 0.11989247311827957, 'fraction_numerical': 0.0, 'mean_word_length': 2.0664835164835167, 'pattern_counts': {'":': 0, '<': 11, '<?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': '526744', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1614, 'n_words': 474}