10
Sometimes I have very large functions, that I feel are very difficult to "compress" or separate into smaller functions, because the functions wouldn't be used in any other part of the script.
So, I'd like some advice on it: should I create functions that wouldn't be used in other parts of the script, or should I create them only if they will be used more than once?
Thanks!
Summary:
- Fills arrays with info of files in directories.
- Processes TXT line by line, looks if the ID in TXT matches "Completed" files array and publishes it in an external product. If it doesn't, checks in the other arrays to make a report of what is missing.
- Saves the errors found in an array, then saves the array to an errors.txt
- file. Finally, returns the report.
Currently my function is:
protected function processScanned()
{
try
{
// EJECUTAR BASH DE NAHUEL
//
//
$PdfCPList = $this->model->getDirFilenames( $this->model->dirCartasPorte, 'pdf' );
$PdfTBList = $this->model->getDirFilenames( $this->model->dirTicketsBalanza, 'pdf' );
$PdfCompList = $this->model->getDirFilenames( $this->model->dirCompletos, 'pdf' );
$PdfUnreconList = $this->model->getDirFilenames( $this->model->dirSinReconocer,'pdf' );
// Adjuntar Novedades
$newsToProcess = $this->model->getDirFilenames( $this->model->dirNovedades, 'txt', true);
$this->appendNewsFiles($newsToProcess);
$report = array();
$report['info'] = array(
'Documentos procesados correctamente'=>0,
'Fecha de última actualización de datos'=>date('d/m/Y H:i:s',(int)file_get_contents($this->model->uriTxtInfo)),
);
if($file = fopen( $this->model->uriTxtProcesar, 'r' ) )
{
$i = 0;
$errors_file = fopen($this->model->uriTxtErrores,'w');
while( $line = fgets