phpstan fixes

This commit is contained in:
Robin Appelman 2025-10-25 21:43:15 +02:00
commit 5d37f6813d
10 changed files with 24 additions and 86 deletions

View file

@ -10,21 +10,17 @@ on:
name: CI
jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
checks:
name: Nix checks
runs-on: nix
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: https://github.com/shivammathur/setup-php@v2
- uses: https://codeberg.org/icewind/attic-action@v1
with:
php-version: "8.2"
extensions: apcu
- name: Composer
run: composer install
- name: PHP-CS-Fixer
run: |
composer run cs:check
name: link
instance: https://cache.icewind.link
authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix flake check --keep-going
php-versions:
runs-on: ubuntu-22.04
@ -201,61 +197,3 @@ jobs:
--coverage-clover=coverage.xml
env:
BACKEND: smbclient
static-psalm-analysis:
runs-on: ubuntu-latest
name: Psalm static analysis - PHP ${{ matrix.php-version }}
strategy:
fail-fast: false
matrix:
php-version:
- "8.2"
- "8.3"
- "8.4"
steps:
- name: krb5-dev
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update
sudo apt-get install -y libkrb5-dev libsmbclient-dev
- name: Checkout
uses: actions/checkout@v4
- name: Set up php
uses: https://github.com/shivammathur/setup-php@master
with:
php-version: "${{ matrix.php-version }}"
tools: composer:v2
coverage: none
extensions: apcu, smbclient, krb5
env:
fail-fast: true
- name: Install dependencies
run: composer i
- name: Run coding standards check
run: composer run psalm
phpstan:
name: PHPStan Static Analysis
runs-on: ubuntu-latest
steps:
- name: krb5-dev
run: |
sudo apt-get update
sudo apt-get install -y libkrb5-dev
- uses: actions/checkout@v4
- name: Setup PHP
uses: https://github.com/shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: apcu, smbclient, krb5
env:
fail-fast: true
- name: Composer
run: composer install
- env:
BACKEND: smbclient
run: php ./vendor/bin/phpstan analyse --level 6 src

8
flake.lock generated
View file

@ -46,11 +46,11 @@
"phps": "phps"
},
"locked": {
"lastModified": 1761418624,
"narHash": "sha256-VKsV/b8rQ+SEzAav2uJYZSbJFv0m6bpsJJSURnsZIPk=",
"lastModified": 1761424893,
"narHash": "sha256-vBYj2I6xdVImVAMU7u1CCZkZELIbbo6dzAo/9pSc6RI=",
"ref": "refs/heads/main",
"rev": "dbdb33ac9ff56810441e6693645da7ea0fbcc950",
"revCount": 3,
"rev": "a59a517f661f7381303588ad20c945ddf916ff5c",
"revCount": 7,
"type": "git",
"url": "https://codeberg.org/icewind/flakelight-php.git"
},

View file

@ -9,6 +9,6 @@
outputs = {flakelight-php, ...}:
flakelight-php ./. {
vendorHash = "sha256-biMQm0+JPJxnxlnvZMpVNhd3s/KPno8LQ/kL8D5xrHU=";
phpExtensions = all: with all; [smbclient];
phpExtensions = all: with all; [smbclient krb5];
};
}

View file

@ -1,5 +1,5 @@
parameters:
level: 3
level: 7
paths:
- src
stubFiles:

View file

@ -13,7 +13,7 @@ final class AnonymousAuth implements IAuth {
return null;
}
public function getWorkgroup(): ?string {
public function getWorkgroup(): string {
return 'dummy';
}

View file

@ -20,7 +20,7 @@ final class BasicAuth implements IAuth {
$this->password = $password;
}
public function getUsername(): ?string {
public function getUsername(): string {
return $this->username;
}
@ -28,7 +28,7 @@ final class BasicAuth implements IAuth {
return $this->workgroup;
}
public function getPassword(): ?string {
public function getPassword(): string {
return $this->password;
}

View file

@ -40,7 +40,7 @@ class Exception extends \Exception {
if (isset($exceptionMap[$error])) {
$exceptionClass = $exceptionMap[$error];
if (is_numeric($error)) {
return new $exceptionClass($path, $error);
return new $exceptionClass($path, (int)$error);
} else {
return new $exceptionClass($path);
}

View file

@ -78,7 +78,7 @@ final class NativeReadStream extends NativeStream {
return $this->readBuffer->remaining() <= 0 && parent::stream_eof();
}
public function stream_tell() {
public function stream_tell(): int {
return $this->pos;
}

View file

@ -58,7 +58,7 @@ final class NativeWriteStream extends NativeStream {
parent::stream_write($this->writeBuffer->flush());
}
public function stream_write($data) {
public function stream_write($data): int {
$written = $this->writeBuffer->push($data);
$this->pos += $written;
@ -79,7 +79,7 @@ final class NativeWriteStream extends NativeStream {
return parent::stream_close() && $flushResult;
}
public function stream_tell() {
public function stream_tell(): int {
return $this->pos;
}

View file

@ -146,7 +146,7 @@ final class Parser {
// A line = explode statement may not fill all array elements
// properly. May happen when accessing non Windows Fileservers
$words = explode(':', $line, 2);
$name = isset($words[0]) ? $words[0] : '';
$name = $words[0];
$value = isset($words[1]) ? $words[1] : '';
$value = trim($value);
@ -160,7 +160,7 @@ final class Parser {
}
return [
'mtime' => (int)strtotime($data['write_time']),
'mode' => hexdec(substr($data['attributes'], $attributeStart + 1, -1)),
'mode' => (int)hexdec(substr($data['attributes'], $attributeStart + 1, -1)),
'size' => isset($data['stream']) ? (int)(explode(' ', $data['stream'])[1]) : 0
];
}
@ -255,7 +255,7 @@ final class Parser {
}
if (substr($mask, 0, 2) === '0x') {
$maskInt = hexdec($mask);
$maskInt = (int)hexdec($mask);
} else {
$maskInt = 0;
foreach (explode('|', $mask) as $maskString) {