LaravelDatadogMiddleware   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 12
c 3
b 0
f 1
dl 0
loc 41
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A logDuration() 0 13 2
A handle() 0 11 2
1
<?php
2
3
namespace ChaseConey\LaravelDatadogHelper\Middleware;
4
5
use Closure;
6
use ChaseConey\LaravelDatadogHelper\Datadog;
7
use Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\HttpFoundation\Response;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class LaravelDatadogMiddleware
11
{
12
13
    /**
14
     * @param $request
15
     * @param Closure $next
16
     * @return \Illuminate\Http\RedirectResponse
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\RedirectResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        $startTime = microtime(true);
21
22
        $response = $next($request);
23
24
        if (config('datadog-helper.enabled', false)) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        if (/** @scrutinizer ignore-call */ config('datadog-helper.enabled', false)) {
Loading history...
25
            static::logDuration($request, $response, $startTime);
26
        }
27
28
        return $response;
29
    }
30
31
    /**
32
     * Logs the duration of a specific request through the application
33
     *
34
     * @param Request $request
35
     * @param Response $response
36
     * @param double $startTime
37
     */
38
    protected static function logDuration(Request $request, Response $response, $startTime)
39
    {
40
        $duration = microtime(true) - $startTime;
41
42
        $tags = [
43
            "status_code" => $response->getStatusCode()
44
        ];
45
46
        if (!config('datadog-helper.middleware_disable_url_tag', false)) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        if (!/** @scrutinizer ignore-call */ config('datadog-helper.middleware_disable_url_tag', false)) {
Loading history...
47
            $tags["url"] = $request->getSchemeAndHttpHost() . $request->getRequestUri();
48
        }
49
50
        Datadog::microtiming('request_time', $duration, 1, $tags);
51
    }
52
}
53