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

BestEffortBucketLogger::writeEvent()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 3
rs 10
c 0
b 0
f 0
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
}