Completed
Push — master ( a35239...addb26 )
by Chase
02:09
created

LaravelDatadogMiddleware::logDuration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 10
rs 9.4285
c 1
b 0
f 1
1
<?php
2
3
namespace ChaseConey\LaravelDatadogHelper\Middleware;
4
5
use Closure;
6
use 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
            "url" => $request->getSchemeAndHttpHost() . $request->getRequestUri(),
44
            "status_code" => $response->getStatusCode()
45
        ];
46
47
        Datadog::timing('request_time', $duration, 1, $tags);
48
    }
49
}
50