Passed
Push — master ( e63f1d...295fd2 )
by Andrea Marco
03:11 queued 14s
created

JsonApiErrorServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 28
ccs 7
cts 7
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\JsonApiError\Providers;
6
7
use Cerbero\JsonApiError\JsonApiError;
8
use Cerbero\JsonApiError\Services\TestResponseMixin;
9
use Illuminate\Contracts\Debug\ExceptionHandler;
10
use Illuminate\Http\Request;
11
use Illuminate\Support\ServiceProvider;
12
use Illuminate\Testing\TestResponse;
13
use Throwable;
14
15
/**
16
 * The package service provider.
17
 */
18
final class JsonApiErrorServiceProvider extends ServiceProvider
19
{
20
    /**
21
     * The name of the package.
22
     */
23
    public const NAME = 'json-api-error';
24
25
    /**
26
     * The path to the translation files.
27
     */
28
    public const PATH_LANG = __DIR__ . '/../../lang';
29
30
    /**
31
     * Bootstrap the package services.
32
     *
33
     * @param \Illuminate\Foundation\Exceptions\Handler $handler
34
     */
35 12
    public function boot(ExceptionHandler $handler): void
36
    {
37 12
        $handler->renderable(function (Throwable $e, Request $request) {
38 11
            return $request->expectsJson() ? JsonApiError::from($e)->response() : null;
39 12
        });
40
41 12
        $this->loadTranslationsFrom(self::PATH_LANG, self::NAME);
42
43 12
        $this->publishes([self::PATH_LANG => $this->app->langPath('vendor/json-api-error')], self::NAME);
44
45 12
        TestResponse::mixin(new TestResponseMixin());
46
    }
47
}
48