Passed
Push — master ( 2d893f...5de32f )
by Atanas
02:41
created

ExceptionsServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 1 1
A register() 0 27 4
1
<?php
2
/**
3
 * @package   WPEmerge
4
 * @author    Atanas Angelov <[email protected]>
5
 * @copyright 2018 Atanas Angelov
6
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7
 * @link      https://wpemerge.com/
8
 */
9
10
namespace WPEmerge\Exceptions;
11
12
use Whoops\Handler\PrettyPageHandler;
13
use Whoops\Run;
14
use WPEmerge\Facades\Application;
15
use WPEmerge\ServiceProviders\ExtendsConfigTrait;
16
use WPEmerge\ServiceProviders\ServiceProviderInterface;
17
18
/**
19
 * Provide exceptions dependencies.
20
 *
21
 * @codeCoverageIgnore
22
 */
23
class ExceptionsServiceProvider implements ServiceProviderInterface {
24
	use ExtendsConfigTrait;
25
26
	/**
27
	 * {@inheritDoc}
28
	 */
29
	public function register( $container ) {
30
		$this->extendConfig( $container, 'debug', [
31
			'pretty_errors' => true,
32
		] );
33
34
		$container['whoops'] = function () {
35
			if ( ! class_exists( Run::class ) ) {
36
				return null;
37
			}
38
39
			$handler = new PrettyPageHandler();
40
			$handler->addResourcePath( WPEMERGE_DIR . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Exceptions' . DIRECTORY_SEPARATOR . 'Whoops' );
41
42
			$run = new Run();
43
			$run->allowQuit( false );
44
			$run->pushHandler( $handler );
45
			return $run;
46
		};
47
48
		$container[ WPEMERGE_EXCEPTIONS_ERROR_HANDLER_KEY ] = function ( $c ) {
49
			$whoops = $c[ WPEMERGE_CONFIG_KEY ]['debug']['pretty_errors'] ? $c['whoops'] : null;
50
			return new ErrorHandler( $whoops, Application::debugging() );
51
		};
52
53
		$container[ WPEMERGE_EXCEPTIONS_CONFIGURATION_ERROR_HANDLER_KEY ] = function ( $c ) {
54
			$whoops = $c[ WPEMERGE_CONFIG_KEY ]['debug']['pretty_errors'] ? $c['whoops'] : null;
55
			return new ErrorHandler( $whoops, Application::debugging() );
56
		};
57
	}
58
59
	/**
60
	 * {@inheritDoc}
61
	 */
62
	public function bootstrap( $container ) {
63
		// Nothing to bootstrap.
64
	}
65
}
66