1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-05 22:27:24 +02:00

PHPStan: Check level 8 without level 7

This commit is contained in:
Jakub Vrana
2025-03-26 21:16:14 +01:00
parent d3b53d9d9c
commit 584d04b5b3
2 changed files with 10 additions and 8 deletions

View File

@@ -81,11 +81,11 @@ All functions have doc-comments, but redundancy is avoided. For example, `Db` me
Inline comments are useful for linking specifications but are generally avoided for explaining self-explanatory code. They start with a lowercase letter and do not end with a period, though I am not entirely happy with this convention.
Comments starting with `//!` mean TODO.
Comments starting with `//!` mean TODO. Comments starting with `//~` are meant for debugging.
## Error Handling
Adminer strictly initializes all variables before use, which is [verified](https://github.com/vrana/php-initialized). However, Adminer relies on the default value of uninitialized array items. This approach leads to more readable code. Consider the following examples:
Adminer strictly initializes all variables before use, which is [verified](/phpstan.neon). However, Adminer relies on the default value of uninitialized array items. This approach leads to more readable code. Consider the following examples:
```php
// Adminer style
@@ -110,7 +110,7 @@ function idx($array, $key, $default = null) {
}
```
Although it would be possible to use such a function in Adminer, the code would still be less readable than the current approach. Using `isset` can introduce bugs, such as in this case: `isset($rw["name"])`. Here, I intended to check if `$row` contains `name`, but a typo in the variable name is silently ignored. `empty()` is even worse and should be avoided in most cases.
Although it would be possible to use such a function in Adminer, the code would still be less readable than the current approach. Using `isset` can introduce bugs, such as in this case: `isset($rw["name"])`. Here, I intended to check if `$row` contains `name`, but a typo in the variable name is silently ignored. The same is true for `??`. `empty()` is even worse and should be avoided in most cases.
Adminer uses `@` only where an error is unavoidable, such as when writing to files. Even if you check whether a file is writable, a race condition exists between the check and the actual write operation.

View File

@@ -1,12 +1,13 @@
parameters:
level: 6
checkNullables: true # level 8
ignoreErrors:
# need to fix
- "~^Function Adminer\\\\fields_from_edit\\(\\) should return~" # Mongo and SimpleDB
- "~Adminer\\\\Result.*mysqli_result~" # mysqli_result
- "~expects array~" # different shape of array
# not real problems
- identifier: include.fileNotFound # relative includes
- identifier: includeOnce.fileNotFound # ./adminer-plugins.php
@@ -39,12 +40,13 @@ parameters:
- identifier: while.alwaysTrue
- identifier: isset.offset
- identifier: deadCode.unreachable
paths:
- adminer/
scanFiles:
- compile.php # compile_file()
excludePaths:
- adminer/adminer-plugins.php
- adminer/designs.php
- adminer/elastic.php
- adminer/sqlite.php
@@ -52,11 +54,11 @@ parameters:
- adminer/drivers/oracle.inc.php
- adminer/drivers/pgsql.inc.php
- adminer/drivers/sqlite.inc.php
phpVersion:
min: 70100
max: 80499
typeAliases:
TableStatus: "array{Name:string, Engine?:?string, Comment?:string, Oid?:numeric-string, Rows?:?numeric-string, Collation?:string, Auto_increment?:?numeric-string, Data_length?:numeric-string, Index_length?:numeric-string, Data_free?:numeric-string, Create_options?:string, nspname?:string}"
Field: "array{field:?string, full_type:string, type:string, length:numeric-string, unsigned:string, default:?string, null:bool, auto_increment:bool, collation:string, privileges:int[], comment:string, primary:bool, generated:string, orig?:string, on_update:?string, on_delete?:string, inout?:string}"