8
8
9
9
use Monolog \Logger ;
10
10
use Symfony \Component \Yaml \Yaml ;
11
+ use Closure ;
11
12
use InvalidArgumentException ;
12
13
14
+ /**
15
+ * @phpstan-import-type Level from \Monolog\Logger
16
+ */
13
17
class ConfigFile implements ResolverInterface
14
18
{
15
19
public function resolve (Set $ config ): void
@@ -62,33 +66,36 @@ public function resolve(Set $config): void
62
66
}
63
67
}
64
68
65
- if (isset ($ input ['userName ' ])) {
69
+ if (isset ($ input ['userName ' ]) && is_string ( $ input [ ' userName ' ]) ) {
66
70
$ config ->userName = trim ($ input ['userName ' ]);
67
71
}
68
72
69
- if (isset ($ input ['groupName ' ])) {
73
+ if (isset ($ input ['groupName ' ]) && is_string ( $ input [ ' groupName ' ]) ) {
70
74
$ config ->groupName = trim ($ input ['groupName ' ]);
71
75
}
72
76
73
- if (isset ($ input ['appPrefix ' ])) {
77
+ if (isset ($ input ['appPrefix ' ]) && is_string ( $ input [ ' appPrefix ' ]) ) {
74
78
$ config ->appPrefix = trim ($ input ['appPrefix ' ]);
75
79
}
76
80
77
- if (isset ($ input ['pidFile ' ])) {
81
+ if (isset ($ input ['pidFile ' ]) && is_string ( $ input [ ' pidFile ' ]) ) {
78
82
$ config ->pidFile = trim ($ input ['pidFile ' ]);
79
83
}
80
84
81
85
if (isset ($ input ['cores ' ]) && is_array ($ input ['cores ' ])) {
82
86
foreach ($ input ['cores ' ] as $ coreConfig ) {
83
- if (!isset ($ coreConfig ['eslPassword ' ], $ coreConfig ['eslHost ' ], $ coreConfig ['eslPort ' ])) {
87
+ if (
88
+ !is_array ($ coreConfig ) || !isset ($ coreConfig ['eslPassword ' ], $ coreConfig ['eslHost ' ], $ coreConfig ['eslPort ' ]) ||
89
+ !is_string ($ coreConfig ['eslPassword ' ]) || !is_string ($ coreConfig ['eslHost ' ]) || !is_string ($ coreConfig ['eslPort ' ])
90
+ ) {
84
91
fwrite (STDERR , 'Malformed `cores` parameter entry in configuration file: password, host and port are mandatory ' . PHP_EOL );
85
92
86
93
continue ;
87
94
}
88
95
89
96
$ core = new Core ;
90
97
91
- if (isset ($ coreConfig ['eslUser ' ])) {
98
+ if (isset ($ coreConfig ['eslUser ' ]) && is_string ( $ coreConfig [ ' eslUser ' ]) ) {
92
99
$ core ->eslUser = $ coreConfig ['eslUser ' ];
93
100
}
94
101
@@ -100,19 +107,19 @@ public function resolve(Set $config): void
100
107
}
101
108
}
102
109
103
- if (isset ($ input ['defaultHttpMethod ' ])) {
110
+ if (isset ($ input ['defaultHttpMethod ' ]) && is_string ( $ input [ ' defaultHttpMethod ' ]) ) {
104
111
$ config ->defaultHttpMethod = trim ($ input ['defaultHttpMethod ' ]);
105
112
}
106
113
107
- if (isset ($ input ['defaultAnswerUrl ' ])) {
114
+ if (isset ($ input ['defaultAnswerUrl ' ]) && is_string ( $ input [ ' defaultAnswerUrl ' ]) ) {
108
115
if (!filter_var ($ input ['defaultAnswerUrl ' ], FILTER_VALIDATE_URL )) {
109
116
fwrite (STDERR , 'Malformed `defaultAnswerUrl` parameter in configuration file ' . PHP_EOL );
110
117
} else {
111
118
$ config ->defaultAnswerUrl = $ input ['defaultAnswerUrl ' ];
112
119
}
113
120
}
114
121
115
- if (isset ($ input ['defaultHangupUrl ' ])) {
122
+ if (isset ($ input ['defaultHangupUrl ' ]) && is_string ( $ input [ ' defaultHangupUrl ' ]) ) {
116
123
if (!filter_var ($ input ['defaultHangupUrl ' ], FILTER_VALIDATE_URL )) {
117
124
fwrite (STDERR , 'Malformed `defaultHangupUrl` parameter in configuration file ' . PHP_EOL );
118
125
} else {
@@ -121,12 +128,18 @@ public function resolve(Set $config): void
121
128
}
122
129
123
130
if (isset ($ input ['extraChannelVars ' ]) && is_array ($ input ['extraChannelVars ' ])) {
124
- $ config ->extraChannelVars = array_filter (
125
- array_map ('trim ' , $ input ['extraChannelVars ' ]),
126
- function (string $ value ): bool {
127
- return strlen ($ value ) > 0 ;
131
+ /* array_map() used to work fine here, but now it breaks the static analysis:
132
+ * https://github.com/phpstan/phpstan/issues/4376
133
+ */
134
+ foreach ($ input ['extraChannelVars ' ] as $ var ) {
135
+ if (is_string ($ var )) {
136
+ $ var = trim ($ var );
137
+
138
+ if (isset ($ var [0 ])) {
139
+ $ config ->extraChannelVars [] = $ var ;
140
+ }
128
141
}
129
- );
142
+ }
130
143
}
131
144
132
145
if (isset ($ input ['verifyPeer ' ])) {
@@ -145,25 +158,25 @@ function (string $value): bool {
145
158
}
146
159
}
147
160
148
- if (isset ($ input ['restServerBindIp ' ])) {
161
+ if (isset ($ input ['restServerBindIp ' ]) && is_string ( $ input [ ' restServerBindIp ' ]) ) {
149
162
if (filter_var ($ input ['restServerBindIp ' ], FILTER_VALIDATE_IP )) {
150
163
$ config ->restServerBindIp = $ input ['restServerBindIp ' ];
151
164
} else {
152
165
fwrite (STDERR , 'Malformed `restServerBindIp` parameter in configuration file: valid IP address required ' . PHP_EOL );
153
166
}
154
167
}
155
168
156
- if (isset ($ input ['restServerBindPort ' ])) {
169
+ if (isset ($ input ['restServerBindPort ' ]) && is_scalar ( $ input [ ' restServerBindPort ' ]) ) {
157
170
$ port = (int )$ input ['restServerBindPort ' ];
158
171
159
172
if (!$ port || ($ port > 65535 )) {
160
173
fwrite (STDERR , 'Malformed `restServerBindPort` parameter in configuration file: valid port number required ' . PHP_EOL );
161
174
} else {
162
- $ config ->restServerBindPort = $ input [ ' restServerBindPort ' ] ;
175
+ $ config ->restServerBindPort = $ port ;
163
176
}
164
177
}
165
178
166
- if (isset ($ input ['restServerAdvertisedHost ' ])) {
179
+ if (isset ($ input ['restServerAdvertisedHost ' ]) && is_string ( $ input [ ' restServerAdvertisedHost ' ]) ) {
167
180
$ config ->restServerAdvertisedHost = trim ($ input ['restServerAdvertisedHost ' ]);
168
181
}
169
182
@@ -185,7 +198,9 @@ function (string $value): bool {
185
198
186
199
if (isset ($ input ['restServerLogLevel ' ])) {
187
200
try {
188
- $ config ->restServerLogLevel = Logger::toMonologLevel ($ input ['restServerLogLevel ' ]);
201
+ /** @var Level */
202
+ $ restServerLogLevel = $ input ['restServerLogLevel ' ];
203
+ $ config ->restServerLogLevel = Logger::toMonologLevel ($ restServerLogLevel );
189
204
} catch (InvalidArgumentException $ e ) {
190
205
fwrite (STDERR , 'Malformed `restServerLogLevel` parameter in configuration file: ' . $ e ->getMessage () . PHP_EOL );
191
206
}
@@ -203,75 +218,81 @@ function (string $value): bool {
203
218
}
204
219
}
205
220
206
- if (isset ($ input ['restAuthId ' ])) {
221
+ if (isset ($ input ['restAuthId ' ]) && is_string ( $ input [ ' restAuthId ' ]) ) {
207
222
$ config ->restAuthId = trim ($ input ['restAuthId ' ]);
208
223
}
209
224
210
- if (isset ($ input ['restAuthToken ' ])) {
225
+ if (isset ($ input ['restAuthToken ' ]) && is_string ( $ input [ ' restAuthToken ' ]) ) {
211
226
$ config ->restAuthToken = trim ($ input ['restAuthToken ' ]);
212
227
}
213
228
214
- if (isset ($ input ['recordUrl ' ])) {
229
+ if (isset ($ input ['recordUrl ' ]) && is_string ( $ input [ ' recordUrl ' ]) ) {
215
230
if (!filter_var ($ input ['recordUrl ' ], FILTER_VALIDATE_URL )) {
216
231
fwrite (STDERR , 'Malformed `recordUrl` parameter in configuration file ' . PHP_EOL );
217
232
} else {
218
233
$ config ->recordUrl = $ input ['recordUrl ' ];
219
234
}
220
235
}
221
236
222
- if (isset ($ input ['outboundServerBindIp ' ])) {
237
+ if (isset ($ input ['outboundServerBindIp ' ]) && is_string ( $ input [ ' outboundServerBindIp ' ]) ) {
223
238
if (filter_var ($ input ['outboundServerBindIp ' ], FILTER_VALIDATE_IP )) {
224
239
$ config ->outboundServerBindIp = $ input ['outboundServerBindIp ' ];
225
240
} else {
226
241
fwrite (STDERR , 'Malformed `outboundServerBindIp` parameter in configuration file: valid IP address required ' . PHP_EOL );
227
242
}
228
243
}
229
244
230
- if (isset ($ input ['outboundServerBindPort ' ])) {
245
+ if (isset ($ input ['outboundServerBindPort ' ]) && is_scalar ( $ input [ ' outboundServerBindPort ' ]) ) {
231
246
$ port = (int )$ input ['outboundServerBindPort ' ];
232
247
233
248
if (!$ port || ($ port > 65535 )) {
234
249
fwrite (STDERR , 'Malformed `outboundServerBindPort` parameter in configuration file: valid port number required ' . PHP_EOL );
235
250
} else {
236
- $ config ->outboundServerBindPort = $ input [ ' outboundServerBindPort ' ] ;
251
+ $ config ->outboundServerBindPort = $ port ;
237
252
}
238
253
}
239
254
240
- if (isset ($ input ['outboundServerAdvertisedIp ' ])) {
255
+ if (isset ($ input ['outboundServerAdvertisedIp ' ]) && is_string ( $ input [ ' outboundServerAdvertisedIp ' ]) ) {
241
256
if (filter_var ($ input ['outboundServerAdvertisedIp ' ], FILTER_VALIDATE_IP )) {
242
257
$ config ->outboundServerAdvertisedIp = $ input ['outboundServerAdvertisedIp ' ];
258
+ } else if ($ input ['outboundServerAdvertisedIp ' ] === Set::INBOUND_SOCKET_ADDRESS ) {
259
+ $ config ->outboundServerAdvertisedIp = Set::INBOUND_SOCKET_ADDRESS ;
243
260
} else {
244
- fwrite (STDERR , 'Malformed `outboundServerAdvertisedIp` parameter in configuration file: valid IP address required ' . PHP_EOL );
261
+ fwrite (STDERR , 'Malformed `outboundServerAdvertisedIp` parameter in configuration file: valid IP address or ` ' . Set:: INBOUND_SOCKET_ADDRESS . ' ` required ' . PHP_EOL );
245
262
}
246
263
}
247
264
248
- if (isset ($ input ['outboundServerAdvertisedPort ' ])) {
265
+ if (isset ($ input ['outboundServerAdvertisedPort ' ]) && is_scalar ( $ input [ ' outboundServerAdvertisedPort ' ]) ) {
249
266
$ port = (int )$ input ['outboundServerAdvertisedPort ' ];
250
267
251
268
if (!$ port || ($ port > 65535 )) {
252
269
fwrite (STDERR , 'Malformed `outboundServerAdvertisedPort` parameter in configuration file: valid port number required ' . PHP_EOL );
253
270
} else {
254
- $ config ->outboundServerAdvertisedPort = $ input [ ' outboundServerAdvertisedPort ' ] ;
271
+ $ config ->outboundServerAdvertisedPort = $ port ;
255
272
}
256
273
}
257
274
258
275
if (isset ($ input ['outboundServerLogLevel ' ])) {
259
276
try {
260
- $ config ->outboundServerLogLevel = Logger::toMonologLevel ($ input ['outboundServerLogLevel ' ]);
277
+ /** @var Level */
278
+ $ outboundServerLogLevel = $ input ['outboundServerLogLevel ' ];
279
+ $ config ->outboundServerLogLevel = Logger::toMonologLevel ($ outboundServerLogLevel );
261
280
} catch (InvalidArgumentException $ e ) {
262
281
fwrite (STDERR , 'Malformed `outboundServerLogLevel` parameter in configuration file: ' . $ e ->getMessage () . PHP_EOL );
263
282
}
264
283
}
265
284
266
285
if (isset ($ input ['inboundServerLogLevel ' ])) {
267
286
try {
268
- $ config ->inboundServerLogLevel = Logger::toMonologLevel ($ input ['inboundServerLogLevel ' ]);
287
+ /** @var Level */
288
+ $ inboundServerLogLevel = $ input ['inboundServerLogLevel ' ];
289
+ $ config ->inboundServerLogLevel = Logger::toMonologLevel ($ inboundServerLogLevel );
269
290
} catch (InvalidArgumentException $ e ) {
270
291
fwrite (STDERR , 'Malformed `inboundServerLogLevel` parameter in configuration file: ' . $ e ->getMessage () . PHP_EOL );
271
292
}
272
293
}
273
294
274
- if (isset ($ input ['callHeartbeatUrl ' ])) {
295
+ if (isset ($ input ['callHeartbeatUrl ' ]) && is_string ( $ input [ ' callHeartbeatUrl ' ]) ) {
275
296
if (!filter_var ($ input ['callHeartbeatUrl ' ], FILTER_VALIDATE_URL )) {
276
297
fwrite (STDERR , 'Malformed `callHeartbeatUrl` parameter in configuration file ' . PHP_EOL );
277
298
} else {
0 commit comments