| Conditions | 22 |
| Paths | 22 |
| Total Lines | 87 |
| Lines | 28 |
| Ratio | 32.18 % |
| 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 'participantObj': |
||
| 74 | if($this->participantObj === null) |
||
| 75 | { |
||
| 76 | if(isset($this->dbData['participant'])) |
||
| 77 | { |
||
| 78 | $this->participantObj = new \VolunteerProfile($this->dbData['participant']); |
||
| 79 | } |
||
| 80 | else |
||
| 81 | { |
||
| 82 | $this->participantObj = false; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | return $this->participantObj; |
||
| 86 | View Code Duplication | case 'webParticipantName': |
|
| 87 | if($this->webParticipantName === null) |
||
| 88 | { |
||
| 89 | if(isset($this->dbData['participant'])) |
||
| 90 | { |
||
| 91 | $tmp = new \VolunteerProfile($this->dbData['participant']); |
||
| 92 | $this->webParticipantName = $tmp->getDisplayName(); |
||
| 93 | } |
||
| 94 | else |
||
| 95 | { |
||
| 96 | $this->webParticipantName = ""; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | return $this->webParticipantName; |
||
| 100 | View Code Duplication | case 'scheduleParticipantName': |
|
| 101 | if($this->scheduleParticipantName === null) |
||
| 102 | { |
||
| 103 | if(isset($this->dbData['participant'])) |
||
| 104 | { |
||
| 105 | $tmp = new \VolunteerProfile($this->dbData['participant']); |
||
| 106 | $this->scheduleParticipantName = $tmp->getDisplayName('paperName'); |
||
| 107 | } |
||
| 108 | else |
||
| 109 | { |
||
| 110 | $this->scheduleParticipantName = ""; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | return $this->scheduleParticipantName; |
||
| 114 | default: |
||
| 115 | return $this->dbData[$propName]; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 180 |
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.