Skip to content

Commit ed978bd

Browse files
committed
chore: Fix psalm issues
1 parent 7ea011c commit ed978bd

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

src/Common/EnvConfig/Client/ConfigToml.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ public function toToml(): string
7979
*
8080
* @param bool $condition The condition to assert.
8181
* @param non-empty-string $message The exception message if the assertion fails.
82-
* @return false Returns false if the assertion passes
8382
* @throws \InvalidArgumentException If the assertion fails.
8483
*/
85-
private static function notAssert(bool $condition, string $message): bool
84+
private static function assert(bool $condition, string $message): void
8685
{
8786
$condition or throw new \InvalidArgumentException($message);
88-
return false;
8987
}
9088

9189
/**
@@ -97,18 +95,12 @@ private static function notAssert(bool $condition, string $message): bool
9795
*/
9896
private static function parseProfiles(mixed $profile): array
9997
{
100-
if (self::notAssert(\is_array($profile), 'The `profile` section must be an array.')) {
101-
return [];
102-
}
98+
self::assert(\is_array($profile), 'The `profile` section must be an array.');
10399

104100
$result = [];
105101
foreach ($profile as $name => $config) {
106-
if (
107-
self::notAssert(\is_array($config), 'Each profile configuration must be an array.')
108-
|| self::notAssert(\strlen($name) > 0, 'Profile name must be a non-empty string.')
109-
) {
110-
continue;
111-
}
102+
self::assert(\is_array($config), 'Each profile configuration must be an array.');
103+
self::assert(\strlen($name) > 0, 'Profile name must be a non-empty string.');
112104

113105
$apiKey = $config['api_key'] ?? null;
114106
$tls = $config['tls'] ?? null;
@@ -118,6 +110,7 @@ private static function parseProfiles(mixed $profile): array
118110
default => new ConfigTls(disabled: true),
119111
};
120112

113+
/** @var non-empty-string $name */
121114
$result[$name] = new ConfigProfile(
122115
address: $config['address'] ?? null,
123116
namespace: $config['namespace'] ?? null,
@@ -138,19 +131,19 @@ private static function parseTls(array $tls): ?ConfigTls
138131
$privateKey = $tls['client_key_path'] ?? $tls['client_key_data'] ?? null;
139132
$certChain = $tls['client_cert_path'] ?? $tls['client_cert_data'] ?? null;
140133

141-
$rootCert === null or self::notAssert(
134+
$rootCert === null or self::assert(
142135
isset($tls['server_ca_cert_path']) xor isset($tls['server_ca_cert_data']),
143136
'Cannot specify both `server_ca_cert_path` and `server_ca_cert_data`.',
144137
);
145-
$privateKey === null or self::notAssert(
138+
$privateKey === null or self::assert(
146139
isset($tls['client_key_path']) xor isset($tls['client_key_data']),
147140
'Cannot specify both `client_key_path` and `client_key_data`.',
148141
);
149-
$certChain === null or self::notAssert(
142+
$certChain === null or self::assert(
150143
isset($tls['client_cert_path']) xor isset($tls['client_cert_data']),
151144
'Cannot specify both `client_cert_path` and `client_cert_data`.',
152145
);
153-
self::notAssert(
146+
self::assert(
154147
($privateKey === null) === ($certChain === null),
155148
'Both `client_key_*` and `client_cert_*` must be specified for mTLS.',
156149
);

src/Common/EnvConfig/ConfigClient.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ public static function loadFromToml(string $source): self
146146

147147
/**
148148
* Serialize the client configuration back to TOML format.
149-
*
150-
* @return non-empty-string TOML representation of the configuration
151149
*/
152150
public function toToml(): string
153151
{
@@ -185,7 +183,7 @@ public function hasProfile(string $name): bool
185183
* Normalize profile names to lowercase and validate for duplicates.
186184
*
187185
* @param array<non-empty-string, ConfigProfile> $profiles Profiles with original case names
188-
* @return array<lowercase-string, ConfigProfile> Profiles with lowercase keys
186+
* @return array<non-empty-lowercase-string, ConfigProfile> Profiles with lowercase keys
189187
* @throws DuplicateProfileException If duplicate names found
190188
*/
191189
private static function normalizeProfileNames(array $profiles): array

0 commit comments

Comments
 (0)