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/PrometheusExporter.php (158 issues)

1
<?php
0 ignored issues
show
Filename "PrometheusExporter.php" doesn't match the expected filename "prometheusexporter.php"
Loading history...
2
namespace Triadev\PrometheusExporter;
3
4
use Prometheus\PushGateway;
5
use Triadev\PrometheusExporter\Contract\PrometheusExporterContract;
6
use Prometheus\CollectorRegistry;
7
use Prometheus\MetricFamilySamples;
8
use Prometheus\Exception\MetricNotFoundException;
9
10
class PrometheusExporter implements PrometheusExporterContract
11
{
12
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
13
     * @var CollectorRegistry
14
     */
15
    private $registry;
0 ignored issues
show
Expected 1 blank line before member var; 0 found
Loading history...
Private member variable "registry" must contain a leading underscore
Loading history...
Private member variable "registry" must be prefixed with an underscore
Loading history...
16
17
    /**
18
     * LpeManager constructor.
19
     *
20
     * @param CollectorRegistry $registry
0 ignored issues
show
Missing parameter comment
Loading history...
21 2
     */
22
    public function __construct(CollectorRegistry $registry)
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
23 2
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
24 2
        $this->registry = $registry;
25
    }
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...
26
27
    /**
28
     * Get metric family samples
29
     *
30
     * @return MetricFamilySamples[]
31 2
     */
32
    public function getMetricFamilySamples()
33 2
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
34
        return $this->registry->getMetricFamilySamples();
35
    }
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 getMetricFamilySamples()
Loading history...
36
    
37
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Parameter $help should have a doc-comment as per coding-style.
Loading history...
Parameter $namespace should have a doc-comment as per coding-style.
Loading history...
Parameter $labelKeys should have a doc-comment as per coding-style.
Loading history...
Parameter $labelValues should have a doc-comment as per coding-style.
Loading history...
38
     * @inheritdoc
39 2
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
40
    public function incCounter($name, $help, $namespace = null, array $labelKeys = [], array $labelValues = [])
0 ignored issues
show
Incorrect spacing between argument "$namespace" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$namespace"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$labelKeys" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelKeys"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
Incorrect spacing between argument "$labelValues" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelValues"; expected 0 but found 1
Loading history...
This line exceeds maximum limit of 100 characters; contains 111 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...
41 2
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
42
        $namespace = $this->getNamespace($namespace);
43
        
44 2
        try {
45 2
            $counter = $this->registry->getCounter($namespace, $name);
46 2
        } catch (MetricNotFoundException $e) {
47
            $counter = $this->registry->registerCounter($namespace, $name, $help, $labelKeys);
48
        }
49 2
50
        $counter->inc($labelValues);
51
52
        $this->pushGateway($this->registry, 'inc');
53
    }
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 incCounter()
Loading history...
54
    
55
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Parameter $help should have a doc-comment as per coding-style.
Loading history...
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Parameter $namespace should have a doc-comment as per coding-style.
Loading history...
Parameter $labelKeys should have a doc-comment as per coding-style.
Loading history...
Parameter $labelValues should have a doc-comment as per coding-style.
Loading history...
56
     * @inheritdoc
57
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
58
    public function incByCounter(
59
        $name,
60
        $help,
61
        $value,
62
        $namespace = null,
0 ignored issues
show
Incorrect spacing between argument "$namespace" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$namespace"; expected 0 but found 1
Loading history...
63
        array $labelKeys = [],
0 ignored issues
show
Incorrect spacing between argument "$labelKeys" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelKeys"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
64
        array $labelValues = []
0 ignored issues
show
Incorrect spacing between argument "$labelValues" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelValues"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
65
    ) {
0 ignored issues
show
Opening brace should be on a new line
Loading history...
66
        $namespace = $this->getNamespace($namespace);
67
68
        try {
69
            $counter = $this->registry->getCounter($namespace, $name);
70
        } catch (MetricNotFoundException $e) {
71
            $counter = $this->registry->registerCounter($namespace, $name, $help, $labelKeys);
72
        }
73
74
        $counter->incBy($value, $labelValues);
75
76
        $this->pushGateway($this->registry, 'incBy');
77
    }
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 incByCounter()
Loading history...
78
    
79
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Parameter $help should have a doc-comment as per coding-style.
Loading history...
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Parameter $namespace should have a doc-comment as per coding-style.
Loading history...
Parameter $labelKeys should have a doc-comment as per coding-style.
Loading history...
Parameter $labelValues should have a doc-comment as per coding-style.
Loading history...
80
     * @inheritdoc
81
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
82
    public function setGauge($name, $help, $value, $namespace = null, array $labelKeys = [], array $labelValues = [])
0 ignored issues
show
Incorrect spacing between argument "$namespace" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$namespace"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$labelKeys" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelKeys"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
Incorrect spacing between argument "$labelValues" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelValues"; expected 0 but found 1
Loading history...
This line exceeds maximum limit of 100 characters; contains 117 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...
83
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
84
        $namespace = $this->getNamespace($namespace);
85
86
        try {
87
            $gauge = $this->registry->getGauge($namespace, $name);
88
        } catch (MetricNotFoundException $e) {
89
            $gauge = $this->registry->registerGauge($namespace, $name, $help, $labelKeys);
90
        }
91
92
        $gauge->set($value, $labelValues);
93
94
        $this->pushGateway($this->registry, 'gauge');
95
    }
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 setGauge()
Loading history...
96
    
97
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Parameter $help should have a doc-comment as per coding-style.
Loading history...
Parameter $namespace should have a doc-comment as per coding-style.
Loading history...
Parameter $labelKeys should have a doc-comment as per coding-style.
Loading history...
Parameter $labelValues should have a doc-comment as per coding-style.
Loading history...
98
     * @inheritdoc
99
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
100
    public function incGauge($name, $help, $namespace = null, array $labelKeys = [], array $labelValues = [])
0 ignored issues
show
Incorrect spacing between argument "$namespace" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$namespace"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$labelKeys" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelKeys"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
Incorrect spacing between argument "$labelValues" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelValues"; expected 0 but found 1
Loading history...
This line exceeds maximum limit of 100 characters; contains 109 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...
101
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
102
        $namespace = $this->getNamespace($namespace);
103
104
        try {
105
            $gauge = $this->registry->getGauge($namespace, $name);
106
        } catch (MetricNotFoundException $e) {
107
            $gauge = $this->registry->registerGauge($namespace, $name, $help, $labelKeys);
108
        }
109
110
        $gauge->inc($labelValues);
111
112
        $this->pushGateway($this->registry, 'inc');
113
    }
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 incGauge()
Loading history...
114
    
115
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Parameter $help should have a doc-comment as per coding-style.
Loading history...
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Parameter $namespace should have a doc-comment as per coding-style.
Loading history...
Parameter $labelKeys should have a doc-comment as per coding-style.
Loading history...
Parameter $labelValues should have a doc-comment as per coding-style.
Loading history...
116
     * @inheritdoc
117
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
118
    public function incByGauge(
119
        $name,
120
        $help,
121
        $value,
122
        $namespace = null,
0 ignored issues
show
Incorrect spacing between argument "$namespace" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$namespace"; expected 0 but found 1
Loading history...
123
        array $labelKeys = [],
0 ignored issues
show
Incorrect spacing between argument "$labelKeys" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelKeys"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
124
        array $labelValues = []
0 ignored issues
show
Incorrect spacing between argument "$labelValues" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelValues"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
125
    ) {
0 ignored issues
show
Opening brace should be on a new line
Loading history...
126
        $namespace = $this->getNamespace($namespace);
127
128
        try {
129
            $gauge = $this->registry->getGauge($namespace, $name);
130
        } catch (MetricNotFoundException $e) {
131
            $gauge = $this->registry->registerGauge($namespace, $name, $help, $labelKeys);
132
        }
133
134
        $gauge->incBy($value, $labelValues);
135
136
        $this->pushGateway($this->registry, 'incBy');
137
    }
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 incByGauge()
Loading history...
138
    
139
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Parameter $help should have a doc-comment as per coding-style.
Loading history...
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Parameter $namespace should have a doc-comment as per coding-style.
Loading history...
Parameter $labelKeys should have a doc-comment as per coding-style.
Loading history...
Parameter $labelValues should have a doc-comment as per coding-style.
Loading history...
Parameter $buckets should have a doc-comment as per coding-style.
Loading history...
140
     * @inheritdoc
141
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
142
    public function setHistogram(
143
        $name,
144
        $help,
145
        $value,
146
        $namespace = null,
0 ignored issues
show
Incorrect spacing between argument "$namespace" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$namespace"; expected 0 but found 1
Loading history...
147
        array $labelKeys = [],
0 ignored issues
show
Incorrect spacing between argument "$labelKeys" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelKeys"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
148
        array $labelValues = [],
0 ignored issues
show
Incorrect spacing between argument "$labelValues" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$labelValues"; expected 0 but found 1
Loading history...
Short array syntax is not allowed
Loading history...
149
        ?array $buckets = null
0 ignored issues
show
Incorrect spacing between argument "$buckets" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$buckets"; expected 0 but found 1
Loading history...
150
    ) {
0 ignored issues
show
Opening brace should be on a new line
Loading history...
151
        $namespace = $this->getNamespace($namespace);
152
153
        try {
154
            $histogram = $this->registry->getHistogram($namespace, $name);
155
        } catch (MetricNotFoundException $e) {
156
            $histogram = $this->registry->registerHistogram($namespace, $name, $help, $labelKeys, $buckets);
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 108 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...
157
        }
158
159
        $histogram->observe($value, $labelValues);
160
161
        $this->pushGateway($this->registry, 'histogram');
162
    }
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 setHistogram()
Loading history...
163 2
    
164
    private function getNamespace(?string $namespace = null) : string
0 ignored issues
show
Private method name "PrometheusExporter::getNamespace" must be prefixed with an underscore
Loading history...
Missing function doc comment
Loading history...
Incorrect spacing between argument "$namespace" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$namespace"; expected 0 but found 1
Loading history...
165 2
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
166 2
        if (!$namespace) {
0 ignored issues
show
There must be a single space after a NOT operator; 0 found
Loading history...
167
            $namespace = config('prometheus-exporter.namespace');
168
        }
169 2
170
        return $namespace;
171
    }
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 getNamespace()
Loading history...
172
    
173
    private function pushGateway(CollectorRegistry $registry, string $job, ?array $groupingKey = null)
0 ignored issues
show
Private method name "PrometheusExporter::pushGateway" must be prefixed with an underscore
Loading history...
Missing function doc comment
Loading history...
Incorrect spacing between argument "$groupingKey" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$groupingKey"; expected 0 but found 1
Loading history...
This line exceeds maximum limit of 100 characters; contains 102 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...
174
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
175
        if (config('prometheus-exporter.adapter') == 'push') {
0 ignored issues
show
Operator == prohibited; use === instead
Loading history...
176
            $pushGateway = new PushGateway(config('prometheus-exporter.push_gateway.address'));
177
            
178
            $pushGateway->push(
179
                $registry,
180
                $job,
181
                $groupingKey
182
            );
183
        }
184
    }
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 pushGateway()
Loading history...
185
}
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...
186