Completed
Pull Request — master (#7)
by Chase
02:04
created

LaravelDatadogMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 38
rs 10
c 1
b 0
f 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A logDuration() 0 10 1
A handle() 0 11 2
1
<?php
2
3
namespace ChaseConey\LaravelDatadogHelper\Middleware;
4
5
use Closure, Datadog;
6
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...
7
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...
8
9
class LaravelDatadogMiddleware
10
{
11
12
    /**
13
     * @param $request
14
     * @param Closure $next
15
     * @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...
16
     */
17
    public function handle($request, Closure $next)
18
    {
19
        $startTime = microtime(true);
20
21
        $response = $next($request);
22
23
        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

23
        if (/** @scrutinizer ignore-call */ config('datadog-helper.enabled', false)) {
Loading history...
24
            static::logDuration($request, $response, $startTime);
25
        }
26
27
        return $response;
28
    }
29
30
    /**
31
     * Logs the duration of a specific request through the application
32
     *
33
     * @param Request $request
34
     * @param Response $response
35
     * @param double $startTime
36
     */
37
    protected static function logDuration(Request $request, Response $response, $startTime)
38
    {
39
        $duration = microtime(true) - $startTime;
40
41
        $tags = [
42
            "url" => $request->getSchemeAndHttpHost() . $request->getRequestUri(),
43
            "status_code" => $response->getStatusCode()
44
        ];
45
46
        Datadog::timing('request_time', $duration, 1, $tags);
47
    }
48
49
}
50