Passed
Push — master ( 950b60...cce8f6 )
by Gabriel
28:13
created

BestEffortBucketLogger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A writeEvent() 0 9 3
A __construct() 0 3 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\BucketTesting\Logging;
6
7
use Psr\Log\LoggerInterface;
8
use WMDE\Fundraising\Frontend\BucketTesting\Bucket;
9
10
/**
11
 * @license GNU GPL v2+
12
 */
13
class BestEffortBucketLogger implements BucketLogger {
14
15
	private $bucketLogger;
16
	private $errorLogging;
17
	private $caughtException;
18
19 36
	public function __construct( BucketLogger $bucketLogger, LoggerInterface $errorLogging ) {
20 36
		$this->bucketLogger = $bucketLogger;
21 36
		$this->errorLogging = $errorLogging;
22 36
	}
23
24 36
	public function writeEvent( LoggingEvent $event, Bucket ...$buckets ): void {
25 36
		if ( $this->caughtException !== null ) {
26 2
			return;
27
		}
28
		try {
29 36
			$this->bucketLogger->writeEvent( $event, ...$buckets );
30 2
		} catch ( LoggingError $error ) {
31 2
			$this->caughtException = $error;
32 2
			$this->errorLogging->error( $error->getMessage(), [ 'exception' => $error ] );
33
		}
34 36
	}
35
36
}