Completed
Pull Request — master (#39)
by
unknown
02:05
created

LoggerHandler   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 21.74 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 16.66%

Importance

Changes 0
Metric Value
dl 20
loc 92
ccs 4
cts 24
cp 0.1666
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A report() 0 4 1
A render() 0 8 1
A renderForConsole() 0 4 1
B shouldRenderException() 20 20 6

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
namespace Recca0120\LaravelTracy\Exceptions;
4
5
use Exception;
6
use Illuminate\Http\Response;
7
use Illuminate\Contracts\View\View;
8
use Recca0120\LaravelTracy\Contracts\IHandler;
9
use Recca0120\LaravelTracy\DebuggerManager;
10
use Illuminate\Contracts\Debug\ExceptionHandler;
11
use Symfony\Component\HttpFoundation\JsonResponse;
12
use Symfony\Component\HttpFoundation\RedirectResponse;
13
14
class LoggerHandler implements ExceptionHandler, IHandler
15
{
16
    /**
17
     * app exception handler.
18
     *
19
     * @var \Illuminate\Contracts\Debug\ExceptionHandler
20
     */
21
    protected $exceptionHandler;
22
23
    /**
24
     * $debuggerManager.
25
     *
26
     * @var \Recca0120\LaravelTracy\DebuggerManager
27
     */
28
    protected $debuggerManager;
29
30
    /**
31
     * __construct.
32
     *
33
     * @param \Illuminate\Contracts\Debug\ExceptionHandler $exceptionHandler
34
     * @param \Recca0120\LaravelTracy\DebuggerManager $debuggerManager
35
     */
36 1
    public function __construct(ExceptionHandler $exceptionHandler, DebuggerManager $debuggerManager)
37
    {
38 1
        $this->exceptionHandler = $exceptionHandler;
39 1
        $this->debuggerManager = $debuggerManager;
40 1
    }
41
42
    /**
43
     * Report or log an exception.
44
     *
45
     * @param \Exception $e
46
     */
47
    public function report(Exception $e)
48
    {
49
        $this->exceptionHandler->report($e);
50
    }
51
52
    /**
53
     * inject sending of email with error and render an exception into an HTTP response.
54
     *
55
     * @param \Illuminate\Http\Request $request
56
     * @param \Exception $e
57
     * @return \Symfony\Component\HttpFoundation\Response
58
     */
59
    public function render($request, Exception $e)
60
    {
61
        $response = $this->exceptionHandler->render($request, $e);
62
63
        $this->debuggerManager->loggerExceptionHandler($e);
64
65
        return $response;
66
    }
67
68
    /**
69
     * Render an exception to the console.
70
     *
71
     * @param \Symfony\Component\Console\Output\OutputInterface $output
72
     * @param \Exception $e
73
     */
74
    public function renderForConsole($output, Exception $e)
75
    {
76
        $this->exceptionHandler->renderForConsole($output, $e);
77
    }
78
79
    /**
80
     * shouldRenderException.
81
     *
82
     * @param \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response $response
83
     * @return bool
84
     */
85 View Code Duplication
    protected function shouldRenderException($response)
0 ignored issues
show
Duplication introduced by
This method 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...
86
    {
87
        if ($response instanceof RedirectResponse) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\HttpFoundation\RedirectResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
88
            return false;
89
        }
90
91
        if ($response instanceof JsonResponse) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\HttpFoundation\JsonResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
92
            return false;
93
        }
94
95
        if ($response->getContent() instanceof View) {
0 ignored issues
show
Bug introduced by
The class Illuminate\Contracts\View\View does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
96
            return false;
97
        }
98
99
        if ($response instanceof Response && $response->getOriginalContent() instanceof View) {
0 ignored issues
show
Bug introduced by
The class Illuminate\Http\Response does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
Bug introduced by
The class Illuminate\Contracts\View\View does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
100
            return false;
101
        }
102
103
        return true;
104
    }
105
}
106