Fixed phpstan issues

This commit is contained in:
Jan Böhmer 2026-03-07 22:30:39 +01:00
parent bcbbb1ecb9
commit 7f8f5990a7
5 changed files with 100 additions and 5 deletions

View file

@ -177,6 +177,11 @@
"allow-contrib": false, "allow-contrib": false,
"require": "7.4.*", "require": "7.4.*",
"docker": true "docker": true
},
"phpstan/extension-installer": {
"ignore" : [
"ekino/phpstan-banned-code"
]
} }
} }
} }

2
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "32c5677a31185e0ed124904012500154", "content-hash": "8fd737684b48f8d24fcad35fce37a297",
"packages": [ "packages": [
{ {
"name": "amphp/amp", "name": "amphp/amp",

86
phpstan.banned_code.neon Normal file
View file

@ -0,0 +1,86 @@
# Manually configure ekino/phpstan-banned-code to detect usage of echo, eval, die/exit, print, shell execution and a set of functions that should not be used in production code.
parametersSchema:
banned_code: structure([
nodes: listOf(structure([
type: string()
functions: schema(listOf(string()), nullable())
]))
use_from_tests: bool()
non_ignorable: bool()
])
parameters:
banned_code:
nodes:
# enable detection of echo
-
type: Stmt_Echo
functions: null
# enable detection of eval
-
type: Expr_Eval
functions: null
# enable detection of die/exit
-
type: Expr_Exit
functions: null
# enable detection of a set of functions
-
type: Expr_FuncCall
functions:
- dd
- debug_backtrace
- dump
- exec
- passthru
- phpinfo
- print_r
- proc_open
- shell_exec
- system
- var_dump
# enable detection of print statements
-
type: Expr_Print
functions: null
# enable detection of shell execution by backticks
-
type: Expr_ShellExec
functions: null
# enable detection of empty()
#-
# type: Expr_Empty
# functions: null
# enable detection of `use Tests\Foo\Bar` in a non-test file
use_from_tests: true
# when true, errors cannot be excluded
non_ignorable: false
services:
-
class: Ekino\PHPStanBannedCode\Rules\BannedNodesRule
tags:
- phpstan.rules.rule
arguments:
- '%banned_code.nodes%'
-
class: Ekino\PHPStanBannedCode\Rules\BannedUseTestRule
tags:
- phpstan.rules.rule
arguments:
- '%banned_code.use_from_tests%'
-
class: Ekino\PHPStanBannedCode\Rules\BannedNodesErrorBuilder
arguments:
- '%banned_code.non_ignorable%'

View file

@ -1,3 +1,6 @@
includes:
- phpstan.banned_code.neon
parameters: parameters:
level: 5 level: 5
@ -6,9 +9,6 @@ parameters:
- src - src
# - tests # - tests
banned_code:
non_ignorable: false # Allow to ignore some banned code
excludePaths: excludePaths:
- src/DataTables/Adapter/* - src/DataTables/Adapter/*
- src/Configuration/* - src/Configuration/*

View file

@ -325,7 +325,11 @@ class EntityImporter
//Iterate over each $entity write it to DB (the invalid entities were already filtered out). //Iterate over each $entity write it to DB (the invalid entities were already filtered out).
foreach ($entities as $entity) { foreach ($entities as $entity) {
$this->persistRecursively($entity); if ($entity instanceof AbstractStructuralDBElement) {
$this->persistRecursively($entity);
} else {
$this->em->persist($entity);
}
} }
//Save changes to database, when no error happened, or we should continue on error. //Save changes to database, when no error happened, or we should continue on error.