Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qual: Improve write_file typing (part 2) #30527

Merged
merged 8 commits into from
Nov 13, 2024
9 changes: 5 additions & 4 deletions htdocs/core/class/commonstickergenerator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ public function __construct($db)
/**
* Function to build PDF on disk, then output on HTTP stream.
*
* @param array<string,mixed> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Adherent|array<array{textleft:string,textheader:string,textfooter:string,textright:string,id:string,photo:string}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param string $outputdir Output directory for pdf file
* @return int 1=OK, 0=KO
* @param string $outputdir Output directory for pdf file
* @param string $filename Short file name of output file
* @return int<-1,1> 1=OK, <=0=KO
*/
abstract public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '');
abstract public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = '');
// phpcs:enable

/**
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/cheque/doc/pdf_blochet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function __construct($db)
* @param string $_dir Directory
* @param string $number Number
* @param Translate $outputlangs Lang output object
* @return int 1=ok, 0=ko
* @return int<-1,1> 1 if OK, <=0 if KO
*/
public function write_file($object, $_dir, $number, $outputlangs)
{
Expand Down
5 changes: 4 additions & 1 deletion htdocs/core/modules/cheque/modules_chequereceipts.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public static function liste_modeles($db, $maxfilenamelength = 0)

return $list;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Fonction to generate document on disk
Expand Down Expand Up @@ -167,7 +169,8 @@ function chequereceipt_pdf_create($db, $id, $message, $modele, $outputlangs)
// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output = $outputlangs->charset_output;
if ($obj->write_file($id, $outputlangs) > 0) {
// TODO: write_file seems invalid, function is likely no longer used - delete ?
if ($obj->write_file($id, $outputlangs) > 0) { // @phan-suppress-current-line PhanParamTooFew,PhanPluginSuspiciousParamPosition
$outputlangs->charset_output = $sav_charset_output;
return 1;
} else {
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/modules/dons/html_cerfafr.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public function isEnabled()
/**
* Write the object to document file to disk
*
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param string $currency Currency code
* @return int >0 if OK, <0 if KO
* @return int<-1,1> >0 if OK, <0 if KO
*/
public function write_file($don, $outputlangs, $currency = '')
{
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/modules/dons/html_generic.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ private function saveFile($path, $contents)
/**
* Write the object to document file to disk
*
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param string $currency Currency code
* @return int >0 if OK, <0 if KO
* @return int<-1,1> >0 if OK, <0 if KO
*/
public function write_file($don, $outputlangs, $currency = '')
{
Expand Down
11 changes: 11 additions & 0 deletions htdocs/core/modules/dons/modules_don.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public static function liste_modeles($db, $maxfilenamelength = 0)

return $list;
}

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Write the object to document file to disk
*
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param string $currency Currency code
* @return int<-1,1> >0 if OK, <0 if KO
*/
abstract public function write_file($don, $outputlangs, $currency = '');
}


Expand Down
18 changes: 9 additions & 9 deletions htdocs/core/modules/member/doc/pdf_standard_member.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,17 @@ public function Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build PDF on disk, then output on HTTP stream.
* Function to build PDF on disk, then output on HTTP stream.
*
* @param Adherent|array $object Member object. Old usage: Array of record information (array('textleft'=>,'textheader'=>, ...'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file. Example: '5161', 'AVERYC32010', 'CARD', ...
* @param string $mode Tell if doc module is called for 'member', ...
* @param int $nooutput 1=Generate only file on disk and do not return it on response
* @param string $filename Name of output file (without extension)
* @return int 1=OK, 0=KO
* @param Adherent|array<array{textleft:string,textheader:string,textfooter:string,textright:string,id:string,photo:string}> $object Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath file. Example: '5161', 'AVERYC32010', 'CARD', ...
* @param string $mode Tell if doc module is called
* @param string $nooutput 1=Generate only file on disk and do not return it on response // TODO: Fix not compatible parameter signature.
* @param string $filename Name of output file (without extension)
* @return int<-1,1> 1=OK, <=0=KO
*/
public function write_file($object, $outputlangs, $srctemplatepath, $mode = 'member', $nooutput = 0, $filename = 'tmp_cards')
public function write_file($object, $outputlangs, $srctemplatepath, $mode = 'member', $nooutput = '', $filename = 'tmp_cards')
{
// phpcs:enable
global $user, $conf, $langs, $mysoc, $_Avery_Labels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ public function Add_PDF_label(&$pdf, $textleft, $header, $footer, $outputlangs,
/**
* Function to build PDF on disk, then output on HTTP stream.
*
* @param array<array{textleft:string,textheader:string,textfooter:string,textright:string,photo:string}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param array<array{textleft:string,textheader:string,textfooter:string,textright:string,id:string,photo:string}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param string $outputdir Output directory for pdf file
* @param string $filename Short file name of PDF output file
* @return int 1=OK, 0=KO
* @return int<-1,1> 1=OK, <=0=KO
*/
public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = 'tmp_address_sheet.pdf')
{
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ public function addSticker(&$pdf, $outputlangs, $param)

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build PDF on disk, then output on HTTP stream.
* Function to build PDF on disk, then output on HTTP stream.
*
* @param Adherent|array<array{textleft:string,textheader:string,textfooter:string,textright:string,code:string,encoding:string,is2d:int<0,1>|bool}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param string $outputdir Output directory for pdf file
* @param string $filename Short file name of PDF output file
* @return int 1=OK, 0=KO
* @return int<-1,1> 1=OK, <=0=KO
*/
public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = 'tmp_address_sheet.pdf')
{
Expand Down
5 changes: 3 additions & 2 deletions htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,18 @@ public function __construct(DoliDB $db)
}
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build pdf onto disk
*
* @param StockTransfer $object Object StockTransfer to generate (or id if old method)
* @param Translate $outputlangs Lang output object
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1=OK, 0=KO
* @return int<-1,1> 1 if OK, <=0 if KO
*/
public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
Expand Down
12 changes: 7 additions & 5 deletions htdocs/don/class/don.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,14 +1019,14 @@ public function info($id)


/**
* Create a document onto disk according to template module.
* Create a document on disk according to template module.
*
* @param string $modele Force template to use ('' to not force)
* @param Translate $outputlangs object lang a utiliser pour traduction
* @param int $hidedetails Hide details of lines
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
* @param int<0,1> $hidedetails Hide details of lines
* @param int<0,1> $hidedesc Hide description
* @param int<0,1> $hideref Hide ref
* @return int<-1,1> 0 if KO, 1 if OK
*/
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
Expand Down Expand Up @@ -1098,6 +1098,8 @@ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hided
$classname = $modele;
$obj = new $classname($this->db);

'@phan-var-force ModeleDon $obj';

// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output = $outputlangs->charset_output;
Expand Down
2 changes: 2 additions & 0 deletions htdocs/recruitment/admin/setup_candidatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@

$module = new $classname($db);

'@phan-var-force ModelePDFRecruitmentCandidature $module';

if ($module->write_file($tmpobject, $langs) > 0) {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public static function liste_modeles($db, $maxfilenamelength = 0)

return $list;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build a document on disk using the generic odt module.
*
* @param RecruitmentCandidature $object Object source to build document
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1 if OK, <=0 if KO
*/
abstract public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
// phpcs:enable
}


Expand Down
Loading