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 |
||
| 40 | View Code Duplication | class PatientDIA extends Patient |
|
|
|
|||
| 41 | { |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string $typ typ pacjenta |
||
| 45 | */ |
||
| 46 | protected $typ = "DIA"; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @Column(columnDefinition="TINYINT(4) DEFAULT 0") * |
||
| 50 | */ |
||
| 51 | public $aktywnoscFizyczna; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @Column(columnDefinition="TINYINT(4) DEFAULT 0") * |
||
| 55 | */ |
||
| 56 | public $higiena; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @Column(columnDefinition="TINYINT(4) DEFAULT 0") * |
||
| 60 | */ |
||
| 61 | public $odzywianie; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @Column(columnDefinition="TINYINT(4) DEFAULT 0") * |
||
| 65 | */ |
||
| 66 | public $wydalanie; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @Column(columnDefinition="TINYINT(4) DEFAULT 0") * |
||
| 70 | */ |
||
| 71 | public $pomiarParametrowZyciowych; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @Column(columnDefinition="TINYINT(4) DEFAULT 0") * |
||
| 75 | */ |
||
| 76 | public $leczenie; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @Column(columnDefinition="TINYINT(4) DEFAULT 0") * |
||
| 80 | */ |
||
| 81 | public $edukacjaZdrowotnaIOpiekaPsychospoleczna; |
||
| 82 | // |
||
| 83 | /** |
||
| 84 | * @return aktywnoscFizyczna |
||
| 85 | */ |
||
| 86 | public function getAktywnoscFizyczna() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param int $aktywnoscFizyczna int aktywnoscFizyczna |
||
| 93 | * @return PatientZZ |
||
| 94 | */ |
||
| 95 | public function setAktywnoscFizyczna($aktywnoscFizyczna) |
||
| 96 | { |
||
| 97 | $this->aktywnoscFizyczna = $aktywnoscFizyczna; |
||
| 98 | return $this; |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @return higiena |
||
| 103 | */ |
||
| 104 | public function getHigiena() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param int $higiena int higiena |
||
| 111 | * @return PatientZZ |
||
| 112 | */ |
||
| 113 | public function setHigiena($higiena) |
||
| 114 | { |
||
| 115 | $this->higiena = $higiena; |
||
| 116 | return $this; |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return odzywianie |
||
| 121 | */ |
||
| 122 | public function getOdzywianie() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param int $odzywianie int odzywianie |
||
| 129 | * @return PatientZZ |
||
| 130 | */ |
||
| 131 | public function setOdzywianie($odzywianie) |
||
| 132 | { |
||
| 133 | $this->odzywianie = $odzywianie; |
||
| 134 | return $this; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return wydalanie |
||
| 139 | */ |
||
| 140 | public function getWydalanie() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param int $wydalanie int wydalanie |
||
| 147 | * @return PatientZZ |
||
| 148 | */ |
||
| 149 | public function setWydalanie($wydalanie) |
||
| 150 | { |
||
| 151 | $this->wydalanie = $wydalanie; |
||
| 152 | return $this; |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @return pomiarParametrowZyciowych |
||
| 157 | */ |
||
| 158 | public function getPomiarParametrowZyciowych() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @param int $pomiarParametrowZyciowych int pomiarParametrowZyciowych |
||
| 165 | * @return PatientZZ |
||
| 166 | */ |
||
| 167 | public function setPomiarParametrowZyciowych($pomiarParametrowZyciowych) |
||
| 168 | { |
||
| 169 | $this->pomiarParametrowZyciowych = $pomiarParametrowZyciowych; |
||
| 170 | return $this; |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return leczenie |
||
| 175 | */ |
||
| 176 | public function getLeczenie() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param int $leczenie int leczenie |
||
| 183 | * @return PatientZZ |
||
| 184 | */ |
||
| 185 | public function setLeczenie($leczenie) |
||
| 186 | { |
||
| 187 | $this->leczenie = $leczenie; |
||
| 188 | return $this; |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @return $edukacjaZdrowotnaIOpiekaPsychospoleczna |
||
| 193 | */ |
||
| 194 | public function getEdukacjaZdrowotnaIOpiekaPsychospoleczna() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param int $edukacjaZdrowotnaIOpiekaPsychospoleczna int edukacjaZdrowotnaIOpiekaPsychospoleczna |
||
| 201 | * @return PatientZZ |
||
| 202 | */ |
||
| 203 | public function setEdukacjaZdrowotnaIOpiekaPsychospoleczna($edukacjaZdrowotnaIOpiekaPsychospoleczna) |
||
| 204 | { |
||
| 208 | |||
| 209 | /** |
||
| 210 | * |
||
| 211 | * @return multitype:string |
||
| 212 | */ |
||
| 213 | public static function getFields() |
||
| 227 | |||
| 228 | } |
||
| 229 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.