This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
1 | <?php |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
2 | namespace Triadev\PrometheusExporter\Middleware; |
||||
3 | |||||
4 | use Illuminate\Http\Request; |
||||
5 | use Closure; |
||||
6 | use Illuminate\Http\Response; |
||||
7 | use Prometheus\Exception\MetricsRegistrationException; |
||||
8 | use Triadev\PrometheusExporter\Contract\PrometheusExporterContract; |
||||
9 | |||||
10 | class RequestPerRoute |
||||
11 | { |
||||
12 | /** @var PrometheusExporterContract */ |
||||
0 ignored issues
–
show
|
|||||
13 | private $prometheusExporter; |
||||
0 ignored issues
–
show
|
|||||
14 | |||||
15 | /** |
||||
16 | * RequestPerRoute constructor. |
||||
17 | * @param PrometheusExporterContract $prometheusExporter |
||||
0 ignored issues
–
show
|
|||||
18 | 2 | */ |
|||
19 | public function __construct(PrometheusExporterContract $prometheusExporter) |
||||
0 ignored issues
–
show
|
|||||
20 | 2 | { |
|||
0 ignored issues
–
show
|
|||||
21 | 2 | $this->prometheusExporter = $prometheusExporter; |
|||
22 | } |
||||
0 ignored issues
–
show
|
|||||
23 | |||||
24 | /** |
||||
25 | * Handle an incoming request. |
||||
26 | * |
||||
27 | * @param Request $request |
||||
0 ignored issues
–
show
|
|||||
28 | * @param \Closure $next |
||||
0 ignored issues
–
show
|
|||||
29 | * @return mixed |
||||
0 ignored issues
–
show
|
|||||
30 | * |
||||
31 | * @throws MetricsRegistrationException |
||||
32 | 2 | */ |
|||
33 | public function handle(Request $request, Closure $next) |
||||
34 | 2 | { |
|||
0 ignored issues
–
show
|
|||||
35 | $start = microtime(true); |
||||
36 | |||||
37 | 2 | /** @var Response $response */ |
|||
0 ignored issues
–
show
|
|||||
38 | $response = $next($request); |
||||
39 | 2 | ||||
40 | $durationMilliseconds = (microtime(true) - $start) * 1000.0; |
||||
0 ignored issues
–
show
|
|||||
41 | 2 | ||||
42 | 2 | $path = $request->path(); |
|||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
43 | 2 | $method = $request->getMethod(); |
|||
44 | $status = $response->getStatusCode(); |
||||
45 | 2 | ||||
46 | $this->requestCountMetric($path, $method, $status); |
||||
47 | $this->requestLatencyMetric($path, $method, $status, $durationMilliseconds); |
||||
48 | |||||
49 | return $response; |
||||
50 | } |
||||
0 ignored issues
–
show
|
|||||
51 | |||||
52 | /** |
||||
0 ignored issues
–
show
|
|||||
53 | * @param string $routeName |
||||
0 ignored issues
–
show
|
|||||
54 | * @param string $method |
||||
0 ignored issues
–
show
|
|||||
55 | * @param int $status |
||||
0 ignored issues
–
show
|
|||||
56 | * |
||||
57 | 2 | * @throws MetricsRegistrationException |
|||
58 | */ |
||||
0 ignored issues
–
show
|
|||||
59 | 2 | private function requestCountMetric(string $routeName, string $method, int $status) |
|||
0 ignored issues
–
show
|
|||||
60 | 2 | { |
|||
0 ignored issues
–
show
|
|||||
61 | 2 | $this->prometheusExporter->incCounter( |
|||
62 | 2 | 'requests_total', |
|||
63 | 'the number of http requests', |
||||
64 | 2 | config('prometheus_exporter.namespace_http'), |
|||
65 | [ |
||||
0 ignored issues
–
show
|
|||||
66 | 'route', |
||||
0 ignored issues
–
show
|
|||||
67 | 'method', |
||||
0 ignored issues
–
show
|
|||||
68 | 'status_code' |
||||
0 ignored issues
–
show
|
|||||
69 | 2 | ], |
|||
70 | 2 | [ |
|||
0 ignored issues
–
show
|
|||||
71 | 2 | $routeName, |
|||
0 ignored issues
–
show
|
|||||
72 | $method, |
||||
0 ignored issues
–
show
|
|||||
73 | $status |
||||
0 ignored issues
–
show
|
|||||
74 | ] |
||||
75 | ); |
||||
76 | } |
||||
0 ignored issues
–
show
|
|||||
77 | |||||
78 | /** |
||||
0 ignored issues
–
show
|
|||||
79 | * @param string $routeName |
||||
0 ignored issues
–
show
|
|||||
80 | * @param string $method |
||||
0 ignored issues
–
show
|
|||||
81 | * @param int $status |
||||
0 ignored issues
–
show
|
|||||
82 | * @param int $duration |
||||
0 ignored issues
–
show
|
|||||
83 | * |
||||
84 | * @throws MetricsRegistrationException |
||||
85 | */ |
||||
0 ignored issues
–
show
|
|||||
86 | private function requestLatencyMetric(string $routeName, string $method, int $status, int $duration) |
||||
0 ignored issues
–
show
|
|||||
87 | { |
||||
0 ignored issues
–
show
|
|||||
88 | $bucketsPerRoute = null; |
||||
89 | |||||
90 | if ($bucketsPerRouteConfig = config('prometheus-exporter.buckets_per_route')) { |
||||
0 ignored issues
–
show
|
|||||
91 | $bucketsPerRoute = array_get($bucketsPerRouteConfig, $routeName); |
||||
0 ignored issues
–
show
The function
array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||
92 | } |
||||
93 | |||||
94 | $this->prometheusExporter->setHistogram( |
||||
95 | 'requests_latency_milliseconds', |
||||
96 | 'duration of requests', |
||||
97 | $duration, |
||||
98 | config('prometheus_exporter.namespace_http'), |
||||
99 | [ |
||||
0 ignored issues
–
show
|
|||||
100 | 'route', |
||||
0 ignored issues
–
show
|
|||||
101 | 'method', |
||||
0 ignored issues
–
show
|
|||||
102 | 'status_code' |
||||
0 ignored issues
–
show
|
|||||
103 | ], |
||||
104 | [ |
||||
0 ignored issues
–
show
|
|||||
105 | $routeName, |
||||
0 ignored issues
–
show
|
|||||
106 | $method, |
||||
0 ignored issues
–
show
|
|||||
107 | $status |
||||
0 ignored issues
–
show
|
|||||
108 | ], |
||||
109 | $bucketsPerRoute |
||||
110 | ); |
||||
111 | } |
||||
0 ignored issues
–
show
|
|||||
112 | } |
||||
0 ignored issues
–
show
|
|||||
113 |