This repository was archived by the owner on Dec 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace HelloFresh \Stats \StatsD ;
3+
4+ use League \StatsD \Client ;
5+ use League \StatsD \Exception \ConnectionException ;
6+
7+ class SilentClient extends Client
8+ {
9+ /**
10+ * @inheritdoc
11+ */
12+ protected function send (array $ data , array $ tags = []) : Client
13+ {
14+ $ tagsData = $ this ->serializeTags (array_replace ($ this ->tags , $ tags ));
15+
16+ try {
17+ $ socket = $ this ->getSocket ();
18+ $ messages = [];
19+ $ prefix = $ this ->namespace ? $ this ->namespace . '. ' : '' ;
20+ foreach ($ data as $ key => $ value ) {
21+ $ messages [] = $ prefix . $ key . ': ' . $ value . $ tagsData ;
22+ }
23+ $ this ->message = implode ("\n" , $ messages );
24+ @fwrite ($ socket , $ this ->message );
25+ fflush ($ socket );
26+ } catch (ConnectionException $ e ) {
27+ if ($ this ->throwConnectionExceptions ) {
28+ throw $ e ;
29+ }
30+ }
31+
32+ return $ this ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use HelloFresh \Stats \StatsD \SilentClient ;
4+ use PHPUnit \Framework \TestCase ;
5+
6+ class SilentClientTest extends TestCase
7+ {
8+ public function testNewInstance ()
9+ {
10+ $ client = new SilentClient ();
11+ $ this ->assertInstanceOf (SilentClient::class, $ client );
12+ $ this ->assertRegExp ('/^StatsD \\\Client::\[[a-zA-Z0-9]+\]$/ ' , (string ) $ client );
13+ }
14+
15+ public function testStaticInstance ()
16+ {
17+ $ client1 = SilentClient::instance ('instance1 ' );
18+ $ this ->assertInstanceOf (SilentClient::class, $ client1 );
19+ $ client2 = SilentClient::instance ('instance2 ' );
20+ $ client3 = SilentClient::instance ('instance1 ' );
21+ $ this ->assertEquals ('StatsD\Client::[instance2] ' , (string ) $ client2 );
22+ $ this ->assertFalse ((string ) $ client1 === (string ) $ client2 );
23+ $ this ->assertTrue ((string ) $ client1 === (string ) $ client3 );
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments