AdvancedErrorHandlerProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 41
loc 41
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 21 21 1
A registerRequirements() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ErrorHandler\Slim;
6
7
use Chubbyphp\ErrorHandler\ContentTypeResolver;
8
use Negotiation\Negotiator;
9
use Pimple\Container;
10
use Pimple\ServiceProviderInterface;
11
12
/**
13
 * @deprecated use Chubbyphp\ErrorHandler\AdvancedErrorHandlerProvider
14
 */
15 View Code Duplication
final class AdvancedErrorHandlerProvider implements ServiceProviderInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    /**
18
     * @param Container $container
19
     */
20 3
    public function register(Container $container)
21
    {
22 3
        $this->registerRequirements($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Chubbyphp\ErrorHandler\S...:registerRequirements() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
23
24 1
        $container['errorHandler.defaultProvider'] = function () use ($container) {
25 1
            throw new \RuntimeException('Please configure your default provider for error handler!');
26
        };
27
28 2
        $container['errorHandler.providers'] = function () use ($container) {
29 2
            return [];
30
        };
31
32 3
        $container['errorHandler'] = function () use ($container) {
33 3
            return new AdvancedErrorHandler(
0 ignored issues
show
Deprecated Code introduced by
The class Chubbyphp\ErrorHandler\Slim\AdvancedErrorHandler has been deprecated with message: use Chubbyphp\ErrorHandler\AdvancedErrorHandler

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
34 3
                $container['errorHandler.contentTypeResolver'],
35 3
                $container['errorHandler.defaultProvider'],
36 2
                $container['errorHandler.providers'],
37 2
                $container['logger'] ?? null
38
            );
39
        };
40 3
    }
41
42
    /**
43
     * @param Container $container
44
     */
45
    private function registerRequirements(Container $container)
46
    {
47 3
        $container['errorHandler.acceptNegation'] = function () use ($container) {
48 3
            return new Negotiator();
49
        };
50
51 3
        $container['errorHandler.contentTypeResolver'] = function () use ($container) {
52 3
            return new ContentTypeResolver($container['errorHandler.acceptNegation']);
53
        };
54
    }
55
}
56