Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
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
21use Liuggio\StatsdClient\Entity\StatsdDataInterface;
22use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
23
24/**
25 * Proxy to prefix metric keys sent to a StatsdDataFactoryInterface
26 *
27 * @since 1.32
28 */
29class PrefixingStatsdDataFactoryProxy implements StatsdDataFactoryInterface {
30
31    /**
32     * @var string
33     */
34    private $prefix;
35
36    /**
37     * @var StatsdDataFactoryInterface
38     */
39    private $factory;
40
41    /**
42     * @param StatsdDataFactoryInterface $factory
43     * @param string $prefix
44     */
45    public function __construct(
46        StatsdDataFactoryInterface $factory,
47        $prefix
48    ) {
49        $this->factory = $factory;
50        $this->prefix = rtrim( $prefix, '.' );
51    }
52
53    /**
54     * @param string $key
55     * @return string
56     */
57    private function addPrefixToKey( $key ) {
58        return $this->prefix . '.' . $key;
59    }
60
61    public function timing( $key, $time ) {
62        return $this->factory->timing( $this->addPrefixToKey( $key ), $time );
63    }
64
65    public function gauge( $key, $value ) {
66        return $this->factory->gauge( $this->addPrefixToKey( $key ), $value );
67    }
68
69    public function set( $key, $value ) {
70        return $this->factory->set( $this->addPrefixToKey( $key ), $value );
71    }
72
73    public function increment( $key ) {
74        return $this->factory->increment( $this->addPrefixToKey( $key ) );
75    }
76
77    public function decrement( $key ) {
78        return $this->factory->decrement( $this->addPrefixToKey( $key ) );
79    }
80
81    public function updateCount( $key, $delta ) {
82        return $this->factory->updateCount( $this->addPrefixToKey( $key ), $delta );
83    }
84
85    public function produceStatsdData(
86        $key,
87        $value = 1,
88        $metric = StatsdDataInterface::STATSD_METRIC_COUNT
89    ) {
90        return $this->factory->produceStatsdData(
91            $this->addPrefixToKey( $key ),
92            $value,
93            $metric
94        );
95    }
96}