mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-06 09:02:59 +01:00
Qual: Enable detection of deprecated modulename & GETPOST(...,'int') (#28457)
* Qual: Enable detection of deprecated modulename & GETPOST(...,'int') # Qual: Enable detection of deprecated modulename & GETPOST(...,'int') Enable phan rules to verify deprecated modulename usage and GETPOST(...,'int') usage in the code. * Qual: Try type hint on to help avoid notification * Qual: Accept 3 parameters for GETPOST to GETPOSTINT conversion * Qual: Convert GETPOST(...,'int',VALUE) to GETPOSTINT(...,VALUE) # Qual: Convert GETPOST(...,'int',VALUE) to GETPOSTINT(...,VALUE) Following the update to the fixer to also convert GETPOST... with 3 parameters. The files are now converted.
This commit is contained in:
46
dev/tools/phan/PHAN.BAT
Normal file
46
dev/tools/phan/PHAN.BAT
Normal file
@@ -0,0 +1,46 @@
|
||||
@ECHO OFF
|
||||
REM Usage (use from root of project):
|
||||
REM - Standard checks:
|
||||
REM PHAN.BAT
|
||||
REM - Extended checks:
|
||||
REM PHAN.BAT extended
|
||||
REM - Use fixer configuration:
|
||||
REM PHAN.BAT fix
|
||||
REM
|
||||
REM Standard phan options can be added on the command line.
|
||||
|
||||
set MEMOPT=--memory-limit=4G
|
||||
set CONFIG=--config-file
|
||||
set CONFIG_FILE=dev/tools/phan/config.php
|
||||
set FIX=
|
||||
set USERARGS=
|
||||
SET TWICE=--analyze-twice
|
||||
|
||||
rem Iterate through each argument
|
||||
for %%i in (%*) do (
|
||||
if "%%i"=="--memory-limit" (
|
||||
set MEMOPT=""
|
||||
)
|
||||
if "%%i"=="extended" (
|
||||
set CONFIG="--config-file"
|
||||
set CONFIG_FILE=dev/tools/phan/config_extended.php
|
||||
goto :nextloop
|
||||
)
|
||||
if "%%i"=="fix" (
|
||||
set FIX="--automatic-fix"
|
||||
set CONFIG="--config-file"
|
||||
set CONFIG_FILE=dev/tools/phan/config_fixer.php
|
||||
set TWICE=
|
||||
goto :nextloop
|
||||
)
|
||||
if "%%i"=="--config-file" (
|
||||
set CONFIG=
|
||||
set CONFIG_FILE=
|
||||
)
|
||||
set "USERARGS=%USERARGS% %%i"
|
||||
|
||||
:nextloop
|
||||
REM NEXTLOOP
|
||||
)
|
||||
|
||||
../phan/vendor/bin/phan.bat %TWICE% %MEMOPT% %FIX% %CONFIG% %CONFIG_FILE% %USERARGS%
|
||||
@@ -184,6 +184,7 @@ $VALID_MODULE_MAPPING = array(
|
||||
);
|
||||
|
||||
$moduleNameRegex = '/^(?:'.implode('|', array_merge(array_keys($DEPRECATED_MODULE_MAPPING), array_keys($VALID_MODULE_MAPPING), array('\$modulename'))).')$/';
|
||||
$deprecatedModuleNameRegex = '/^(?!(?:'.implode('|', array_keys($DEPRECATED_MODULE_MAPPING)).')$).*/';
|
||||
|
||||
/**
|
||||
* This configuration will be read and overlaid on top of the
|
||||
@@ -266,12 +267,15 @@ return [
|
||||
// with the plugin's implementation (e.g. 'vendor/phan/phan/.phan/plugins/AlwaysReturnPlugin.php')
|
||||
'ParamMatchRegexPlugin' => [
|
||||
'/^GETPOST$/' => [1, $sanitizeRegex],
|
||||
'/^isModEnabled$/' => [0, $moduleNameRegex],
|
||||
'/^isModEnabled$/' => [0, $moduleNameRegex, 'UnknownModuleName'],
|
||||
// Note: trick to have different key for same regex:
|
||||
'/^isModEnable[d]$/' => [0, $deprecatedModuleNameRegex, "DeprecatedModuleName"],
|
||||
'/^sanitizeVal$/' => [1, $sanitizeRegex],
|
||||
],
|
||||
'plugins' => [
|
||||
__DIR__.'/plugins/NoVarDumpPlugin.php',
|
||||
__DIR__.'/plugins/ParamMatchRegexPlugin.php',
|
||||
__DIR__.'/plugins/GetPostFixerPlugin.php', // Only detects without --automatic-fix
|
||||
// checks if a function, closure or method unconditionally returns.
|
||||
// can also be written as 'vendor/phan/phan/.phan/plugins/AlwaysReturnPlugin.php'
|
||||
//'DeprecateAliasPlugin',
|
||||
|
||||
@@ -185,6 +185,8 @@ $VALID_MODULE_MAPPING = array(
|
||||
|
||||
$moduleNameRegex = '/^(?:'.implode('|', array_merge(array_keys($DEPRECATED_MODULE_MAPPING), array_keys($VALID_MODULE_MAPPING))).')$/';
|
||||
|
||||
$deprecatedModuleNameRegex = '/^(?!(?:'.implode('|', array_keys($DEPRECATED_MODULE_MAPPING)).')$).*/';
|
||||
|
||||
/**
|
||||
* This configuration will be read and overlaid on top of the
|
||||
* default configuration. Command line arguments will be applied
|
||||
@@ -265,12 +267,15 @@ return [
|
||||
// with the plugin's implementation (e.g. 'vendor/phan/phan/.phan/plugins/AlwaysReturnPlugin.php')
|
||||
'ParamMatchRegexPlugin' => [
|
||||
'/^GETPOST$/' => [1, $sanitizeRegex],
|
||||
'/^isModEnabled$/' => [0, $moduleNameRegex],
|
||||
'/^isModEnabled$/' => [0, $moduleNameRegex, 'UnknownModuleName'],
|
||||
// Note: trick to have different key for same regex:
|
||||
'/^isModEnable[d]$/' => [0, $deprecatedModuleNameRegex, "DeprecatedModuleName"],
|
||||
'/^sanitizeVal$/' => [1, $sanitizeRegex],
|
||||
],
|
||||
'plugins' => [
|
||||
__DIR__.'/plugins/NoVarDumpPlugin.php',
|
||||
__DIR__.'/plugins/ParamMatchRegexPlugin.php',
|
||||
__DIR__.'/plugins/GetPostFixerPlugin.php', // Only detects without --automatic-fix
|
||||
'DeprecateAliasPlugin',
|
||||
//'EmptyMethodAndFunctionPlugin',
|
||||
'InvalidVariableIssetPlugin',
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/plugins/DeprecatedModuleNameFixer.php';
|
||||
|
||||
/* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
*/
|
||||
define('DOL_PROJECT_ROOT', __DIR__.'/../../..');
|
||||
|
||||
@@ -46,7 +46,7 @@ call_user_func(static function (): void {
|
||||
continue;
|
||||
}
|
||||
$arguments = $node->children;
|
||||
if (count($arguments) != 3) {
|
||||
if (!in_array(count($arguments), [3, 5])) { // ',' included !
|
||||
print "Arg Count is ".count($arguments)." - Skip $instance".PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user