Code Duplication    Length = 41-41 lines in 2 locations

src/AdvancedErrorHandlerProvider.php 1 location

@@ 11-51 (lines=41) @@
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.service'] = function () use ($container) {
29
            return new AdvancedErrorHandler(
30
                $container['errorHandler.contentTypeResolver'],
31
                $container['errorHandler.defaultProvider'],
32
                $container['errorHandler.providers'],
33
                $container['logger'] ?? null
34
            );
35
        };
36
    }
37
38
    /**
39
     * @param Container $container
40
     */
41
    private function registerRequirements(Container $container)
42
    {
43
        $container['errorHandler.acceptNegation'] = function () use ($container) {
44
            return new Negotiator();
45
        };
46
47
        $container['errorHandler.contentTypeResolver'] = function () use ($container) {
48
            return new ContentTypeResolver($container['errorHandler.acceptNegation']);
49
        };
50
    }
51
}
52

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