ErrorHandlerMiddlewareFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\Http;
6
7
use Devanych\Di\FactoryInterface;
8
use HttpSoft\Basis\ErrorHandler\ErrorJsonResponseGenerator;
9
use HttpSoft\Basis\ErrorHandler\LogErrorListener;
10
use HttpSoft\ErrorHandler\ErrorHandlerMiddleware;
11
use Psr\Container\ContainerInterface;
12
use Psr\Log\LoggerInterface;
13
14
final class ErrorHandlerMiddlewareFactory implements FactoryInterface
15
{
16
    /**
17
     * @param ContainerInterface $container
18
     * @return ErrorHandlerMiddleware
19
     * @psalm-suppress MixedArgument
20
     * @psalm-suppress MixedArrayAccess
21
     */
22 4
    public function create(ContainerInterface $container): ErrorHandlerMiddleware
23
    {
24 4
        $errorHandler = new ErrorHandlerMiddleware(new ErrorJsonResponseGenerator($container->get('config')['debug']));
25 2
        $errorHandler->addListener(new LogErrorListener($container->get(LoggerInterface::class)));
26 2
        return $errorHandler;
27
    }
28
}
29