Issues (472)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Middleware/RequestPerRoute.php (72 issues)

1
<?php
0 ignored issues
show
Filename "RequestPerRoute.php" doesn't match the expected filename "requestperroute.php"
Loading history...
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
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
13
    private $prometheusExporter;
0 ignored issues
show
Private member variable "prometheusExporter" must contain a leading underscore
Loading history...
Expected 1 blank line before member var; 0 found
Loading history...
Private member variable "prometheusExporter" must be prefixed with an underscore
Loading history...
14
    
15
    /**
16
     * RequestPerRoute constructor.
17
     * @param PrometheusExporterContract $prometheusExporter
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
Missing parameter comment
Loading history...
18 2
     */
19
    public function __construct(PrometheusExporterContract $prometheusExporter)
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
20 2
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
21 2
        $this->prometheusExporter = $prometheusExporter;
22
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end __construct()
Loading history...
23
    
24
    /**
25
     * Handle an incoming request.
26
     *
27
     * @param  Request $request
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 1 found
Loading history...
28
     * @param  \Closure $next
0 ignored issues
show
Missing parameter comment
Loading history...
29
     * @return mixed
0 ignored issues
show
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
30
     *
31
     * @throws MetricsRegistrationException
32 2
     */
33
    public function handle(Request $request, Closure $next)
34 2
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
35
        $start = microtime(true);
36
    
37 2
        /** @var Response $response */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
38
        $response = $next($request);
39 2
    
40
        $durationMilliseconds = (microtime(true) - $start) * 1000.0;
0 ignored issues
show
Arithmetic operation must be bracketed
Loading history...
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.

Loading history...
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
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end handle()
Loading history...
51
    
52
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
53
     * @param string $routeName
0 ignored issues
show
Missing parameter comment
Loading history...
54
     * @param string $method
0 ignored issues
show
Missing parameter comment
Loading history...
55
     * @param int $status
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 4 spaces after parameter type; 1 found
Loading history...
56
     *
57 2
     * @throws MetricsRegistrationException
58
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
59 2
    private function requestCountMetric(string $routeName, string $method, int $status)
0 ignored issues
show
Private method name "RequestPerRoute::requestCountMetric" must be prefixed with an underscore
Loading history...
60 2
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
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
Short array syntax is not allowed
Loading history...
66
                'route',
0 ignored issues
show
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
67
                'method',
0 ignored issues
show
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
68
                'status_code'
0 ignored issues
show
There should be a trailing comma after the last value of an array declaration.
Loading history...
69 2
            ],
70 2
            [
0 ignored issues
show
Short array syntax is not allowed
Loading history...
71 2
                $routeName,
0 ignored issues
show
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
72
                $method,
0 ignored issues
show
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
73
                $status
0 ignored issues
show
There should be a trailing comma after the last value of an array declaration.
Loading history...
74
            ]
75
        );
76
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end requestCountMetric()
Loading history...
77
    
78
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
79
     * @param string $routeName
0 ignored issues
show
Missing parameter comment
Loading history...
80
     * @param string $method
0 ignored issues
show
Missing parameter comment
Loading history...
81
     * @param int $status
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 4 spaces after parameter type; 1 found
Loading history...
82
     * @param int $duration
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 4 spaces after parameter type; 1 found
Loading history...
83
     *
84
     * @throws MetricsRegistrationException
85
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
86
    private function requestLatencyMetric(string $routeName, string $method, int $status, int $duration)
0 ignored issues
show
Private method name "RequestPerRoute::requestLatencyMetric" must be prefixed with an underscore
Loading history...
This line exceeds maximum limit of 100 characters; contains 104 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
87
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
88
        $bucketsPerRoute = null;
89
        
90
        if ($bucketsPerRouteConfig = config('prometheus-exporter.buckets_per_route')) {
0 ignored issues
show
Assignments must be the first block of code on a line
Loading history...
91
            $bucketsPerRoute = array_get($bucketsPerRouteConfig, $routeName);
0 ignored issues
show
Deprecated Code introduced by
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 ignore-deprecated  annotation

91
            $bucketsPerRoute = /** @scrutinizer ignore-deprecated */ array_get($bucketsPerRouteConfig, $routeName);

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.

Loading history...
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
Short array syntax is not allowed
Loading history...
100
                'route',
0 ignored issues
show
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
101
                'method',
0 ignored issues
show
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
102
                'status_code'
0 ignored issues
show
There should be a trailing comma after the last value of an array declaration.
Loading history...
103
            ],
104
            [
0 ignored issues
show
Short array syntax is not allowed
Loading history...
105
                $routeName,
0 ignored issues
show
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
106
                $method,
0 ignored issues
show
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
107
                $status
0 ignored issues
show
There should be a trailing comma after the last value of an array declaration.
Loading history...
108
            ],
109
            $bucketsPerRoute
110
        );
111
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end requestLatencyMetric()
Loading history...
112
}
0 ignored issues
show
Expected //end class
Loading history...
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
113