LaravelDatadogHelperServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 7
Bugs 2 Features 0
Metric Value
wmc 4
eloc 25
c 7
b 2
f 0
dl 0
loc 61
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 4 1
A initDatadog() 0 31 2
1
<?php
2
3
namespace ChaseConey\LaravelDatadogHelper;
4
5
use ChaseConey\LaravelDatadogHelper\Datadog\BatchedDogStatsd;
6
use ChaseConey\LaravelDatadogHelper\Datadog\DogStatsd;
7
use Illuminate\Support\ServiceProvider;
8
9
class LaravelDatadogHelperServiceProvider extends ServiceProvider
10
{
11
12
    /**
13
     * Perform post-registration booting of services.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        /** @noinspection PhpUndefinedFunctionInspection */
20
        $this->publishes(
21
            [
22
                __DIR__ . '/../config/datadog-helper.php' => config_path('datadog-helper.php'),
0 ignored issues
show
Bug introduced by
The function config_path 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

22
                __DIR__ . '/../config/datadog-helper.php' => /** @scrutinizer ignore-call */ config_path('datadog-helper.php'),
Loading history...
23
            ]
24
        );
25
    }
26
27
    /**
28
     * Register any package services.
29
     *
30
     * @return void
31
     */
32
    public function register()
33
    {
34
        $this->app->singleton('datadog', function () {
35
            return $this->initDatadog();
36
        });
37
    }
38
39
    protected function initDatadog()
40
    {
41
        $this->mergeConfigFrom(
42
            __DIR__ . '/../config/datadog-helper.php',
43
            'datadog-helper'
44
        );
45
46
        /** @noinspection PhpUndefinedFunctionInspection */
47
        $laravelConfig = config('datadog-helper');
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

47
        $laravelConfig = /** @scrutinizer ignore-call */ config('datadog-helper');
Loading history...
48
49
        $ddConfig = [
50
            'host' => $laravelConfig['statsd_server'],
51
            'port' => $laravelConfig['statsd_port'],
52
            'socket_path' => $laravelConfig['statsd_socket_path'],
53
            'datadog_host' => $laravelConfig['datadog_host'],
54
            'api_key' => $laravelConfig['api_key'],
55
            'app_key' => $laravelConfig['application_key'],
56
            'global_tags' => $laravelConfig['global_tags'],
57
        ];
58
59
        $maxBuffer = $laravelConfig['max_buffer_length'];
60
        if ($maxBuffer > 1) {
61
            $datadog = new BatchedDogStatsd($ddConfig);
62
            $datadog::$maxBufferLength = $maxBuffer;
63
        } else {
64
            $datadog = new DogStatsd($ddConfig);
65
        }
66
67
        $datadog->setMetricsPrefix($laravelConfig['prefix']);
68
69
        return $datadog;
70
    }
71
}
72