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 |
||
19 | abstract class AbstractBucket extends Stage |
||
20 | { |
||
21 | /** |
||
22 | * @var DocumentManager |
||
23 | */ |
||
24 | private $dm; |
||
25 | |||
26 | /** |
||
27 | * @var ClassMetadata |
||
28 | */ |
||
29 | private $class; |
||
30 | |||
31 | /** |
||
32 | * @var Bucket\BucketOutput|null |
||
33 | */ |
||
34 | protected $output; |
||
35 | |||
36 | /** |
||
37 | * @var Expr |
||
38 | */ |
||
39 | protected $groupBy; |
||
40 | |||
41 | 8 | public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class) |
|
48 | |||
49 | /** |
||
50 | * An expression to group documents by. To specify a field path, prefix the |
||
51 | * field name with a dollar sign $ and enclose it in quotes. |
||
52 | * |
||
53 | * @param array|Expr $expression |
||
54 | * @return $this |
||
55 | */ |
||
56 | 8 | public function groupBy($expression) |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 8 | public function getExpression() |
|
80 | |||
81 | /** |
||
82 | * @return array |
||
83 | */ |
||
84 | abstract protected function getExtraPipelineFields(); |
||
85 | |||
86 | /** |
||
87 | * Returns the stage name with the dollar prefix |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | abstract protected function getStageName(); |
||
92 | |||
93 | 8 | View Code Duplication | private function convertExpression($expression) |
103 | |||
104 | /** |
||
105 | * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister |
||
106 | */ |
||
107 | 8 | private function getDocumentPersister() |
|
111 | } |
||
112 |
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 mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.