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 |
||
11 | class InverseDocumentFrequency |
||
12 | { |
||
13 | /** |
||
14 | * @var \PDO |
||
15 | */ |
||
16 | protected $dbHandle; |
||
17 | protected $documentCount; |
||
18 | |||
19 | /** |
||
20 | * InverseDocumentFrequency constructor. |
||
21 | * |
||
22 | * @param resource $dbHandle |
||
23 | * @param int $documentCount |
||
24 | */ |
||
25 | public function __construct($dbHandle, $documentCount) |
||
30 | |||
31 | /** |
||
32 | * Formula to calculate: |
||
33 | * idf(t) = 1 + log ( totalDocuments / (documentsThatContainTheTerm + 1)) |
||
34 | * @throws \Exception |
||
35 | */ |
||
36 | public function execute() |
||
60 | } |
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..