Skip to content

Commit 2e20d1e

Browse files
committed
chore: Fix psalm issues
1 parent 89f5dfc commit 2e20d1e

File tree

6 files changed

+85
-45
lines changed

6 files changed

+85
-45
lines changed

src/Common/EnvConfig/Client/ConfigCodec.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,23 @@
1414
*/
1515
final class ConfigCodec
1616
{
17+
/** @var non-empty-string|null $endpoint Endpoint URL for the remote codec service */
18+
public readonly ?string $endpoint;
19+
20+
/** @var non-empty-string|null $auth Authorization header value for codec authentication */
21+
public readonly ?string $auth;
22+
1723
/**
18-
* @param non-empty-string|null $endpoint Endpoint URL for the remote codec service
19-
* @param non-empty-string|null $auth Authorization header value for codec authentication
24+
* @param string|null $endpoint Endpoint URL for the remote codec service
25+
* @param string|null $auth Authorization header value for codec authentication
2026
*/
2127
public function __construct(
22-
public readonly ?string $endpoint = null,
23-
public readonly ?string $auth = null,
24-
) {}
28+
?string $endpoint = null,
29+
?string $auth = null,
30+
) {
31+
$this->auth = $auth === '' ? null : $auth;
32+
$this->endpoint = $endpoint === '' ? null : $endpoint;
33+
}
2534

2635
/**
2736
* Merge this codec config with another, with the other config's values taking precedence.

src/Common/EnvConfig/Client/ConfigEnv.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,39 @@
4343
*/
4444
final class ConfigEnv
4545
{
46-
public function __construct(
46+
/**
47+
* Current active profile name from TEMPORAL_PROFILE
48+
* @var non-empty-lowercase-string|null
49+
*/
50+
public readonly ?string $currentProfile;
51+
52+
/**
53+
* Path to TOML configuration file from TEMPORAL_CONFIG_FILE
54+
* @var non-empty-string|null
55+
*/
56+
public readonly ?string $configFile;
57+
58+
/**
59+
* @param ConfigProfile $profile Profile constructed from environment variables
60+
* @param string|null $currentProfile Current active profile name
61+
* @param string|null $configFile Path to TOML configuration file
62+
*/
63+
private function __construct(
4764
/**
4865
* Profile constructed from environment variables
4966
*/
5067
public readonly ConfigProfile $profile,
51-
/**
52-
* Current active profile name from TEMPORAL_PROFILE
53-
* @var non-empty-lowercase-string|null
54-
*/
55-
public readonly ?string $currentProfile = null,
56-
/**
57-
* Path to TOML configuration file from TEMPORAL_CONFIG_FILE
58-
* @var non-empty-string|null
59-
*/
60-
public readonly ?string $configFile = null,
61-
) {}
68+
?string $currentProfile = null,
69+
?string $configFile = null,
70+
) {
71+
$this->currentProfile = $currentProfile === '' || $currentProfile === null
72+
? null
73+
: \strtolower($currentProfile);
74+
$this->configFile = $configFile === '' ? null : $configFile;
75+
}
6276

6377
public static function fromEnvProvider(EnvProvider $env): self
6478
{
65-
$profile = \strtolower($env->get('TEMPORAL_PROFILE', '')) ?? '';
66-
$profile === '' and $profile = null;
67-
6879
return new self(
6980
new ConfigProfile(
7081
address: $env->get('TEMPORAL_ADDRESS'),
@@ -74,7 +85,7 @@ public static function fromEnvProvider(EnvProvider $env): self
7485
grpcMeta: self::fetchGrpcMeta($env),
7586
codecConfig: self::fetchCodecConfig($env),
7687
),
77-
$profile,
88+
$env->get('TEMPORAL_PROFILE'),
7889
$env->get('TEMPORAL_CONFIG_FILE'),
7990
);
8091
}
@@ -139,6 +150,7 @@ private static function fetchGrpcMeta(EnvProvider $env): array
139150

140151
foreach ($meta as $key => $value) {
141152
// Transform header name: lowercase and replace _ with -
153+
/** @var non-empty-string $headerName */
142154
$headerName = \str_replace('_', '-', $key);
143155
$result[$headerName] = $value;
144156
}

src/Common/EnvConfig/Client/ConfigProfile.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,21 @@ private static function mergeTlsConfigs(?ConfigTls $to, ?ConfigTls $from): ?Conf
191191
* Keys are normalized to lowercase per gRPC specification. Values from the second array
192192
* replace values from the first array for duplicate keys (case-insensitive).
193193
*
194-
* @param array<non-empty-lowercase-string, list<string>> $to Base metadata
195-
* @param array<non-empty-lowercase-string, list<string>> $from Metadata to merge (overrides base)
194+
* @param array<non-empty-string, list<string>> $to Base metadata
195+
* @param array<non-empty-string, list<string>> $from Metadata to merge (overrides base)
196196
* @return array<non-empty-lowercase-string, list<string>> Merged metadata
197197
*/
198198
private static function mergeGrpcMeta(array $to, array $from): array
199199
{
200-
$merged = $to;
200+
$merged = [];
201+
foreach ($to as $key => $values) {
202+
$merged[\strtolower($key)] = $values;
203+
}
204+
201205
foreach ($from as $key => $values) {
202-
$lowerKey = \strtolower($key);
203-
$merged[$lowerKey] = $values;
206+
$merged[\strtolower($key)] = $values;
204207
}
208+
205209
return $merged;
206210
}
207211

src/Common/EnvConfig/Client/ConfigTls.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,38 @@
1515
*/
1616
final class ConfigTls
1717
{
18+
/** @var non-empty-string|null Root certificates string or file in PEM format */
19+
public readonly ?string $rootCerts;
20+
21+
/** @var non-empty-string|null Client private key string or file in PEM format */
22+
public readonly ?string $privateKey;
23+
24+
/** @var non-empty-string|null Client certificate chain string or file in PEM format */
25+
public readonly ?string $certChain;
26+
27+
/** @var non-empty-string|null Server name override for TLS verification */
28+
public readonly ?string $serverName;
29+
1830
/**
1931
* @param bool $disabled Whether to disable TLS.
20-
* @param non-empty-string|null $rootCerts Root certificates string or file in PEM format.
32+
* @param string|null $rootCerts Root certificates string or file in PEM format.
2133
* If null provided, default gRPC root certificates are used.
22-
* @param non-empty-string|null $privateKey Client private key string or file in PEM format.
23-
* @param non-empty-string|null $certChain Client certificate chain string or file in PEM format.
24-
* @param non-empty-string|null $serverName Server name override for TLS verification.
34+
* @param string|null $privateKey Client private key string or file in PEM format.
35+
* @param string|null $certChain Client certificate chain string or file in PEM format.
36+
* @param string|null $serverName Server name override for TLS verification.
2537
*/
2638
public function __construct(
2739
public readonly ?bool $disabled = false,
28-
public readonly ?string $rootCerts = null,
29-
public readonly ?string $privateKey = null,
30-
public readonly ?string $certChain = null,
31-
public readonly ?string $serverName = null,
32-
) {}
40+
?string $rootCerts = null,
41+
?string $privateKey = null,
42+
?string $certChain = null,
43+
?string $serverName = null,
44+
) {
45+
$this->rootCerts = $rootCerts === '' ? null : $rootCerts;
46+
$this->privateKey = $privateKey === '' ? null : $privateKey;
47+
$this->certChain = $certChain === '' ? null : $certChain;
48+
$this->serverName = $serverName === '' ? null : $serverName;
49+
}
3350

3451
public function mergeWith(ConfigTls $from): self
3552
{

src/Common/EnvConfig/ConfigClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static function load(
113113
public static function loadFromEnv(EnvProvider $envProvider = new SystemEnvProvider()): self
114114
{
115115
$envConfig = ConfigEnv::fromEnvProvider($envProvider);
116-
$profileName = \strtolower($envConfig->currentProfile ?? 'default');
116+
$profileName = $envConfig->currentProfile ?? 'default';
117117

118118
return new self([$profileName => $envConfig->profile]);
119119
}

src/Common/EnvConfig/SystemEnvProvider.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function get(string $name, ?string $default = null): ?string
2323
{
2424
// Try $_ENV first for better performance
2525
if (isset($_ENV[$name])) {
26-
return $_ENV[$name];
26+
return (string) $_ENV[$name];
2727
}
2828

2929
// Fallback to getenv() for environment variables not in $_ENV
@@ -45,21 +45,19 @@ public function getByPrefix(string $prefix, bool $stripPrefix = false): array
4545
if (\str_starts_with($key, $prefix)) {
4646
$resultKey = $stripPrefix ? \substr($key, $prefixLength) : $key;
4747
if ($resultKey !== '') {
48-
$result[$resultKey] = $value;
48+
$result[$resultKey] = (string) $value;
4949
}
5050
}
5151
}
5252

5353
// Search in getenv() for variables not in $_ENV
5454
// Note: getenv() without arguments returns all environment variables
5555
$envVars = \getenv();
56-
if (\is_array($envVars)) {
57-
foreach ($envVars as $key => $value) {
58-
if (\str_starts_with($key, $prefix) && !isset($_ENV[$key])) {
59-
$resultKey = $stripPrefix ? \substr($key, $prefixLength) : $key;
60-
if ($resultKey !== '' && !\array_key_exists($resultKey, $result)) {
61-
$result[$resultKey] = $value;
62-
}
56+
foreach ($envVars as $key => $value) {
57+
if (\str_starts_with($key, $prefix) && !isset($_ENV[$key])) {
58+
$resultKey = $stripPrefix ? \substr($key, $prefixLength) : $key;
59+
if ($resultKey !== '' && !\array_key_exists($resultKey, $result)) {
60+
$result[$resultKey] = $value;
6361
}
6462
}
6563
}

0 commit comments

Comments
 (0)