<commit_before><?php namespace Performance\Lib;

use Performance\Lib\Handlers\ConfigHandler;
use Performance\Lib\Interfaces\ExportInterface;

class Point implements ExportInterface
{
    const POINT_PRELOAD = '__POINT_PRELOAD';
    const POINT_CALIBRATE = 'Calibrate point';

    private $config;
    private $active;
    private $label;
    private $startTime;
    private $startMemoryUsage;
    private $stopTime;
    private $stopMemoryUsage;
    private $memoryPeak;
    private $differenceTime;
    private $differenceMemory;
    private $queryLog = [];
    private $newLineMessage = [];

    /**
     * Point constructor.
     * @param $name
     * @param $startTime
     * @param $startMemory
     */
    public function __construct(ConfigHandler $config, $name)
    {
        // Set items
        $this->config = $config;
        $this->setLabel($name);
    }

    /*
     * Start point
     *
     * return void
     */
    public function start()
    {
        $this->setActive(true);
        $this->setStartTime();
        $this->setStartMemoryUsage();
    }

    /*
     * Finish point
     *
     * return void
     */
    public function finish()
    {
        $this->setActive(false);
        $this->setStopTime();
        $this->setStopMemoryUsage();
        $this->setMemoryPeak();
        $this->setDifferenceTime();
        $this->setDifferenceMemory();
    }

    /*
     * Simple export function
     */
    public function export()
    {
        $vars = get_object_vars($this);
        unset($vars['config']); // skip config

        return $vars;
    }

    // Get and set

    /**
     * @return mixed
     */
    public function getMemoryPeak()
    {
        return $this->memoryPeak;
    }

    /**
     * @param mixed $stopMemoryPeak
     */
    public function setMemoryPeak($memoryPeak = null)
    {
        $this->memoryPeak = ( $memoryPeak ) ? $memoryPeak : memory_get_peak_usage(true);
    }

    /**
     * @return mixed
     */
    public function isActive()
    {
        return $this->active;
    }

    /**
     * @param mixed $active
     */
    public function setActive($active)
    {
        $this->active = $active;
    }

    /**
     * @return mixed
     */
    public function getStopTime()
    {
        return $this->stopTime;
    }

    /**
     * @param mixed $stopTime
     */
    public function setStopTime($stopTime = null)
    {
        $this->stopTime = ($stopTime) ? $stopTime : microtime(true);
    }

    /**
     * @return mixed
     */
    public function getStopMemoryUsage()
    {
        return $this->stopMemoryUsage;
    }

    /**
     * @param mixed $stopMemory
     */
    public function setStopMemoryUsage($stopMemoryUsage = null)
    {
        $this->stopMemoryUsage = ($stopMemoryUsage) ? $stopMemoryUsage : memory_get_usage(true);
    }


    /**<commit_msg>The finish function will not overwrite the stop time when it is set<commit_after><?php namespace Performance\Lib;

use Performance\Lib\Handlers\ConfigHandler;
use Performance\Lib\Interfaces\ExportInterface;

class Point implements ExportInterface
{
    const POINT_PRELOAD = '__POINT_PRELOAD';
    const POINT_CALIBRATE = 'Calibrate point';

    private $config;
    private $active;
    private $label;
    private $startTime;
    private $startMemoryUsage;
    private $stopTime;
    private $stopMemoryUsage;
    private $memoryPeak;
    private $differenceTime;
    private $differenceMemory;
    private $queryLog = [];
    private $newLineMessage = [];

    /**
     * Point constructor.
     * @param $name
     * @param $startTime
     * @param $startMemory
     */
    public function __construct(ConfigHandler $config, $name)
    {
        // Set items
        $this->config = $config;
        $this->setLabel($name);
    }

    /*
     * Start point
     *
     * return void
     */
    public function start()
    {
        $this->setActive(true);
        $this->setStartTime();
        $this->setStartMemoryUsage();
    }

    /*
     * Finish point
     *
     * return void
     */
    public function finish()
    {
        $this->setActive(false);
        $this->setStopTimeIfNotExists();
        $this->setStopMemoryUsage();
        $this->setMemoryPeak();
        $this->setDifferenceTime();
        $this->setDifferenceMemory();
    }

    /*
     * Simple export function
     */
    public function export()
    {
        $vars = get_object_vars($this);
        unset($vars['config']); // skip config

        return $vars;
    }

    // Get and set

    /**
     * @return mixed
     */
    public function getMemoryPeak()
    {
        return $this->memoryPeak;
    }

    /**
     * @param mixed $stopMemoryPeak
     */
    public function setMemoryPeak($memoryPeak = null)
    {
        $this->memoryPeak = ( $memoryPeak ) ? $memoryPeak : memory_get_peak_usage(true);
    }

    /**
     * @return mixed
     */
    public function isActive()
    {
        return $this->active;
    }

    /**
     * @param mixed $active
     */
    public function setActive($active)
    {
        $this->active = $active;
    }

    /**
     * @return mixed
     */
    public function getStopTime()
    {
        return $this->stopTime;
    }

    /**
     * @param mixed $stopTime
     */
    public function setStopTimeIfNotExists($stopTime = null)
    {
        if(is_null($this->stopTime)) $this->setStopTime($stopTime);
    }

    /**
     * @param mixed $stopTime
     */
    public function setStopTime($stopTime = null)
    {
        $this->stopTime = ($stopTime) ? $stopTime : microtime(true);
    }

    /**
     * @return mixed
     */
    public function getStopMemoryUsage()
    {
        return $this->stopMemoryUsage;
    }

    /**
     * @param mixed $stopMemory
     */
    public function setStopMemoryUsage($stopMemoryUsage = null)
    {
        $this->stopMemoryUsage = ($stopMemoryUsage) ? $stopMemoryUsage : memory_get_usage(true);
    }

    /**
{'fraction_non_alphanumeric': 0.12647954007439974, 'fraction_numerical': 0.0, 'mean_word_length': 2.058428128231644, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '2310539', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1743, 'n_words': 357}