Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ConfigureEnvironmentServiceProvider | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
register | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
setTimeZone | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
displayErrors | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
errorReporting | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
setupDevErrorHandler | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Helpers; |
6 | |
7 | use Carbon\CarbonTimeZone; |
8 | use Engelsystem\Config\Config; |
9 | use Engelsystem\Container\ServiceProvider; |
10 | use Engelsystem\Environment; |
11 | use Engelsystem\Exceptions\Handler; |
12 | use Engelsystem\Exceptions\Handlers\HandlerInterface; |
13 | |
14 | class ConfigureEnvironmentServiceProvider extends ServiceProvider |
15 | { |
16 | public function register(): void |
17 | { |
18 | /** @var Config $config */ |
19 | $config = $this->app->get('config'); |
20 | |
21 | $timezone = new CarbonTimeZone($config->get('timezone')); |
22 | $this->setTimeZone($timezone); |
23 | |
24 | $this->displayErrors(false); |
25 | if ($config->get('environment') == 'development') { |
26 | $this->displayErrors(true); |
27 | $this->errorReporting(E_ALL); |
28 | $this->setupDevErrorHandler(); |
29 | } |
30 | } |
31 | |
32 | /** |
33 | * @codeCoverageIgnore |
34 | */ |
35 | protected function setTimeZone(CarbonTimeZone $timeZone): void |
36 | { |
37 | ini_set('date.timezone', (string) $timeZone); |
38 | date_default_timezone_set((string) $timeZone); |
39 | } |
40 | |
41 | /** |
42 | * @codeCoverageIgnore |
43 | */ |
44 | protected function displayErrors(bool $displayErrors): void |
45 | { |
46 | ini_set('display_errors', $displayErrors); |
47 | } |
48 | |
49 | /** |
50 | * @codeCoverageIgnore |
51 | */ |
52 | protected function errorReporting(int $errorReporting): void |
53 | { |
54 | error_reporting($errorReporting); |
55 | } |
56 | |
57 | /** |
58 | * Setup the development error handler |
59 | */ |
60 | protected function setupDevErrorHandler(): void |
61 | { |
62 | /** @var Handler $errorHandler */ |
63 | $errorHandler = $this->app->get('error.handler'); |
64 | $errorHandler->setEnvironment(Environment::DEVELOPMENT); |
65 | $this->app->bind(HandlerInterface::class, 'error.handler.development'); |
66 | } |
67 | } |