<commit_before><?php
/**
 * User: <NAME> <<EMAIL>>
 * Date: 6/18/15
 * Time: 8:23 PM
 */

namespace Hitmeister\Component\Metrics\Collector;

use Hitmeister\Component\Metrics\Buffer\BufferInterface;
use Hitmeister\Component\Metrics\Metric\Metric;
use Hitmeister\Component\Metrics\Metric\SamplingMetricInterface;
use Symfony\Component\Stopwatch\Stopwatch;

abstract class AbstractCollector implements CollectorInterface
{
    /**
     * Prefix for metrics.
     *
     * @var string
     */
    protected $prefix = '';

    /**
     * Tags will be added to each metric.
     * For example: env or server name.
     *
     * @var array
     */
    protected $tags = [];

    /**
     * Buffer for metrics.
     *
     * @var BufferInterface
     */
    protected $buffer;

    /**
     * @inheritdoc
     */
    public function increment($names, array $tags = [], $value = 1, $sampleRate = 1.0)
    {
        return $this->counter($names, $value, $tags, $sampleRate);
    }

    /**
     * @inheritdoc
     */
    public function decrement($names, array $tags = [], $value = 1, $sampleRate = 1.0)
    {
        return $this->counter($names, ($value < 0 ? $value : -$value), $tags, $sampleRate);
    }

    /**
     * @inheritdoc
     */
    public function counter($names, $value, array $tags = [], $sampleRate = 1.0)
    {
        $names = (array)$names;
        $className = '\Hitmeister\Component\Metrics\Metric\CounterMetric';
        $metrics = $this->createMetrics($className, $names, $value, $tags, $sampleRate);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function timer($names, $value, array $tags = [], $sampleRate = 1.0)
    {
        $names = (array)$names;
        $className = '\Hitmeister\Component\Metrics\Metric\TimerMetric';
        $metrics = $this->createMetrics($className, $names, $value, $tags, $sampleRate);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function memory($names, $value, array $tags = [], $sampleRate = 1.0)
    {
        $names = (array)$names;
        $className = '\Hitmeister\Component\Metrics\Metric\MemoryMetric';
        $metrics = $this->createMetrics($className, $names, $value, $tags, $sampleRate);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function gauge($names, $value, array $tags = [])
    {
        $names = (array)$names;
        $className = '\Hitmeister\Component\Metrics\Metric\GaugeMetric';
        $metrics = $this->createMetrics($className, $names, $value, $tags);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function unique($names, $value, array $tags = [])
    {
        $names = (array)$names;
        $className = '\Hitmeister\Component\Metrics\Metric\UniqueMetric';
        $metrics = $this->createMetrics($className, $names, $value, $tags);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function closure($name, $function, array $tags = [], $sampleRate = 1.0)
    {
        if (!is_callable($function)) {
            throw new \LogicException('$function argument is not callable');
        }

        // Event happened once
        $this->increment($name, $tags, 1, $sampleRate);

        // Start trackers
        $stopwatch = new Stopwatch();<commit_msg>Get a fully qualified name of class by `ClassName::class`<commit_after><?php
/**
 * User: <NAME> <<EMAIL>>
 * Date: 6/18/15
 * Time: 8:23 PM
 */

namespace Hitmeister\Component\Metrics\Collector;

use Hitmeister\Component\Metrics\Buffer\BufferInterface;
use Hitmeister\Component\Metrics\Metric\CounterMetric;
use Hitmeister\Component\Metrics\Metric\GaugeMetric;
use Hitmeister\Component\Metrics\Metric\MemoryMetric;
use Hitmeister\Component\Metrics\Metric\Metric;
use Hitmeister\Component\Metrics\Metric\SamplingMetricInterface;
use Hitmeister\Component\Metrics\Metric\TimerMetric;
use Hitmeister\Component\Metrics\Metric\UniqueMetric;
use Symfony\Component\Stopwatch\Stopwatch;

abstract class AbstractCollector implements CollectorInterface
{
    /**
     * Prefix for metrics.
     *
     * @var string
     */
    protected $prefix = '';

    /**
     * Tags will be added to each metric.
     * For example: env or server name.
     *
     * @var array
     */
    protected $tags = [];

    /**
     * Buffer for metrics.
     *
     * @var BufferInterface
     */
    protected $buffer;

    /**
     * @inheritdoc
     */
    public function increment($names, array $tags = [], $value = 1, $sampleRate = 1.0)
    {
        return $this->counter($names, $value, $tags, $sampleRate);
    }

    /**
     * @inheritdoc
     */
    public function decrement($names, array $tags = [], $value = 1, $sampleRate = 1.0)
    {
        return $this->counter($names, ($value < 0 ? $value : -$value), $tags, $sampleRate);
    }

    /**
     * @inheritdoc
     */
    public function counter($names, $value, array $tags = [], $sampleRate = 1.0)
    {
        $names = (array)$names;
        $metrics = $this->createMetrics(CounterMetric::class, $names, $value, $tags, $sampleRate);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function timer($names, $value, array $tags = [], $sampleRate = 1.0)
    {
        $names = (array)$names;
        $metrics = $this->createMetrics(TimerMetric::class, $names, $value, $tags, $sampleRate);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function memory($names, $value, array $tags = [], $sampleRate = 1.0)
    {
        $names = (array)$names;
        $metrics = $this->createMetrics(MemoryMetric::class, $names, $value, $tags, $sampleRate);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function gauge($names, $value, array $tags = [])
    {
        $names = (array)$names;
        $metrics = $this->createMetrics(GaugeMetric::class, $names, $value, $tags);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function unique($names, $value, array $tags = [])
    {
        $names = (array)$names;
        $metrics = $this->createMetrics(UniqueMetric::class, $names, $value, $tags);
        $this->buffer->addBatch($metrics);
        return $this;
    }

    /**
     * @inheritdoc
     */
    public function closure($name, $function, array $tags = [], $sampleRate = 1.0)
    {
        if (!is_callable($function)) {
            throw new \LogicException('$function argument is not callable');
        }

        // Event happened once
        $this->increment($name, $tags, 1, $sampleRate);

        // Start trackers
        $stopwatch = new Stopwatch();
{'fraction_non_alphanumeric': 0.1577133007756392, 'fraction_numerical': 0.0068945705257110025, 'mean_word_length': 2.469357249626308, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 45, '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': '6120406', 'n_tokens_mistral': 2135, 'n_tokens_neox': 2082, 'n_words': 451}