Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 23 | abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin { |
||
| 24 | public $extKey = 'dlf'; |
||
| 25 | public $prefixId = 'tx_dlf'; |
||
| 26 | public $scriptRelPath = 'Classes/Common/AbstractPlugin.php'; |
||
| 27 | // Plugins are cached by default (@see setCache()). |
||
| 28 | public $pi_USER_INT_obj = FALSE; |
||
| 29 | public $pi_checkCHash = TRUE; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * This holds the current document |
||
| 33 | * |
||
| 34 | * @var \Kitodo\Dlf\Common\Document |
||
| 35 | * @access protected |
||
| 36 | */ |
||
| 37 | protected $doc; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * This holds the plugin's parsed template |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | * @access protected |
||
| 44 | */ |
||
| 45 | protected $template = ''; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Read and parse the template file |
||
| 49 | * |
||
| 50 | * @access protected |
||
| 51 | * |
||
| 52 | * @param string $part: Name of the subpart to load |
||
|
|
|||
| 53 | * |
||
| 54 | * @return void |
||
| 55 | */ |
||
| 56 | protected function getTemplate($part = '###TEMPLATE###') { |
||
| 65 | |||
| 66 | /** |
||
| 67 | * All the needed configuration values are stored in class variables |
||
| 68 | * Priority: Flexforms > TS-Templates > Extension Configuration > ext_localconf.php |
||
| 69 | * |
||
| 70 | * @access protected |
||
| 71 | * |
||
| 72 | * @param array $conf: configuration array from TS-Template |
||
| 73 | * |
||
| 74 | * @return void |
||
| 75 | */ |
||
| 76 | protected function init(array $conf) { |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Loads the current document into $this->doc |
||
| 112 | * |
||
| 113 | * @access protected |
||
| 114 | * |
||
| 115 | * @return void |
||
| 116 | */ |
||
| 117 | protected function loadDocument() { |
||
| 158 | |||
| 159 | /** |
||
| 160 | * The main method of the PlugIn |
||
| 161 | * |
||
| 162 | * @access public |
||
| 163 | * |
||
| 164 | * @param string $content: The PlugIn content |
||
| 165 | * @param array $conf: The PlugIn configuration |
||
| 166 | * |
||
| 167 | * @abstract |
||
| 168 | * |
||
| 169 | * @return string The content that is displayed on the website |
||
| 170 | */ |
||
| 171 | abstract public function main($content, $conf); |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Wraps the input string in a tag with the class attribute set to the class name |
||
| 175 | * |
||
| 176 | * @access public |
||
| 177 | * |
||
| 178 | * @param string $content: HTML content to wrap in the div-tags with the class of the plugin |
||
| 179 | * |
||
| 180 | * @return string HTML content wrapped, ready to return to the parent object. |
||
| 181 | */ |
||
| 182 | public function pi_wrapInBaseClass($content) { |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Parses a string into a Typoscript array |
||
| 195 | * |
||
| 196 | * @access protected |
||
| 197 | * |
||
| 198 | * @param string $string: The string to parse |
||
| 199 | * |
||
| 200 | * @return array The resulting typoscript array |
||
| 201 | */ |
||
| 202 | protected function parseTS($string = '') { |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Sets some configuration variables if the plugin is cached. |
||
| 210 | * |
||
| 211 | * @access protected |
||
| 212 | * |
||
| 213 | * @param boolean $cache: Should the plugin be cached? |
||
| 214 | * |
||
| 215 | * @return void |
||
| 216 | */ |
||
| 217 | protected function setCache($cache = TRUE) { |
||
| 234 | } |
||
| 235 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.