| Conditions | 13 |
| Paths | 13 |
| Total Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 30 | public function __get($propName) |
||
| 31 | { |
||
| 32 | switch($propName) |
||
| 33 | { |
||
| 34 | case 'modTime': |
||
| 35 | if($this->mod === null) |
||
| 36 | { |
||
| 37 | $this->mod = new \DateInterval('PT'.strval($this->role->down_time).'H'); |
||
|
|
|||
| 38 | } |
||
| 39 | return $this->mod; |
||
| 40 | case 'startTime': |
||
| 41 | if($this->myStart === null) |
||
| 42 | { |
||
| 43 | $this->myStart = new \DateTime($this->dbData['startTime']); |
||
| 44 | } |
||
| 45 | return $this->myStart; |
||
| 46 | case 'startTimeWithMod': |
||
| 47 | if($this->modStart === null) |
||
| 48 | { |
||
| 49 | $this->modStart = clone $this->startTime; |
||
| 50 | $this->modStart->sub($this->modTime); |
||
| 51 | } |
||
| 52 | return $this->modStart; |
||
| 53 | case 'endTime': |
||
| 54 | if($this->myEnd === null) |
||
| 55 | { |
||
| 56 | $this->myEnd = new \DateTime($this->dbData['endTime']); |
||
| 57 | } |
||
| 58 | return $this->myEnd; |
||
| 59 | case 'endTimeWithMod': |
||
| 60 | if($this->modEnd === null) |
||
| 61 | { |
||
| 62 | $this->modEnd = clone $this->endTime; |
||
| 63 | $this->modEnd->add($this->modTime); |
||
| 64 | } |
||
| 65 | return $this->modEnd; |
||
| 66 | case 'role': |
||
| 67 | if(!isset(self::$roleCache[$this->dbData['roleID']])) |
||
| 68 | { |
||
| 69 | self::$roleCache[$this->dbData['roleID']] = new \VolunteerRole($this->dbData['roleID']); |
||
| 70 | } |
||
| 71 | return self::$roleCache[$this->dbData['roleID']]; |
||
| 72 | default: |
||
| 73 | return $this->dbData[$propName]; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 138 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.