Code Duplication    Length = 41-43 lines in 2 locations

src/AdvancedErrorHandlerProvider.php 1 location

@@ 11-53 (lines=43) @@
8
use Pimple\Container;
9
use Pimple\ServiceProviderInterface;
10
11
final class AdvancedErrorHandlerProvider implements ServiceProviderInterface
12
{
13
    /**
14
     * @param Container $container
15
     */
16
    public function register(Container $container)
17
    {
18
        $this->registerRequirements($container);
19
20
        $container['errorHandler.defaultProvider'] = function () use ($container) {
21
            throw new \RuntimeException('Please configure your default provider for error handler!');
22
        };
23
24
        $container['errorHandler.providers'] = function () use ($container) {
25
            return [];
26
        };
27
28
        $container['errorHandler.middleware'] = function () use ($container) {
29
            return new ErrorHandlerMiddleware(
30
                 new AdvancedErrorHandler(
31
                    $container['errorHandler.contentTypeResolver'],
32
                    $container['errorHandler.defaultProvider'],
33
                    $container['errorHandler.providers'],
34
                    $container['logger'] ?? null
35
                )
36
            );
37
        };
38
    }
39
40
    /**
41
     * @param Container $container
42
     */
43
    private function registerRequirements(Container $container)
44
    {
45
        $container['errorHandler.acceptNegation'] = function () use ($container) {
46
            return new Negotiator();
47
        };
48
49
        $container['errorHandler.contentTypeResolver'] = function () use ($container) {
50
            return new ContentTypeResolver($container['errorHandler.acceptNegation']);
51
        };
52
    }
53
}
54

src/Slim/AdvancedErrorHandlerProvider.php 1 location

@@ 15-55 (lines=41) @@
12
/**
13
 * @deprecated use Chubbyphp\ErrorHandler\AdvancedErrorHandlerProvider
14
 */
15
final class AdvancedErrorHandlerProvider implements ServiceProviderInterface
16
{
17
    /**
18
     * @param Container $container
19
     */
20
    public function register(Container $container)
21
    {
22
        $this->registerRequirements($container);
23
24
        $container['errorHandler.defaultProvider'] = function () use ($container) {
25
            throw new \RuntimeException('Please configure your default provider for error handler!');
26
        };
27
28
        $container['errorHandler.providers'] = function () use ($container) {
29
            return [];
30
        };
31
32
        $container['errorHandler'] = function () use ($container) {
33
            return new AdvancedErrorHandler(
34
                $container['errorHandler.contentTypeResolver'],
35
                $container['errorHandler.defaultProvider'],
36
                $container['errorHandler.providers'],
37
                $container['logger'] ?? null
38
            );
39
        };
40
    }
41
42
    /**
43
     * @param Container $container
44
     */
45
    private function registerRequirements(Container $container)
46
    {
47
        $container['errorHandler.acceptNegation'] = function () use ($container) {
48
            return new Negotiator();
49
        };
50
51
        $container['errorHandler.contentTypeResolver'] = function () use ($container) {
52
            return new ContentTypeResolver($container['errorHandler.acceptNegation']);
53
        };
54
    }
55
}
56