Completed
Push — master ( 1a208e...8fcc93 )
by Jérémy
29s queued 23s
created

Config::getApiHost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Ekino New Relic bundle.
7
 *
8
 * (c) Ekino - Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\NewRelicBundle\NewRelic;
15
16
/**
17
 * This value object contains data and configuration that should be passed to the interactors.
18
 */
19
class Config
20
{
21
    private $name;
22
    private $apiKey;
23
    private $apiHost = null;
24
    private $licenseKey;
25
    private $xmit;
26
    private $customEvents;
27
    private $customMetrics;
28
    private $customParameters;
29
    private $deploymentNames;
30
31
    public function __construct(?string $name, string $apiKey = null, string $licenseKey = null, bool $xmit = false, array $deploymentNames = [], ?string $apiHost = null)
32
    {
33
        $this->name = (!empty($name) ? $name : \ini_get('newrelic.appname')) ?: '';
34
        $this->apiKey = $apiKey;
35
        $this->apiHost = $apiHost;
36
        $this->licenseKey = (!empty($licenseKey) ? $licenseKey : \ini_get('newrelic.license')) ?: '';
37
        $this->xmit = $xmit;
38
        $this->deploymentNames = $deploymentNames;
39
        $this->customEvents = [];
40
        $this->customMetrics = [];
41
        $this->customParameters = [];
42
    }
43
44
    public function setCustomEvents(array $customEvents): void
45
    {
46
        $this->customEvents = $customEvents;
47
    }
48
49
    public function getCustomEvents(): array
50
    {
51
        return $this->customEvents;
52
    }
53
54
    public function addCustomEvent(string $name, array $attributes): void
55
    {
56
        $this->customEvents[$name][] = $attributes;
57
    }
58
59
    public function setCustomMetrics(array $customMetrics): void
60
    {
61
        $this->customMetrics = $customMetrics;
62
    }
63
64
    public function getCustomMetrics(): array
65
    {
66
        return $this->customMetrics;
67
    }
68
69
    public function setCustomParameters(array $customParameters): void
70
    {
71
        $this->customParameters = $customParameters;
72
    }
73
74
    /**
75
     * @param string|int|float $value or any scalar value
76
     */
77
    public function addCustomParameter(string $name, $value): void
78
    {
79
        $this->customParameters[$name] = $value;
80
    }
81
82
    public function addCustomMetric(string $name, float $value): void
83
    {
84
        $this->customMetrics[$name] = $value;
85
    }
86
87
    public function getCustomParameters(): array
88
    {
89
        return $this->customParameters;
90
    }
91
92
    public function getName(): string
93
    {
94
        return $this->name;
95
    }
96
97
    /**
98
     * @return string[]
99
     */
100
    public function getDeploymentNames(): array
101
    {
102
        return $this->deploymentNames;
103
    }
104
105
    public function getApiKey(): ?string
106
    {
107
        return $this->apiKey;
108
    }
109
110
    public function getApiHost(): ?string
111
    {
112
        return $this->apiHost;
113
    }
114
115
    public function getLicenseKey(): ?string
116
    {
117
        return $this->licenseKey;
118
    }
119
120
    public function getXmit(): bool
121
    {
122
        return $this->xmit;
123
    }
124
}
125