diff options
author | jld3103 <jld3103yt@gmail.com> | 2023-03-31 17:19:12 +0200 |
---|---|---|
committer | jld3103 <jld3103yt@gmail.com> | 2023-04-05 07:07:53 +0200 |
commit | e7926b964441b8b6d6ffc6a656896bc0276e9cc3 (patch) | |
tree | 4411695614d3224931abc3a07d03e7f05c93f803 /build/psalm | |
parent | 14283001a5894ca1816069aa53387fb08cccc43b (diff) | |
download | nextcloud-server-e7926b964441b8b6d6ffc6a656896bc0276e9cc3.tar.gz nextcloud-server-e7926b964441b8b6d6ffc6a656896bc0276e9cc3.zip |
Refactor AppFrameworkTainter to make it more readable
Signed-off-by: jld3103 <jld3103yt@gmail.com>
Diffstat (limited to 'build/psalm')
-rw-r--r-- | build/psalm/AppFrameworkTainter.php | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/build/psalm/AppFrameworkTainter.php b/build/psalm/AppFrameworkTainter.php index 15023da8d58..9a68885b175 100644 --- a/build/psalm/AppFrameworkTainter.php +++ b/build/psalm/AppFrameworkTainter.php @@ -22,6 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + use Psalm\CodeLocation; use Psalm\Plugin\EventHandler\AfterFunctionLikeAnalysisInterface; use Psalm\Plugin\EventHandler\Event\AfterFunctionLikeAnalysisEvent; @@ -29,27 +30,29 @@ use Psalm\Type\TaintKindGroup; class AppFrameworkTainter implements AfterFunctionLikeAnalysisInterface { public static function afterStatementAnalysis(AfterFunctionLikeAnalysisEvent $event): ?bool { - if ($event->getStatementsSource()->getFQCLN() !== null) { - if ($event->getCodebase()->classExtendsOrImplements($event->getStatementsSource()->getFQCLN(), \OCP\AppFramework\Controller::class)) { - if ($event->getStmt() instanceof PhpParser\Node\Stmt\ClassMethod) { - if ($event->getStmt()->isPublic() && !$event->getStmt()->isMagic()) { - foreach ($event->getStmt()->params as $i => $param) { - $expr_type = new Psalm\Type\Union([new Psalm\Type\Atomic\TString()]); - $expr_identifier = (strtolower($event->getStatementsSource()->getFQCLN()) . '::' . strtolower($event->getFunctionlikeStorage()->cased_name) . '#' . ($i + 1)); - - if ($expr_type) { - $event->getCodebase()->addTaintSource( - $expr_type, - $expr_identifier, - TaintKindGroup::ALL_INPUT, - new CodeLocation($event->getStatementsSource(), $param) - ); - } - } - } - } - } + if ($event->getStatementsSource()->getFQCLN() === null) { + return null; + } + if (!$event->getCodebase()->classExtendsOrImplements($event->getStatementsSource()->getFQCLN(), \OCP\AppFramework\Controller::class)) { + return null; + } + if (!($event->getStmt() instanceof PhpParser\Node\Stmt\ClassMethod)) { + return null; } + if (!$event->getStmt()->isPublic() || $event->getStmt()->isMagic()) { + return null; + } + foreach ($event->getStmt()->params as $i => $param) { + $expr_type = new Psalm\Type\Union([new Psalm\Type\Atomic\TString()]); + $expr_identifier = (strtolower($event->getStatementsSource()->getFQCLN()) . '::' . strtolower($event->getFunctionlikeStorage()->cased_name) . '#' . ($i + 1)); + $event->getCodebase()->addTaintSource( + $expr_type, + $expr_identifier, + TaintKindGroup::ALL_INPUT, + new CodeLocation($event->getStatementsSource(), $param) + ); + } + return null; } } |