psalm fixes

This commit is contained in:
Robin Appelman 2021-10-27 15:28:12 +02:00
commit cce108848c
5 changed files with 18 additions and 9 deletions

View file

@ -82,6 +82,7 @@ jobs:
run: | run: |
echo '{"host": "localhost","user": "test","password": "test","share": "test","root": ""}' > tests/config.json echo '{"host": "localhost","user": "test","password": "test","share": "test","root": ""}' > tests/config.json
- name: PHPUnit Tests - name: PHPUnit Tests
timeout-minutes: 2
env: env:
BACKEND: ${{ matrix.backend }} BACKEND: ${{ matrix.backend }}
run: php ./vendor/bin/phpunit tests -c tests/phpunit.xml --coverage-clover=coverage.xml run: php ./vendor/bin/phpunit tests -c tests/phpunit.xml --coverage-clover=coverage.xml

View file

@ -267,14 +267,14 @@ class NativeShare extends AbstractShare {
* Open a writeable stream to a remote file * Open a writeable stream to a remote file
* Note: This method will truncate the file to 0bytes first * Note: This method will truncate the file to 0bytes first
* *
* @param string $source * @param string $target
* @return resource a writeable stream * @return resource a writeable stream
* *
* @throws NotFoundException * @throws NotFoundException
* @throws InvalidTypeException * @throws InvalidTypeException
*/ */
public function write(string $source) { public function write(string $target) {
$url = $this->buildUrl($source); $url = $this->buildUrl($target);
$handle = $this->getState()->create($url); $handle = $this->getState()->create($url);
return NativeWriteStream::wrap($this->getState(), $handle, 'w', $url); return NativeWriteStream::wrap($this->getState(), $handle, 'w', $url);
} }
@ -282,14 +282,14 @@ class NativeShare extends AbstractShare {
/** /**
* Open a writeable stream and set the cursor to the end of the stream * Open a writeable stream and set the cursor to the end of the stream
* *
* @param string $source * @param string $target
* @return resource a writeable stream * @return resource a writeable stream
* *
* @throws NotFoundException * @throws NotFoundException
* @throws InvalidTypeException * @throws InvalidTypeException
*/ */
public function append(string $source) { public function append(string $target) {
$url = $this->buildUrl($source); $url = $this->buildUrl($target);
$handle = $this->getState()->open($url, "a+"); $handle = $this->getState()->open($url, "a+");
return NativeWriteStream::wrap($this->getState(), $handle, "a", $url); return NativeWriteStream::wrap($this->getState(), $handle, "a", $url);
} }

View file

@ -62,7 +62,7 @@ class System implements ISystem {
$result = null; $result = null;
$output = []; $output = [];
exec("which $binary 2>&1", $output, $result); exec("which $binary 2>&1", $output, $result);
$this->paths[$binary] = $result === 0 ? trim(implode('', $output)) : null; $this->paths[$binary] = $result === 0 && isset($output[0]) ? (string)$output[0] : null;
} }
return $this->paths[$binary]; return $this->paths[$binary];
} }

View file

@ -132,6 +132,6 @@ class Connection extends RawConnection {
// ignore any errors while trying to send the close command, the process might already be dead // ignore any errors while trying to send the close command, the process might already be dead
@$this->write('close' . PHP_EOL); @$this->write('close' . PHP_EOL);
} }
parent::close($terminate); $this->close_process($terminate);
} }
} }

View file

@ -91,7 +91,7 @@ class RawConnection {
public function isValid(): bool { public function isValid(): bool {
if (is_resource($this->process)) { if (is_resource($this->process)) {
$status = proc_get_status($this->process); $status = proc_get_status($this->process);
return (bool)$status['running']; return $status['running'];
} else { } else {
return false; return false;
} }
@ -202,6 +202,14 @@ class RawConnection {
* @psalm-assert null $this->process * @psalm-assert null $this->process
*/ */
public function close(bool $terminate = true): void { public function close(bool $terminate = true): void {
$this->close_process($terminate);
}
/**
* @param bool $terminate
* @psalm-assert null $this->process
*/
protected function close_process(bool $terminate = true): void {
if (!is_resource($this->process)) { if (!is_resource($this->process)) {
return; return;
} }