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 namespace Comodojo\Extender\Orm\Entities; |
||
| 29 | class Schedule { |
||
| 30 | |||
| 31 | use BaseEntityTrait; |
||
| 32 | use ProcessEntityTrait; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | * |
||
| 37 | * @ORM\Column(name="description", type="text", length=65535, nullable=true) |
||
| 38 | */ |
||
| 39 | protected $description; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | * |
||
| 44 | * @ORM\Column(name="min", type="string", length=16, nullable=false) |
||
| 45 | */ |
||
| 46 | protected $min; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var string |
||
| 50 | * |
||
| 51 | * @ORM\Column(name="hour", type="string", length=16, nullable=false) |
||
| 52 | */ |
||
| 53 | protected $hour; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string |
||
| 57 | * |
||
| 58 | * @ORM\Column(name="day", type="string", length=16, nullable=false) |
||
| 59 | */ |
||
| 60 | protected $day; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var string |
||
| 64 | * |
||
| 65 | * @ORM\Column(name="month", type="string", length=16, nullable=false) |
||
| 66 | */ |
||
| 67 | protected $month; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | * |
||
| 72 | * @ORM\Column(name="weekday", type="string", length=16, nullable=false) |
||
| 73 | */ |
||
| 74 | protected $weekday; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var string |
||
| 78 | * |
||
| 79 | * @ORM\Column(name="year", type="string", length=16, nullable=false) |
||
| 80 | */ |
||
| 81 | protected $year; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var boolean |
||
| 85 | * |
||
| 86 | * @ORM\Column(name="enabled", type="boolean", nullable=false) |
||
| 87 | */ |
||
| 88 | protected $enabled = 0; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var datetime |
||
| 92 | * |
||
| 93 | * @ORM\Column(name="firstrun", type="datetime", nullable=true) |
||
| 94 | */ |
||
| 95 | protected $firstrun; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var datetime |
||
| 99 | * |
||
| 100 | * @ORM\Column(name="lastrun", type="datetime", nullable=true) |
||
| 101 | */ |
||
| 102 | protected $lastrun; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Get a brief job description |
||
| 106 | * |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | public function getDescription() { |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Set brief job description |
||
| 117 | * |
||
| 118 | * @param string $description |
||
| 119 | * @return Schedule |
||
| 120 | */ |
||
| 121 | public function setDescription($description) { |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Get cron expression of this schedule |
||
| 131 | * |
||
| 132 | * @return string |
||
| 133 | */ |
||
| 134 | public function getExpression() { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * set cron expression for this schedule |
||
| 142 | * |
||
| 143 | * @param srting $expression A cron-compatible expression |
||
| 144 | * @return Schedule |
||
| 145 | */ |
||
| 146 | public function setExpression($expression) { |
||
| 160 | |||
| 161 | /** |
||
| 162 | * True if job is currently enabled |
||
| 163 | * |
||
| 164 | * @return bool |
||
| 165 | */ |
||
| 166 | public function getEnabled() { |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Set enable/disable status |
||
| 174 | * |
||
| 175 | * @param bool $enable |
||
| 176 | * @return Schedule |
||
| 177 | */ |
||
| 178 | public function setEnable($enable) { |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Get the first-run-date of job |
||
| 190 | * |
||
| 191 | * @return DateTime |
||
| 192 | */ |
||
| 193 | public function getFirstrun() { |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Set the first-run-date of job |
||
| 201 | * |
||
| 202 | * @param DateTime $datetime |
||
| 203 | * @return Schedule |
||
| 204 | */ |
||
| 205 | public function setFirstrun(DateTime $datetime) { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Get the first-run-date of job |
||
| 215 | * |
||
| 216 | * @return DateTime |
||
| 217 | */ |
||
| 218 | public function getLastrun() { |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Set the first-run-date of job |
||
| 226 | * |
||
| 227 | * @param DateTime $datetime |
||
| 228 | * @return Schedule |
||
| 229 | */ |
||
| 230 | public function setLastrun(DateTime $datetime) { |
||
| 237 | |||
| 238 | View Code Duplication | public function shouldRunJob(DateTime $time) { |
|
| 251 | |||
| 252 | View Code Duplication | public function getNextPlannedRun(DateTime $time) { |
|
| 265 | |||
| 266 | protected function buildExpression() { |
||
| 280 | } |
||
| 281 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: