Cast config values for strict type matching (#2)

This commit is contained in:
Namoshek 2021-01-05 20:10:57 +01:00 committed by GitHub
parent 78af7a1889
commit 082f2f25b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 15 deletions

View File

@ -126,13 +126,13 @@ class ConnectionManager
throw new ConnectionNotAvailableException($name); throw new ConnectionNotAvailableException($name);
} }
$host = Arr::get($config, 'host'); $host = (string) Arr::get($config, 'host');
$port = Arr::get($config, 'port', 1883); $port = (int) Arr::get($config, 'port', 1883);
$clientId = Arr::get($config, 'client_id'); $clientId = Arr::get($config, 'client_id');
$protocol = Arr::get($config, 'protocol', MqttClient::MQTT_3_1); $protocol = (string) Arr::get($config, 'protocol', MqttClient::MQTT_3_1);
$cleanSession = Arr::get($config, 'use_clean_session', true); $cleanSession = (bool) Arr::get($config, 'use_clean_session', true);
$repository = Arr::get($config, 'repository', Repository::class); $repository = Arr::get($config, 'repository', Repository::class);
$loggingEnabled = Arr::get($config, 'enable_logging', true); $loggingEnabled = (bool) Arr::get($config, 'enable_logging', true);
$settings = $this->buildConnectionSettings(Arr::get($config, 'connection_settings', [])); $settings = $this->buildConnectionSettings(Arr::get($config, 'connection_settings', []));
$repository = $this->application->make($repository); $repository = $this->application->make($repository);
@ -153,16 +153,16 @@ class ConnectionManager
protected function buildConnectionSettings(array $config): ConnectionSettings protected function buildConnectionSettings(array $config): ConnectionSettings
{ {
return (new ConnectionSettings) return (new ConnectionSettings)
->setConnectTimeout(Arr::get($config, 'connect_timeout', 60)) ->setConnectTimeout((int) Arr::get($config, 'connect_timeout', 60))
->setSocketTimeout(Arr::get($config, 'socket_timeout', 5)) ->setSocketTimeout((int) Arr::get($config, 'socket_timeout', 5))
->setResendTimeout(Arr::get($config, 'resend_timeout', 10)) ->setResendTimeout((int) Arr::get($config, 'resend_timeout', 10))
->setKeepAliveInterval(Arr::get($config, 'keep_alive_interval', 10)) ->setKeepAliveInterval((int) Arr::get($config, 'keep_alive_interval', 10))
->setUsername(Arr::get($config, 'auth.username')) ->setUsername(Arr::get($config, 'auth.username'))
->setPassword(Arr::get($config, 'auth.password')) ->setPassword(Arr::get($config, 'auth.password'))
->setUseTls(Arr::get($config, 'tls.enabled', false)) ->setUseTls((bool) Arr::get($config, 'tls.enabled', false))
->setTlsSelfSignedAllowed(Arr::get($config, 'tls.allow_self_signed_certificate', false)) ->setTlsSelfSignedAllowed((bool) Arr::get($config, 'tls.allow_self_signed_certificate', false))
->setTlsVerifyPeer(Arr::get($config, 'tls.verify_peer', true)) ->setTlsVerifyPeer((bool) Arr::get($config, 'tls.verify_peer', true))
->setTlsVerifyPeerName(Arr::get($config, 'tls.verify_peer_name', true)) ->setTlsVerifyPeerName((bool) Arr::get($config, 'tls.verify_peer_name', true))
->setTlsCertificateAuthorityFile(Arr::get($config, 'tls.ca_file')) ->setTlsCertificateAuthorityFile(Arr::get($config, 'tls.ca_file'))
->setTlsCertificateAuthorityPath(Arr::get($config, 'tls.ca_path')) ->setTlsCertificateAuthorityPath(Arr::get($config, 'tls.ca_path'))
->setTlsClientCertificateFile(Arr::get($config, 'tls.client_certificate_file')) ->setTlsClientCertificateFile(Arr::get($config, 'tls.client_certificate_file'))
@ -170,7 +170,7 @@ class ConnectionManager
->setTlsClientCertificateKeyPassphrase(Arr::get($config, 'tls.client_certificate_key_passphrase')) ->setTlsClientCertificateKeyPassphrase(Arr::get($config, 'tls.client_certificate_key_passphrase'))
->setLastWillTopic(Arr::get($config, 'last_will.topic')) ->setLastWillTopic(Arr::get($config, 'last_will.topic'))
->setLastWillMessage(Arr::get($config, 'last_will.message')) ->setLastWillMessage(Arr::get($config, 'last_will.message'))
->setLastWillQualityOfService(Arr::get($config, 'last_will.quality_of_service', MqttClient::QOS_AT_MOST_ONCE)) ->setLastWillQualityOfService((int) Arr::get($config, 'last_will.quality_of_service', MqttClient::QOS_AT_MOST_ONCE))
->setRetainLastWill(Arr::get($config, 'last_will.retain', false)); ->setRetainLastWill((bool) Arr::get($config, 'last_will.retain', false));
} }
} }