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 |
||
| 14 | class AutomatedEditsHelper extends HelperBase |
||
| 15 | { |
||
| 16 | |||
| 17 | /** @var string[] The list of tools that are considered reverting. */ |
||
| 18 | public $revertTools = [ |
||
| 19 | 'Generic rollback', |
||
| 20 | 'Undo', |
||
| 21 | 'Pending changes revert', |
||
| 22 | 'Huggle', |
||
| 23 | 'STiki', |
||
| 24 | 'Igloo', |
||
| 25 | 'WikiPatroller', |
||
| 26 | 'Twinkle revert', |
||
| 27 | 'Bot revert' |
||
| 28 | ]; |
||
| 29 | |||
| 30 | /** @var string[] The list of tool names and their regexes. */ |
||
| 31 | protected $tools; |
||
| 32 | |||
| 33 | public function __construct(ContainerInterface $container) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Was the edit (semi-)automated, based on the edit summary? |
||
| 40 | * @param string $summary Edit summary |
||
| 41 | * @return boolean Yes or no |
||
| 42 | */ |
||
| 43 | View Code Duplication | public function isAutomated($summary) |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Was the edit a revert, based on the edit summary? |
||
| 56 | * @param string $summary Edit summary |
||
| 57 | * @return boolean Yes or no |
||
| 58 | */ |
||
| 59 | View Code Duplication | public function isRevert($summary) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Get the name of the tool that matched the given edit summary |
||
| 74 | * @param string $summary Edit summary |
||
| 75 | * @return string|boolean Name of tool, or false if nothing was found |
||
| 76 | */ |
||
| 77 | View Code Duplication | public function getTool($summary) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Get the list of automated tools |
||
| 90 | * @return array Associative array of 'tool name' => 'regex' |
||
| 91 | */ |
||
| 92 | public function getTools() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Get a list of nonautomated edits by a user |
||
| 103 | * @param string $project Project domain such as en.wikipedia.org |
||
| 104 | * @param string $username |
||
| 105 | * @param string|integer $namespace Numerical value or 'all' for all namespaces |
||
| 106 | * @param integer $offset Used for pagination, offset results by N edits |
||
| 107 | * @return string[] Data as returned by database query, includes: |
||
| 108 | * 'page_title' (string, including namespace), |
||
| 109 | * 'namespace' (integer), 'rev_id' (int), |
||
| 110 | * 'timestamp' (DateTime), 'minor_edit' (bool) |
||
| 111 | * 'sumamry' (string) |
||
| 112 | */ |
||
| 113 | public function getNonautomatedEdits($project, $username, $namespace, $offset = 0) |
||
| 182 | } |
||
| 183 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.