| Conditions | 16 |
| Paths | 16 |
| Total Lines | 60 |
| 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 |
||
| 31 | public function __get($propName) |
||
| 32 | { |
||
| 33 | switch($propName) |
||
| 34 | { |
||
| 35 | case 'modTime': |
||
| 36 | if($this->mod === null) |
||
| 37 | { |
||
| 38 | $this->mod = new \DateInterval('PT'.strval($this->role->down_time).'H'); |
||
|
|
|||
| 39 | } |
||
| 40 | return $this->mod; |
||
| 41 | case 'startTime': |
||
| 42 | if($this->myStart === null) |
||
| 43 | { |
||
| 44 | $this->myStart = new \DateTime($this->dbData['startTime']); |
||
| 45 | } |
||
| 46 | return $this->myStart; |
||
| 47 | case 'startTimeWithMod': |
||
| 48 | if($this->modStart === null) |
||
| 49 | { |
||
| 50 | $this->modStart = clone $this->startTime; |
||
| 51 | $this->modStart->sub($this->modTime); |
||
| 52 | } |
||
| 53 | return $this->modStart; |
||
| 54 | case 'endTime': |
||
| 55 | if($this->myEnd === null) |
||
| 56 | { |
||
| 57 | $this->myEnd = new \DateTime($this->dbData['endTime']); |
||
| 58 | } |
||
| 59 | return $this->myEnd; |
||
| 60 | case 'endTimeWithMod': |
||
| 61 | if($this->modEnd === null) |
||
| 62 | { |
||
| 63 | $this->modEnd = clone $this->endTime; |
||
| 64 | $this->modEnd->add($this->modTime); |
||
| 65 | } |
||
| 66 | return $this->modEnd; |
||
| 67 | case 'role': |
||
| 68 | if(!isset(self::$roleCache[$this->dbData['roleID']])) |
||
| 69 | { |
||
| 70 | self::$roleCache[$this->dbData['roleID']] = new \VolunteerRole($this->dbData['roleID']); |
||
| 71 | } |
||
| 72 | return self::$roleCache[$this->dbData['roleID']]; |
||
| 73 | case 'webParticipantName': |
||
| 74 | if($this->webParticipantName === null) |
||
| 75 | { |
||
| 76 | if(isset($this->dbData['participant'])) |
||
| 77 | { |
||
| 78 | $tmp = new \VolunteerProfile($this->dbData['participant']); |
||
| 79 | $this->webParticipantName = $tmp->getDisplayName(); |
||
| 80 | } |
||
| 81 | else |
||
| 82 | { |
||
| 83 | $this->webParticipantName = ""; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | return $this->webParticipantName; |
||
| 87 | default: |
||
| 88 | return $this->dbData[$propName]; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 153 |
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.