| Conditions | 10 |
| Paths | 8 |
| Total Lines | 77 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php namespace XoopsModules\Tdmcreate\Files\User; |
||
| 114 | public function getUserPdfTcpdf($moduleDirname, $fields) |
||
| 115 | { |
||
| 116 | $fieldId = $this->xc->getXcSaveFieldId($fields); |
||
| 117 | $stuModuleDirname = mb_strtoupper($moduleDirname); |
||
| 118 | $ret = ''; |
||
| 119 | foreach (array_keys($fields) as $f) { |
||
| 120 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 121 | $fieldDefault = $fields[$f]->getVar('field_default'); |
||
| 122 | $fieldElement = $fields[$f]->getVar('field_element'); |
||
| 123 | $getVar = $this->xc->getXcGetVar('', 'pdfContent', $fieldName, true); |
||
| 124 | switch ($fieldElement) { |
||
| 125 | case 2: |
||
| 126 | if (false !== mb_strpos($fieldName, 'title') || false !== mb_strpos($fieldName, 'name') && '' == $fieldDefault) { |
||
| 127 | $ret .= $this->phpcode->getPhpCodeStripTags("pdfData['title']", $getVar); |
||
| 128 | } |
||
| 129 | break; |
||
| 130 | case 3: |
||
| 131 | case 4: |
||
| 132 | $ret .= $this->phpcode->getPhpCodeStripTags("pdfData['content']", $getVar); |
||
| 133 | break; |
||
| 134 | case 8: |
||
| 135 | $ret .= $this->xc->getXcUnameFromId("pdfData['author']", $getVar); |
||
| 136 | break; |
||
| 137 | case 15: |
||
| 138 | $ret .= $this->xc->getXcFormatTimeStamp("pdfData['date']", $getVar); |
||
| 139 | break; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | $ret .= $this->phpcode->getPhpCodeCommentLine('Get Config'); |
||
| 143 | $ret .= $this->xc->getXcEqualsOperator("\$pdfData['creator'] ", "\$GLOBALS['xoopsConfig']['xoops_sitename']"); |
||
| 144 | $ret .= $this->xc->getXcEqualsOperator("\$pdfData['subject'] ", "\$GLOBALS['xoopsConfig']['slogan']"); |
||
| 145 | $ret .= $this->xc->getXcEqualsOperator("\$pdfData['keywords'] ", "\$GLOBALS['xoopsConfig']['keywords']"); |
||
| 146 | $ret .= $this->phpcode->getPhpCodeCommentLine('Defines'); |
||
| 147 | $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_CREATOR", "\$pdfData['creator']"); |
||
| 148 | $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_AUTHOR", "\$pdfData['author']"); |
||
| 149 | $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_TITLE", "\$pdfData['title']"); |
||
| 150 | $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_STRING", "\$pdfData['subject']"); |
||
| 151 | $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_LOGO", "'logo.gif'"); |
||
| 152 | $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_IMAGES_PATH", "XOOPS_ROOT_PATH.'/images/'"); |
||
| 153 | $ret .= $this->xc->getXcEqualsOperator('$myts', 'MyTextSanitizer::getInstance()', null, true); |
||
| 154 | $ret .= $this->xc->getXcEqualsOperator('$content', "''"); |
||
| 155 | $ret .= $this->xc->getXcEqualsOperator('$content', "\$myts->undoHtmlSpecialChars(\$pdfData['content'])", '.'); |
||
| 156 | $ret .= $this->xc->getXcEqualsOperator('$content', '$myts->displayTarea($content)'); |
||
| 157 | $ret .= $this->xc->getXcEqualsOperator('$pdf', 'new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false)'); |
||
| 158 | $ret .= $this->xc->getXcEqualsOperator('$title', "\$myts->undoHtmlSpecialChars(\$pdfData['title'])"); |
||
| 159 | $ret .= $this->xc->getXcEqualsOperator('$keywords', "\$myts->undoHtmlSpecialChars(\$pdfData['keywords'])"); |
||
| 160 | $ret .= $this->xc->getXcEqualsOperator("\$pdfData['fontsize']", '12'); |
||
| 161 | $ret .= $this->phpcode->getPhpCodeCommentLine('For schinese'); |
||
| 162 | $ifLang = $this->getSimpleString("\$pdf->SetFont('gbsn00lp', '', \$pdfData['fontsize']);", "\t"); |
||
| 163 | $elseLang = $this->getSimpleString("\$pdf->SetFont(\$pdfData['fontname'], '', \$pdfData['fontsize']);", "\t"); |
||
| 164 | $ret .= $this->phpcode->getPhpCodeConditions('_LANGCODE', ' == ', "'cn'", $ifLang, $elseLang); |
||
| 165 | $ret .= $this->phpcode->getPhpCodeCommentLine('Set document information'); |
||
| 166 | $ret .= $this->getSimpleString("\$pdf->SetCreator(\$pdfData['creator']);"); |
||
| 167 | $ret .= $this->getSimpleString("\$pdf->SetAuthor(\$pdfData['author']);"); |
||
| 168 | $ret .= $this->getSimpleString('$pdf->SetTitle($title);'); |
||
| 169 | $ret .= $this->getSimpleString('$pdf->SetKeywords($keywords);'); |
||
| 170 | $ret .= $this->phpcode->getPhpCodeCommentLine('Set default header data'); |
||
| 171 | $ret .= $this->getSimpleString("\$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, {$stuModuleDirname}_HEADER_TITLE, {$stuModuleDirname}_HEADER_STRING);"); |
||
| 172 | $ret .= $this->phpcode->getPhpCodeCommentLine('Set margins'); |
||
| 173 | $ret .= $this->getSimpleString('$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP + 10, PDF_MARGIN_RIGHT);'); |
||
| 174 | $ret .= $this->phpcode->getPhpCodeCommentLine('Set auto page breaks'); |
||
| 175 | $ret .= $this->getSimpleString('$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);'); |
||
| 176 | $ret .= $this->getSimpleString('$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);'); |
||
| 177 | $ret .= $this->getSimpleString('$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);'); |
||
| 178 | $ret .= $this->getSimpleString('$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor'); |
||
| 179 | $ifLang = $this->getSimpleString("\$pdf->setHeaderFont(array('gbsn00lp', '', \$pdfData['fontsize']));", "\t"); |
||
| 180 | $ifLang .= $this->getSimpleString("\$pdf->setFooterFont(array('gbsn00lp', '', \$pdfData['fontsize']));", "\t"); |
||
| 181 | $elseLang = $this->getSimpleString("\$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));", "\t"); |
||
| 182 | $elseLang .= $this->getSimpleString("\$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));", "\t"); |
||
| 183 | $ret .= $this->phpcode->getPhpCodeConditions('_LANGCODE', ' == ', "'cn'", $ifLang, $elseLang); |
||
| 184 | $ret .= $this->phpcode->getPhpCodeCommentLine('Set some language-dependent strings (optional)'); |
||
| 185 | $fileExist = $this->phpcode->getPhpCodeFileExists("\$lang = XOOPS_ROOT_PATH.'/Frameworks/tcpdf/lang/eng.php'"); |
||
| 186 | $contIf = $this->phpcode->getPhpCodeIncludeDir('$lang', '', true, false, 'require', "\t"); |
||
| 187 | $contIf .= $this->getSimpleString('$pdf->setLanguageArray($l);', "\t"); |
||
| 188 | $ret .= $this->phpcode->getPhpCodeConditions("@{$fileExist}", '', '', $contIf); |
||
| 189 | |||
| 190 | return $ret; |
||
| 191 | } |
||
| 242 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..