Passed
Pull Request — master (#2028)
by Gabriel
203:46 queued 138:41
created

ProductionEnvironmentSetup::setApplicationLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ProductionEnvironmentSetup::setSofortLogger() 0 2 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Factories\EnvironmentSetup;
6
7
use Doctrine\ORM\Tools\Setup;
8
use Monolog\Formatter\JsonFormatter;
9
use Monolog\Handler\StreamHandler;
10
use Monolog\Logger;
11
use Psr\Log\LoggerInterface;
12
use WMDE\Fundraising\Frontend\Factories\FunFunFactory;
13
14
class ProductionEnvironmentSetup implements EnvironmentSetup {
15 1
16 1
	public function setEnvironmentDependentInstances( FunFunFactory $factory ) {
17
		$this->initializeLoggers( $factory );
18 1
19 1
		$factory->enableCaching();
0 ignored issues
show
Deprecated Code introduced by
The function WMDE\Fundraising\Fronten...actory::enableCaching() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

19
		/** @scrutinizer ignore-deprecated */ $factory->enableCaching();
Loading history...
20
	}
21 1
22 1
	private function initializeLoggers( FunFunFactory $factory ) {
23 1
		$this->setPaypalLogger( $factory );
24 1
		$this->setSofortLogger( $factory );
25 1
		$this->setCreditCardLogger( $factory );
26
		$this->setDoctrineConfiguration( $factory );
27 1
	}
28 1
29 1
	private function setPaypalLogger( FunFunFactory $factory ) {
30 1
		$factory->setPaypalLogger( $this->createStreamLoggerForPayment( 'paypal', $factory->getLoggingPath() ) );
31
	}
32 1
33
	private function setSofortLogger( FunFunFactory $factory ) {
34 1
		$factory->setSofortLogger( $this->createStreamLoggerForPayment( 'sofort', $factory->getLoggingPath() ) );
35 1
	}
36
37 1
	private function setDoctrineConfiguration( FunFunFactory $factory ) {
38 1
		// Setup will choose its own caching (APCu, Redis, Memcached, Array) based on the PHP environment and its extensions.
39
		// See https://phabricator.wikimedia.org/T249338
40 1
		$factory->setDoctrineConfiguration( Setup::createConfiguration( false, $factory->getWritableApplicationDataPath() . '/doctrine_proxies' ) );
41 1
	}
42
43 1
	private function setCreditCardLogger( FunFunFactory $factory ) {
44 1
		$factory->setCreditCardLogger( $this->createStreamLoggerForPayment( 'creditcard', $factory->getLoggingPath() ) );
45
	}
46 1
47 1
	private function createStreamLoggerForPayment( string $paymentName, string $loggingPath ): LoggerInterface {
48
		$logger = new Logger( $paymentName );
49 1
		$streamHandler = new StreamHandler( $loggingPath . '/' . $paymentName . '.log' );
50 1
		$streamHandler->setFormatter( new JsonFormatter() );
51 1
		$logger->pushHandler( $streamHandler );
52
		return $logger;
53 1
	}
54
}
55