Skip to content

Commit

Permalink
Improve phpdoc typing
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Mar 30, 2024
1 parent f272425 commit ba460e5
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions htdocs/core/lib/modulebuilder.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
* @param string $objectname Name of object
* @param string $newmask New mask
* @param string $readdir Directory source (use $destdir when not defined)
* @param array $addfieldentry Array of 1 field entry to add array('key'=>,'type'=>,''label'=>,'visible'=>,'enabled'=>,'position'=>,'notnull'=>','index'=>,'searchall'=>,'comment'=>,'help'=>,'isameasure')
* @param array{key:string,type:string,label:string,picot?:string,enabled:int<0,1>,notnull:int<0,1>,position:int,visible:int,noteditable?:int<0,1>,alwayseditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int<0,1>,css?:string,cssview?:string,csslist?:string,help?:string,showoncombobox?:int<0,1>,disabled?:int<0,1>,autofocusoncreate?:int<0,1>,arrayofkeyval?:array<string,string>,validate?:int<0,1>,comment?:string} $addfieldentry Array of 1 field entry to add
* @param string $delfieldentry Id of field to remove
* @return int|object Return integer <=0 if KO, Object if OK
* @return int<-7,-1>|CommonObject Return integer <=0 if KO, Object if OK
* @see rebuildObjectSql()
*/
function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = '', $addfieldentry = array(), $delfieldentry = '')

Check warning on line 39 in htdocs/core/lib/modulebuilder.lib.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modulebuilder.lib.php: PhanTypeMismatchDefault: Default value for array{key:string,type:string,label:string,picot?:string,enabled:int,notnull:int,position:int,visible:int,noteditable?:int,alwayseditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,cssview?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,autofocusoncreate?:int,arrayofkeyval?:array&lt;string,string&gt;,validate?:int,comment?:string} $addfieldentry can't be array{}
Expand Down Expand Up @@ -89,6 +89,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
} else {
return -4;
}
'@phan-var-force CommonObject $object';

// Backup old file
dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.'.back', $newmask, 1);
Expand Down Expand Up @@ -549,11 +550,11 @@ function compareFirstValue($a, $b)
* @param string $file filename or path
* @param array<int,string[]> $permissions permissions existing in file
* @param int|null $key key for permission needed
* @param array|null $right $right to update or add
* @param array{0:string,1:string}|null $right $right to update or add
* @param string|null $objectname name of object
* @param string|null $module name of module
* @param int<-2,2> $action 0 for delete, 1 for add, 2 for update, -1 when delete object completely, -2 for generate rights after add
* @return int 1 if OK,-1 if KO
* @return int<-1,1> 1 if OK,-1 if KO
*/
function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $module, $action)
{
Expand Down Expand Up @@ -672,7 +673,7 @@ function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $
* Converts a formatted properties string into an associative array.
*
* @param string $string The formatted properties string.
* @return array The resulting associative array.
* @return array<string,bool|int|float|string|mixed[]> The resulting associative array.
*/
function parsePropertyString($string)
{
Expand Down Expand Up @@ -874,7 +875,7 @@ function getFromFile($file, $start, $end)
* Write all permissions of each object in AsciiDoc format
* @param string $file path of the class
* @param string $destfile file where write table of permissions
* @return int 1 if OK, -1 if KO
* @return int<-1,1> 1 if OK, -1 if KO
*/
function writePermsInAsciiDoc($file, $destfile)
{
Expand Down Expand Up @@ -959,9 +960,9 @@ function writePermsInAsciiDoc($file, $destfile)
*
* @param string $srcfile Source file to use as example
* @param string $file Path of modified file
* @param array $objects Array of objects in the module
* @param string[] $objects Array of objects in the module
* @param string $modulename Name of module
* @return int Return 1 if OK, -1 if KO
* @return int<-1,1> Return 1 if OK, -1 if KO
*/
function addObjectsToApiFile($srcfile, $file, $objects, $modulename)
{
Expand Down Expand Up @@ -1044,9 +1045,9 @@ function addObjectsToApiFile($srcfile, $file, $objects, $modulename)
* Remove Object variables and methods from API_Module File
*
* @param string $file File api module
* @param array $objects Array of objects in the module
* @param string[] $objects Array of objects in the module
* @param string $objectname Name of object want to remove
* @return int 1 if OK, -1 if KO
* @return int<-1,1> 1 if OK, -1 if KO
*/
function removeObjectFromApiFile($file, $objects, $objectname)
{
Expand Down Expand Up @@ -1091,12 +1092,12 @@ function removeObjectFromApiFile($file, $objects, $objectname)


/**
* @param string $file path of filename
* @param mixed $menus all menus for module
* @param mixed|null $menuWantTo menu get for do actions
* @param int|null $key key for the concerned menu
* @param int $action for specify what action (0 = delete, 1 = add, 2 = update, -1 = when delete object)
* @return int 1 if OK, -1 if KO
* @param string $file path of filename
* @param array<int,array{fk_menu:string,type:string,titre:string,mainmenu:string,leftmenu:string,url:string,langs:string,position:int,enabled:int,perms:string,target:string,user:int}> $menus all menus for module
* @param mixed|null $menuWantTo menu get for do actions
* @param int|null $key key for the concerned menu
* @param int<-1,2> $action for specify what action (0 = delete, 1 = add, 2 = update, -1 = when delete object)
* @return int<-1,1> 1 if OK, -1 if KO
*/
function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
{
Expand Down Expand Up @@ -1194,7 +1195,7 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
*
* @param string $module The name of the module.
* @param string $file The path to the module descriptor file.
* @param array $dicts The dictionary data to be updated.
* @param array<string,string|array<string,int|string>> $dicts The dictionary data to be updated.
* @return int Returns the number of replacements made in the file.
*/
function updateDictionaryInFile($module, $file, $dicts)
Expand Down Expand Up @@ -1267,8 +1268,8 @@ static function ($val) {
* @param string $modulename The lowercase name of the module for which the dictionary table is being created.
* @param string $file The file path to the Dolibarr module builder file where the dictionaries are defined.
* @param string $namedic The name of the dictionary, which will also be used as the base for the table name.
* @param array|null $dictionnaires An optional array containing pre-existing dictionary data, including 'tabname', 'tablib', 'tabsql', etc.
* @return int|void Return int < 0 if error, return nothing on success
* @param array<string,string|array<string,int|string>> $dictionnaires An optional array containing pre-existing dictionary data, including 'tabname', 'tablib', 'tabsql', etc.
* @return int<-1,-1>|void Return int < 0 if error, return nothing on success
*/
function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = null)
{
Expand All @@ -1289,10 +1290,10 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul

$columns = array(
'rowid' => array('type' => 'integer', 'value' => 11, 'extra' => 'AUTO_INCREMENT'),
'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'),
'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'),
'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'),
'use_default' => array('type' => 'varchar', 'value' => 11, 'default'=>'1'),
'code' => array('type' => 'varchar', 'value' => 255, 'null' => 'NOT NULL'),
'label' => array('type' => 'varchar', 'value' => 255, 'null' => 'NOT NULL'),
'position' => array('type' => 'integer', 'value' => 11, 'null' => 'NULL'),
'use_default' => array('type' => 'varchar', 'value' => 11, 'default' => '1'),
'active' => array('type' => 'integer', 'value' => 3)
);

Expand Down Expand Up @@ -1348,7 +1349,7 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul
*
* @param string $file_api filename or path of api
* @param string $file_doc filename or path of documentation
* @return int -1 if KO, 1 if OK, 0 if nothing change
* @return int<-1,1> -1 if KO, 1 if OK, 0 if nothing change
*/
function writeApiUrlsInDoc($file_api, $file_doc)
{
Expand Down

0 comments on commit ba460e5

Please sign in to comment.