Skip to content

Commit

Permalink
fix new psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Apr 19, 2021
1 parent 5c6a422 commit 9dba42a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/AnonymousAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace Icewind\SMB;

use Icewind\SMB\Exception\Exception;

class AnonymousAuth implements IAuth {
public function getUsername(): ?string {
return null;
Expand All @@ -39,6 +41,8 @@ public function getExtraCommandLineArguments(): string {
}

public function setExtraSmbClientOptions($smbClientState): void {
smbclient_option_set($smbClientState, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, true);
if (smbclient_option_set($smbClientState, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, true) === false) {
throw new Exception("Failed to set smbclient options for anonymous auth");
}
}
}
10 changes: 8 additions & 2 deletions src/KerberosAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace Icewind\SMB;

use Icewind\SMB\Exception\Exception;

/**
* Use existing kerberos ticket to authenticate
*/
Expand All @@ -42,7 +44,11 @@ public function getExtraCommandLineArguments(): string {
}

public function setExtraSmbClientOptions($smbClientState): void {
smbclient_option_set($smbClientState, SMBCLIENT_OPT_USE_KERBEROS, true);
smbclient_option_set($smbClientState, SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS, false);
$success = (bool)smbclient_option_set($smbClientState, SMBCLIENT_OPT_USE_KERBEROS, true);
$success = $success && smbclient_option_set($smbClientState, SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS, false);

if (!$success) {
throw new Exception("Failed to set smbclient options for kerberos auth");
}
}
}
11 changes: 6 additions & 5 deletions src/Native/NativeState.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ public function init(IAuth $auth, IOptions $options) {
/** @var resource $state */
$state = smbclient_state_new();
$this->state = $state;
/** @psalm-suppress UnusedFunctionCall */
smbclient_option_set($this->state, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, false);
/** @psalm-suppress UnusedFunctionCall */
smbclient_option_set($this->state, SMBCLIENT_OPT_TIMEOUT, $options->getTimeout() * 1000);

if (function_exists('smbclient_client_protocols')) {
$maxProtocol = $options->getMaxProtocol();
$minProtocol = $options->getMinProtocol();

smbclient_client_protocols($this->state, $minProtocol, $maxProtocol);
smbclient_client_protocols($this->state, $options->getMinProtocol(), $options->getMaxProtocol());
}

$auth->setExtraSmbClientOptions($this->state);
Expand Down Expand Up @@ -357,7 +356,9 @@ public function setxattr(string $uri, string $key, string $value, int $flags = 0

public function __destruct() {
if ($this->connected) {
smbclient_state_free($this->state);
if (smbclient_state_free($this->state) === false) {
throw new Exception("Failed to free smb state");
}
}
}
}
8 changes: 6 additions & 2 deletions src/Native/NativeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ abstract class NativeStream implements File {
* @return resource
*/
protected static function wrapClass(NativeState $state, $smbStream, string $mode, string $url, string $class) {
stream_wrapper_register('nativesmb', $class);
if (stream_wrapper_register('nativesmb', $class) === false) {
throw new Exception("Failed to register stream wrapper");
}
$context = stream_context_create([
'nativesmb' => [
'state' => $state,
Expand All @@ -61,7 +63,9 @@ protected static function wrapClass(NativeState $state, $smbStream, string $mode
]
]);
$fh = fopen('nativesmb://', $mode, false, $context);
stream_wrapper_unregister('nativesmb');
if (stream_wrapper_unregister('nativesmb') === false) {
throw new Exception("Failed to unregister stream wrapper");
}
return $fh;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Wrapped/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function listShares(): array {
$shareNames = $parser->parseListShares($output);

$shares = [];
foreach ($shareNames as $name => $description) {
foreach ($shareNames as $name => $_description) {
$shares[] = $this->getShare($name);
}
return $shares;
Expand Down

0 comments on commit 9dba42a

Please sign in to comment.