Skip to content

Commit

Permalink
🦺 Removed possibly falsy string comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
cdosoftei committed May 16, 2024
1 parent 4df5ddd commit 0491356
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 30 deletions.
2 changes: 1 addition & 1 deletion etc/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
includes:
- ../vendor/phpstan/phpstan/conf/bleedingEdge.neon
parameters:
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- identifier: missingType.generics
- '#Parameter \#1 \$onFulfilled of method React\\Promise\\PromiseInterface<mixed>::then\(\) expects \(callable\(mixed\):#'
1 change: 1 addition & 0 deletions etc/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<issueHandlers>
<PropertyNotSetInConstructor errorLevel="suppress" />
<TypeDoesNotContainType errorLevel="suppress" />
<InternalMethod errorLevel="suppress" />

<!-- https://github.com/vimeo/psalm/issues/4823 -->
<RedundantPropertyInitializationCheck errorLevel="suppress" />
Expand Down
10 changes: 5 additions & 5 deletions src/Config/CliArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function resolve(AbstractSet $config): void
$configFile = $args['c'];
}

if ($configFile) {
if (is_string($configFile)) {
switch (pathinfo($configFile, PATHINFO_EXTENSION)) {
case 'json':
case 'yml':
Expand Down Expand Up @@ -168,7 +168,7 @@ function (string $value): bool {
if (isset($args['rest-bind-address']) && is_string($args['rest-bind-address'])) {
$err = Set::parseSocketAddr($args['rest-bind-address'], $ip, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed --rest-bind-address argument: ip:port required' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand Down Expand Up @@ -245,7 +245,7 @@ function (string $value): bool {
if (isset($args['outbound-bind-address']) && is_string($args['outbound-bind-address'])) {
$err = Set::parseSocketAddr($args['outbound-bind-address'], $ip, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed --outbound-bind-address argument: ip:port required' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand All @@ -263,7 +263,7 @@ function (string $value): bool {
} else {
$err = Set::parseSocketAddr($args['outbound-advertised-address'], $ip, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed --outbound-advertised-address argument: ip:port or `inbound_socket_address` required' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand Down Expand Up @@ -313,7 +313,7 @@ function (string $value): bool {

protected function help(): never
{
$cmd = !isset($_SERVER['argv']) || !is_array($_SERVER['argv']) || empty($_SERVER['argv'][0])
$cmd = !isset($_SERVER['argv']) || !is_array($_SERVER['argv']) || !is_string($_SERVER['argv'][0]) || !strlen($_SERVER['argv'][0])
? './bin/ficore'
: $_SERVER['argv'][0];

Expand Down
6 changes: 3 additions & 3 deletions src/Config/EnvironmentVars.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function (string $value): bool {
if (isset($env[self::PREFIX . 'REST_BIND_ADDRESS'])) {
$err = Set::parseSocketAddr($env[self::PREFIX . 'REST_BIND_ADDRESS'], $ip, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed ' . self::PREFIX . 'REST_BIND_ADDRESS environment variable' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand Down Expand Up @@ -173,7 +173,7 @@ function (string $value): bool {
if (isset($env[self::PREFIX . 'OUTBOUND_BIND_ADDRESS'])) {
$err = Set::parseSocketAddr($env[self::PREFIX . 'OUTBOUND_BIND_ADDRESS'], $ip, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed ' . self::PREFIX . 'OUTBOUND_BIND_ADDRESS environment variable' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand All @@ -191,7 +191,7 @@ function (string $value): bool {
} else {
$err = Set::parseSocketAddr($env[self::PREFIX . 'OUTBOUND_ADVERTISED_ADDRESS'], $ip, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed ' . self::PREFIX . 'OUTBOUND_ADVERTISED_ADDRESS environment variable' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/Config/LegacyConfigFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function (string $value): bool {
if (isset($legacy['rest_server']['HTTP_ADDRESS']) && is_string($legacy['rest_server']['HTTP_ADDRESS'])) {
$err = Set::parseSocketAddr($legacy['rest_server']['HTTP_ADDRESS'], $ip, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed HTTP_ADDRESS (rest_server) line in legacy configuration file' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand All @@ -117,7 +117,7 @@ function (string $value): bool {
if (isset($legacy['rest_server']['FS_INBOUND_ADDRESS']) && is_string($legacy['rest_server']['FS_INBOUND_ADDRESS'])) {
$err = Set::parseHostPort($legacy['rest_server']['FS_INBOUND_ADDRESS'], $host, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed FS_INBOUND_ADDRESS (rest_server) line in legacy configuration file' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand Down Expand Up @@ -182,7 +182,7 @@ function (string $value): bool {
if (isset($legacy['outbound_server']['FS_OUTBOUND_ADDRESS']) && is_string($legacy['outbound_server']['FS_OUTBOUND_ADDRESS'])) {
$err = Set::parseSocketAddr($legacy['outbound_server']['FS_OUTBOUND_ADDRESS'], $ip, $port);

if ($err) {
if (is_string($err)) {
fwrite(STDERR, 'Malformed FS_OUTBOUND_ADDRESS (outbound_server) line in legacy configuration file' . PHP_EOL);
fwrite(STDERR, $err . PHP_EOL);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function makeRequest(string $url, string $method = 'POST', array $params
throw new HttpClientException("Cannot send {$url}, cannot parse url");
}

if (!empty($parsed['query'])) {
if (isset($parsed['query']) && strlen($parsed['query'])) {
parse_str($parsed['query'], $extra);
$params = array_merge($params, $extra);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rest/Controller/AuthenticatedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function authenticate(ServerRequestInterface $request): PromiseInterfa

$decoded = base64_decode($parts[1], true);

if (!$decoded) {
if ($decoded === false) {
return reject(new AuthException('Cannot decode authentication payload'));
}

Expand Down
22 changes: 16 additions & 6 deletions src/Rest/Inquiry/V0_1/BulkCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,35 @@ public function export(): RequestInterface
/** @psalm-suppress PropertyTypeCoercion */
$request->gateways[$destIdx] = [];
$gateways = explode(',', $destGateways);
$gatewayCodecs = !empty($this->gwCodecsList[$destIdx])
$gatewayCodecs =
(isset($this->gwCodecsList[$destIdx]) && strlen($this->gwCodecsList[$destIdx]))
? str_getcsv($this->gwCodecsList[$destIdx], ',', "'")
: [];
$gatewayTimeouts = !empty($this->gwTimeoutsList[$destIdx]) ? explode(',', $this->gwTimeoutsList[$destIdx]) : [];
$gatewayRetries = !empty($this->gwRetriesList[$destIdx]) ? explode(',', $this->gwRetriesList[$destIdx]) : [];
$gatewayTimeouts =
(isset($this->gwTimeoutsList[$destIdx]) && strlen($this->gwTimeoutsList[$destIdx]))
? explode(',', $this->gwTimeoutsList[$destIdx])
: [];
$gatewayRetries =
(isset($this->gwRetriesList[$destIdx]) && strlen($this->gwRetriesList[$destIdx]))
? explode(',', $this->gwRetriesList[$destIdx])
: [];

foreach ($gateways as $gwIdx => $gateway) {
$gw = new Gateway();
$gw->name = $gateway;

if (!empty($gatewayCodecs[$gwIdx])) {
if (isset($gatewayCodecs[$gwIdx]) && strlen($gatewayCodecs[$gwIdx])) {
$gw->codecs = $gatewayCodecs[$gwIdx];
}

if (!empty($gatewayTimeouts[$gwIdx])) {
if (isset($gatewayTimeouts[$gwIdx]) && strlen($gatewayTimeouts[$gwIdx])) {
$gw->timeout = intval($gatewayTimeouts[$gwIdx]);
}

$gw->tries = empty($gatewayRetries[$gwIdx]) ? 1 : (int)$gatewayRetries[$gwIdx];
$gw->tries =
(isset($gatewayRetries[$gwIdx]) && strlen($gatewayRetries[$gwIdx]))
? (int)$gatewayRetries[$gwIdx]
: 1;

/** @psalm-suppress PropertyTypeCoercion */
$request->gateways[$destIdx][] = $gw;
Expand Down
9 changes: 6 additions & 3 deletions src/Rest/Inquiry/V0_1/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,18 @@ public function export(): RequestInterface
$gw = new Gateway();
$gw->name = $gateway;

if (!empty($gatewayCodecs[$gwIdx])) {
if (isset($gatewayCodecs[$gwIdx]) && strlen($gatewayCodecs[$gwIdx])) {
$gw->codecs = $gatewayCodecs[$gwIdx];
}

if (!empty($gatewayTimeouts[$gwIdx])) {
if (isset($gatewayTimeouts[$gwIdx]) && strlen($gatewayTimeouts[$gwIdx])) {
$gw->timeout = intval($gatewayTimeouts[$gwIdx]);
}

$gw->tries = empty($gatewayRetries[$gwIdx]) ? 1 : (int)$gatewayRetries[$gwIdx];
$gw->tries =
(isset($gatewayRetries[$gwIdx]) && strlen($gatewayRetries[$gwIdx]))
? (int)$gatewayRetries[$gwIdx]
: 1;

$request->gateways[0][] = $gw;
}
Expand Down
22 changes: 16 additions & 6 deletions src/Rest/Inquiry/V0_1/GroupCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,25 +284,35 @@ public function export(): RequestInterface
/** @psalm-suppress PropertyTypeCoercion */
$request->gateways[$destIdx] = [];
$gateways = explode(',', $destGateways);
$gatewayCodecs = !empty($this->gwCodecsList[$destIdx])
$gatewayCodecs =
(isset($this->gwCodecsList[$destIdx]) && strlen($this->gwCodecsList[$destIdx]))
? str_getcsv($this->gwCodecsList[$destIdx], ',', "'")
: [];
$gatewayTimeouts = !empty($this->gwTimeoutsList[$destIdx]) ? explode(',', $this->gwTimeoutsList[$destIdx]) : [];
$gatewayRetries = !empty($this->gwRetriesList[$destIdx]) ? explode(',', $this->gwRetriesList[$destIdx]) : [];
$gatewayTimeouts =
(isset($this->gwTimeoutsList[$destIdx]) && strlen($this->gwTimeoutsList[$destIdx]))
? explode(',', $this->gwTimeoutsList[$destIdx])
: [];
$gatewayRetries =
(isset($this->gwRetriesList[$destIdx]) && strlen($this->gwRetriesList[$destIdx]))
? explode(',', $this->gwRetriesList[$destIdx])
: [];

foreach ($gateways as $gwIdx => $gateway) {
$gw = new Gateway();
$gw->name = $gateway;

if (!empty($gatewayCodecs[$gwIdx])) {
if (isset($gatewayCodecs[$gwIdx]) && strlen($gatewayCodecs[$gwIdx])) {
$gw->codecs = $gatewayCodecs[$gwIdx];
}

if (!empty($gatewayTimeouts[$gwIdx])) {
if (isset($gatewayTimeouts[$gwIdx]) && strlen($gatewayTimeouts[$gwIdx])) {
$gw->timeout = intval($gatewayTimeouts[$gwIdx]);
}

$gw->tries = empty($gatewayRetries[$gwIdx]) ? 1 : (int)$gatewayRetries[$gwIdx];
$gw->tries =
(isset($gatewayRetries[$gwIdx]) && strlen($gatewayRetries[$gwIdx]))
? (int)$gatewayRetries[$gwIdx]
: 1;

/** @psalm-suppress PropertyTypeCoercion */
$request->gateways[$destIdx][] = $gw;
Expand Down
2 changes: 1 addition & 1 deletion src/Rest/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function run(): void
if (!isset($this->config->restServerAdvertisedHost)) {
$hostname = gethostname();

if (!$hostname) {
if ($hostname === false || !strlen($hostname)) {
$this->config->restServerAdvertisedHost = $this->config->appPrefix;
} else {
$this->config->restServerAdvertisedHost = $hostname;
Expand Down

0 comments on commit 0491356

Please sign in to comment.