Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.33% covered (success)
93.33%
14 / 15
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
PrefixingStatsdDataFactoryProxy
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
9 / 9
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addPrefixToKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 timing
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 gauge
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 set
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 increment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 decrement
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 updateCount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 produceStatsdData
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace Wikimedia\Stats;
22
23use Liuggio\StatsdClient\Entity\StatsdDataInterface;
24use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
25
26/**
27 * Proxy to prefix metric keys sent to a StatsdDataFactoryInterface
28 *
29 * @since 1.32
30 */
31class PrefixingStatsdDataFactoryProxy implements StatsdDataFactoryInterface {
32
33    /**
34     * @var string
35     */
36    private $prefix;
37
38    /**
39     * @var StatsdDataFactoryInterface
40     */
41    private $factory;
42
43    /**
44     * @param StatsdDataFactoryInterface $factory
45     * @param string $prefix
46     */
47    public function __construct(
48        StatsdDataFactoryInterface $factory,
49        $prefix
50    ) {
51        $this->factory = $factory;
52        $this->prefix = rtrim( $prefix, '.' );
53    }
54
55    /**
56     * @param string $key
57     * @return string
58     */
59    private function addPrefixToKey( $key ) {
60        return $this->prefix . '.' . $key;
61    }
62
63    public function timing( $key, $time ) {
64        return $this->factory->timing( $this->addPrefixToKey( $key ), $time );
65    }
66
67    public function gauge( $key, $value ) {
68        return $this->factory->gauge( $this->addPrefixToKey( $key ), $value );
69    }
70
71    public function set( $key, $value ) {
72        return $this->factory->set( $this->addPrefixToKey( $key ), $value );
73    }
74
75    public function increment( $key ) {
76        return $this->factory->increment( $this->addPrefixToKey( $key ) );
77    }
78
79    public function decrement( $key ) {
80        return $this->factory->decrement( $this->addPrefixToKey( $key ) );
81    }
82
83    public function updateCount( $key, $delta ) {
84        return $this->factory->updateCount( $this->addPrefixToKey( $key ), $delta );
85    }
86
87    public function produceStatsdData(
88        $key,
89        $value = 1,
90        $metric = StatsdDataInterface::STATSD_METRIC_COUNT
91    ) {
92        return $this->factory->produceStatsdData(
93            $this->addPrefixToKey( $key ),
94            $value,
95            $metric
96        );
97    }
98}
99
100/** @deprecated class alias since 1.43 */
101class_alias( PrefixingStatsdDataFactoryProxy::class, 'PrefixingStatsdDataFactoryProxy' );