Test Failed
Push — main ( d01f4c...5af89f )
by Bingo
15:56
created

InternalsImpl::setIntegration()   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
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Jabe\Engine\Impl\Telemetry\Dto;
4
5
use Jabe\Engine\Telemetry\{
6
    ApplicationServerInterface,
7
    DatabaseInterface,
8
    InternalsInterface,
9
    LicenseKeyDataInterface
10
};
11
12
class InternalsImpl implements InternalsInterface
13
{
14
    public const SERIALIZED_APPLICATION_SERVER = "application-server";
15
    public const SERIALIZED_INTEGRATION = "integration";
16
    public const SERIALIZED_LICENSE_KEY = "license-key";
17
    public const SERIALIZED_TELEMETRY_ENABLED = "telemetry-enabled";
18
19
    protected $database;
20
    protected $applicationServer;
21
    protected $licenseKey;
22
    protected $commands = [];
23
    protected $integration = [];
24
    protected $metrics = [];
25
    protected $webapps = [];
26
27
    protected $telemetryEnabled;
28
29
    public function __construct(/*DatabaseImpl|InternalsImpl*/$databaseOrOnternals, ApplicationServerInterface $server = null, LicenseKeyDataInterface $licenseKey = null)
0 ignored issues
show
Unused Code introduced by
The parameter $databaseOrOnternals is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
    public function __construct(/*DatabaseImpl|InternalsImpl*//** @scrutinizer ignore-unused */ $databaseOrOnternals, ApplicationServerInterface $server = null, LicenseKeyDataInterface $licenseKey = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        if ($databaseOrInternals instanceof DatabaseInterface) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $databaseOrInternals does not exist. Did you maybe mean $databaseOrOnternals?
Loading history...
32
            $this->database = $databaseOrInternals;
33
            $this->applicationServer = $server;
34
            $this->licenseKey = $licenseKey;
35
        } elseif ($databaseOrInternals instanceof InternalsInterface) {
36
            $this->database = $databaseOrInternals->database;
0 ignored issues
show
Bug introduced by
Accessing database on the interface Jabe\Engine\Telemetry\InternalsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
37
            $this->applicationServer = $databaseOrInternals->applicationServer;
0 ignored issues
show
Bug introduced by
Accessing applicationServer on the interface Jabe\Engine\Telemetry\InternalsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
38
            $this->licenseKey = $databaseOrInternals->licenseKey;
0 ignored issues
show
Bug introduced by
Accessing licenseKey on the interface Jabe\Engine\Telemetry\InternalsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
39
            $this->integration = $databaseOrInternals->getIntegration();
40
            $this->commands = $databaseOrInternals->getCommands();
41
            $this->metrics = $databaseOrInternals->getMetrics();
42
            $this->telemetryEnabled = $databaseOrInternals->telemetryEnabled;
0 ignored issues
show
Bug introduced by
Accessing telemetryEnabled on the interface Jabe\Engine\Telemetry\InternalsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
43
            $this->webapps = $databaseOrInternals->webapps;
0 ignored issues
show
Bug introduced by
Accessing webapps on the interface Jabe\Engine\Telemetry\InternalsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
44
        }
45
    }
46
47
    public function __toString()
48
    {
49
        $commands = [];
50
        foreach ($this->commands as $command) {
51
            $commands[] = json_decode($command);
52
        }
53
        $integrations = [];
54
        foreach ($this->integration as $integration) {
55
            $integrations[] = json_decode($integration);
56
        }
57
        return json_encode([
58
            'database' => json_decode($this->database),
59
            'applicationServer' => json_decode($this->applicationServer),
60
            'licenseKey' => json_decode($this->licenseKey),
61
            'commands' => $commands,
62
            'integration' => $integrations
63
        ]);
64
    }
65
66
    public function getDatabase(): DatabaseInterface
67
    {
68
        return $this->database;
69
    }
70
71
    public function setDatabase(DatabaseInterface $database): void
72
    {
73
        $this->database = $database;
74
    }
75
76
    public function getApplicationServer(): ApplicationServerInterface
77
    {
78
        return $this->applicationServer;
79
    }
80
81
    public function setApplicationServer(ApplicationServerInterface $applicationServer): void
82
    {
83
        $this->applicationServer = $applicationServer;
84
    }
85
86
    public function getCommands(): array
87
    {
88
        return $this->commands;
89
    }
90
91
    public function setCommands(array $commands): void
92
    {
93
        $this->commands = $commands;
94
    }
95
96
    public function getMetrics(): array
97
    {
98
        return $this->metrics;
99
    }
100
101
    public function setMetrics(array $metrics): void
102
    {
103
        $this->metrics = $metrics;
104
    }
105
106
    public function mergeDynamicData(InternalsInterface $other): void
107
    {
108
        $this->commands = $other->commands;
0 ignored issues
show
Bug introduced by
Accessing commands on the interface Jabe\Engine\Telemetry\InternalsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
109
        $this->metrics = $other->metrics;
0 ignored issues
show
Bug introduced by
Accessing metrics on the interface Jabe\Engine\Telemetry\InternalsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
110
    }
111
112
    public function getIntegration(): array
113
    {
114
        return $this->integration;
115
    }
116
117
    public function setIntegration(array $integration): void
118
    {
119
        $this->integration = $integration;
120
    }
121
122
    public function getLicenseKey(): LicenseKeyDataInterface
123
    {
124
        return $this->licenseKey;
125
    }
126
127
    public function setLicenseKey(LicenseKeyDataInterface $licenseKey): void
128
    {
129
        $this->licenseKey = $licenseKey;
130
    }
131
132
    public function getTelemetryEnabled(): bool
133
    {
134
        return $this->telemetryEnabled;
135
    }
136
137
    public function setTelemetryEnabled(bool $telemetryEnabled): void
138
    {
139
        $this->telemetryEnabled = $telemetryEnabled;
140
    }
141
142
    public function getWebapps(): array
143
    {
144
        return $this->webapps;
145
    }
146
147
    public function setWebapps(array $webapps): void
148
    {
149
        $this->webapps = $webapps;
150
    }
151
}
152