psalm fixes

This commit is contained in:
Robin Appelman 2025-10-25 20:47:47 +02:00
commit 8101154ac3
6 changed files with 26 additions and 7 deletions

View file

@ -55,8 +55,16 @@ final class KerberosTicket {
return new KerberosTicket($krb5, $ticketName);
}
public static function load(string $ticket): KerberosTicket {
private static function tmpNam(): string {
$tmpFilename = tempnam(sys_get_temp_dir(), "krb5cc_php_");
if ($tmpFilename === false) {
throw new \Exception("Failed to create temporary file for ticket");
}
return $tmpFilename;
}
public static function load(string $ticket): KerberosTicket {
$tmpFilename = self::tmpNam();
file_put_contents($tmpFilename, $ticket);
register_shutdown_function(function () use ($tmpFilename) {
if (file_exists($tmpFilename)) {
@ -74,12 +82,15 @@ final class KerberosTicket {
if (substr($this->cacheName, 0, 5) === 'FILE:') {
$ticket = file_get_contents(substr($this->cacheName, 5));
} else {
$tmpFilename = tempnam(sys_get_temp_dir(), "krb5cc_php_");
$tmpFilename = self::tmpNam();
$tmpCacheFile = "FILE:" . $tmpFilename;
$this->krb5->save($tmpCacheFile);
$ticket = file_get_contents($tmpFilename);
unlink($tmpFilename);
}
if ($ticket === false) {
throw new \Exception("Failed to read saved ticket");
}
return $ticket;
}
}

View file

@ -204,6 +204,9 @@ final class NativeShare extends AbstractShare {
*/
public function put(string $source, string $target): bool {
$sourceHandle = fopen($source, 'rb');
if (!$sourceHandle) {
return false;
}
$targetUrl = $this->buildUrl($target);
$targetHandle = $this->getState()->create($targetUrl);

View file

@ -65,6 +65,9 @@ abstract class NativeStream implements File {
if (stream_wrapper_unregister('nativesmb') === false) {
throw new Exception("Failed to unregister stream wrapper");
}
if ($fh === false) {
throw new \Exception("Failed to start stream wrapper");
}
return $fh;
}

View file

@ -88,7 +88,7 @@ final class Connection extends RawConnection {
}
/**
* @param string|bool $promptLine (optional) prompt line that might contain some info about the error
* @param string|false $promptLine (optional) prompt line that might contain some info about the error
* @throws ConnectException
* @return no-return
*/

View file

@ -159,7 +159,7 @@ final class Parser {
throw new Exception("Malformed state response from server");
}
return [
'mtime' => strtotime($data['write_time']),
'mtime' => (int)strtotime($data['write_time']),
'mode' => hexdec(substr($data['attributes'], $attributeStart + 1, -1)),
'size' => isset($data['stream']) ? (int)(explode(' ', $data['stream'])[1]) : 0
];
@ -182,7 +182,7 @@ final class Parser {
list(, $name, $mode, $size, $time) = $matches;
if ($name !== '.' and $name !== '..') {
$mode = $this->parseMode(strtoupper($mode));
$time = strtotime($time . ' ' . $this->timeZone);
$time = (int)strtotime($time . ' ' . $this->timeZone);
$path = $basePath . '/' . $name;
$content[] = new FileInfo($path, $name, (int)$size, $time, $mode, function () use ($aclCallback, $path): array {
return $aclCallback($path);

View file

@ -77,7 +77,7 @@ class RawConnection {
'COLUMNS' => 8192, // prevent smbclient from line-wrapping it's output
'TZ' => 'UTC',
]);
$this->process = proc_open($this->command, $descriptorSpec, $this->pipes, '/', $env);
$this->process = proc_open($this->command, $descriptorSpec, $this->pipes, '/', $env) ?: null;
if (!$this->isValid()) {
throw new ConnectionException();
}
@ -211,7 +211,9 @@ class RawConnection {
? "username=$user"
: "username=$user\npassword=$password\n";
$this->authStream = fopen('php://temp', 'w+');
/** @var resource $stream */
$stream = fopen('php://temp', 'w+');
$this->authStream = $stream;
fwrite($this->authStream, $auth);
rewind($this->authStream);
}