PrometheusExporterServiceProvider   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 39
c 7
b 0
f 0
dl 0
loc 85
rs 10
ccs 30
cts 33
cp 0.9091
wmc 14

6 Methods

Rating   Name   Duplication   Size   Complexity  
A registerMiddlewareForRequestMetrics() 0 6 2
A bootConfig() 0 13 3
A bootRoutes() 0 4 2
A registerAdapter() 0 19 5
A boot() 0 4 1
A register() 0 11 1
1
<?php
0 ignored issues
show
Coding Style introduced by
Filename "PrometheusExporterServiceProvider.php" doesn't match the expected filename "prometheusexporterserviceprovider.php"
Loading history...
2
namespace Triadev\PrometheusExporter\Provider;
3
4
use Illuminate\Routing\Router;
5
use Illuminate\Support\ServiceProvider;
6
use Prometheus\Storage\InMemory;
7
use Triadev\PrometheusExporter\Contract\PrometheusExporterContract;
8
use Prometheus\Storage\Redis;
9
use Prometheus\Storage\APC;
10
use Prometheus\Storage\Adapter;
11
use Triadev\PrometheusExporter\Middleware\RequestPerRoute;
12
use Triadev\PrometheusExporter\PrometheusExporter;
13
14
class PrometheusExporterServiceProvider extends ServiceProvider
15
{
16
    /**
17
     * Bootstrap the application events.
18
     *
19
     * @return void
20
     */
21 6
    public function boot()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
22
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
23 6
        $this->bootConfig();
24
        $this->bootRoutes();
25 6
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end boot()
Loading history...
26 6
    
27 6
    private function bootConfig()
0 ignored issues
show
Coding Style introduced by
Private method name "PrometheusExporterServiceProvider::bootConfig" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
28 6
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
29
        $source = realpath(__DIR__ . '/../Config/config.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
30
    
31
        if (class_exists('Illuminate\Foundation\Application', false)) {
32
            $this->publishes([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
33 6
                __DIR__ . '/../Config/config.php' => config_path('prometheus-exporter.php'),
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 30 spaces, but found 16.
Loading history...
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
34
            ], 'config');
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 29 space(s), but found 12.
Loading history...
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
35 6
        } elseif (class_exists('Laravel\Lumen\Application', false)) {
0 ignored issues
show
Coding Style introduced by
Usage of ELSEIF not allowed; use ELSE IF instead
Loading history...
36 6
            $this->app/** @scrutinizer ignore-call */->configure('prometheus-exporter');
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
37
        }
38 6
    
39
        $this->mergeConfigFrom($source, 'prometheus-exporter');
40
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end bootConfig()
Loading history...
41
    
42
    private function bootRoutes()
0 ignored issues
show
Coding Style introduced by
Private method name "PrometheusExporterServiceProvider::bootRoutes" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
43
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
44
        if (class_exists('Illuminate\Foundation\Application', false)) {
45 6
            $this->loadRoutesFrom(__DIR__ . '/../Routes/routes.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
46
        }
47 6
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end bootRoutes()
Loading history...
48
49 6
    /**
50 6
     * Register the service provider.
51 3
     *
52 3
     * @throws \ErrorException
53 3
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
54
    public function register()
55 1
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
56 1
        $this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'prometheus-exporter');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
57 1
    
58 2
        $this->registerAdapter();
59 1
        $this->registerMiddlewareForRequestMetrics();
60 1
    
61 1
        $this->app->bind(
62 1
            PrometheusExporterContract::class,
63 1
            PrometheusExporter::class,
64
            true
65
        );
66
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end register()
Loading history...
67
    
68
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
69 6
     * @throws \ErrorException
70 6
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
71
    private function registerAdapter()
0 ignored issues
show
Coding Style introduced by
Private method name "PrometheusExporterServiceProvider::registerAdapter" must be prefixed with an underscore
Loading history...
72 6
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
73 6
        switch (config('prometheus-exporter.adapter')) {
74
            case 'apc':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
75
                $this->app->bind(Adapter::class, APC::class);
76
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
77
            case 'redis':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
78
                $this->app->bind(Adapter::class, function () {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
79
                    return new Redis(config('prometheus-exporter.redis'));
80
                });
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
81
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
82
            case 'push':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
83
                $this->app->bind(Adapter::class, APC::class);
84
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
85
            case 'inmemory':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
86
                $this->app->bind(Adapter::class, InMemory::class);
87
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
88
            default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
89
                throw new \ErrorException('"prometheus-exporter.adapter" must be either apc or redis');
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 103 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...
90
        }
91
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end registerAdapter()
Loading history...
92
    
93
    private function registerMiddlewareForRequestMetrics()
0 ignored issues
show
Coding Style introduced by
Private method name "PrometheusExporterServiceProvider::registerMiddlewareForRequestMetrics" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
94
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
95
        if (class_exists('Illuminate\Foundation\Application', false)) {
96
            /** @var Router $router */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
97
            $router = $this->app['router'];
98
            $router->aliasMiddleware('lpe.requestPerRoute', RequestPerRoute::class);
99
        }
100
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end registerMiddlewareForRequestMetrics()
Loading history...
101
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
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...
102