| Conditions | 33 |
| Paths | 1280 |
| Total Lines | 151 |
| Code Lines | 68 |
| Lines | 32 |
| Ratio | 21.19 % |
| 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 | <!DOCTYPE html> |
||
| 35 | function OutputvCard(vCard $vCard) |
||
| 36 | { |
||
| 37 | echo '<h2>'.$vCard -> FN[0].'</h2>'; |
||
|
|
|||
| 38 | |||
| 39 | if ($vCard -> PHOTO) |
||
| 40 | { |
||
| 41 | foreach ($vCard -> PHOTO as $Photo) |
||
| 42 | { |
||
| 43 | if ($Photo['encoding'] == 'b') |
||
| 44 | { |
||
| 45 | echo '<img src="data:image/'.$Photo['type'][0].';base64,'.$Photo['value'].'" /><br />'; |
||
| 46 | } |
||
| 47 | else |
||
| 48 | { |
||
| 49 | echo '<img src="'.$Photo['value'].'" /><br />'; |
||
| 50 | } |
||
| 51 | |||
| 52 | /* |
||
| 53 | // It can also be saved to a file |
||
| 54 | try |
||
| 55 | { |
||
| 56 | $vCard -> SaveFile('photo', 0, 'test_image.jpg'); |
||
| 57 | // The parameters are: |
||
| 58 | // - name of the file we want to save (photo, logo or sound) |
||
| 59 | // - index of the file in case of multiple files (defaults to 0) |
||
| 60 | // - target path to save to, including the filenam |
||
| 61 | } |
||
| 62 | catch (Exception $E) |
||
| 63 | { |
||
| 64 | // Target path not writable |
||
| 65 | } |
||
| 66 | */ |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | foreach ($vCard -> N as $Name) |
||
| 71 | { |
||
| 72 | echo '<h3>Name: '.$Name['firstname'].' '.$Name['lastname'].'</h3>'; |
||
| 73 | } |
||
| 74 | |||
| 75 | foreach ($vCard -> ORG as $Organization) |
||
| 76 | { |
||
| 77 | echo '<h3>Organization: '.$Organization['name']. |
||
| 78 | ($Organization['unit1'] || $Organization['unit2'] ? |
||
| 79 | ' ('.implode(', ', array($Organization['unit1'], $Organization['unit2'])).')' : |
||
| 80 | '' |
||
| 81 | ).'</h3>'; |
||
| 82 | } |
||
| 83 | |||
| 84 | View Code Duplication | if ($vCard -> TEL) |
|
| 85 | { |
||
| 86 | echo '<p><h4>Phone</h4>'; |
||
| 87 | foreach ($vCard -> TEL as $Tel) |
||
| 88 | { |
||
| 89 | if (is_scalar($Tel)) |
||
| 90 | { |
||
| 91 | echo $Tel.'<br />'; |
||
| 92 | } |
||
| 93 | else |
||
| 94 | { |
||
| 95 | echo $Tel['value'].' ('.implode(', ', $Tel['type']).')<br />'; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | echo '</p>'; |
||
| 99 | } |
||
| 100 | |||
| 101 | View Code Duplication | if ($vCard -> EMAIL) |
|
| 102 | { |
||
| 103 | echo '<p><h4>Email</h4>'; |
||
| 104 | foreach ($vCard -> EMAIL as $Email) |
||
| 105 | { |
||
| 106 | if (is_scalar($Email)) |
||
| 107 | { |
||
| 108 | echo $Email; |
||
| 109 | } |
||
| 110 | else |
||
| 111 | { |
||
| 112 | echo $Email['value'].' ('.implode(', ', $Email['type']).')<br />'; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | echo '</p>'; |
||
| 116 | } |
||
| 117 | |||
| 118 | if ($vCard -> URL) |
||
| 119 | { |
||
| 120 | echo '<p><h4>URL</h4>'; |
||
| 121 | foreach ($vCard -> URL as $URL) |
||
| 122 | { |
||
| 123 | if (is_scalar($URL)) |
||
| 124 | { |
||
| 125 | echo $URL.'<br />'; |
||
| 126 | } |
||
| 127 | else |
||
| 128 | { |
||
| 129 | echo $URL['value'].'<br />'; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | echo '</p>'; |
||
| 133 | } |
||
| 134 | |||
| 135 | if ($vCard -> IMPP) |
||
| 136 | { |
||
| 137 | echo '<p><h4>Instant messaging</h4>'; |
||
| 138 | foreach ($vCard -> IMPP as $IMPP) |
||
| 139 | { |
||
| 140 | if (is_scalar($IMPP)) |
||
| 141 | { |
||
| 142 | echo $IMPP.'<br />'; |
||
| 143 | } |
||
| 144 | else |
||
| 145 | { |
||
| 146 | echo $IMPP['value'].'<br/ >'; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | echo '</p>'; |
||
| 150 | } |
||
| 151 | |||
| 152 | if ($vCard -> ADR) |
||
| 153 | { |
||
| 154 | foreach ($vCard -> ADR as $Address) |
||
| 155 | { |
||
| 156 | echo '<p><h4>Address ('.implode(', ', $Address['type']).')</h4>'; |
||
| 157 | echo 'Street address: <strong>'.($Address['streetaddress'] ? $Address['streetaddress'] : '-').'</strong><br />'. |
||
| 158 | 'PO Box: <strong>'.($Address['pobox'] ? $Address['pobox'] : '-').'</strong><br />'. |
||
| 159 | 'Extended address: <strong>'.($Address['extendedaddress'] ? $Address['extendedaddress'] : '-').'</strong><br />'. |
||
| 160 | 'Locality: <strong>'.($Address['locality'] ? $Address['locality'] : '-').'</strong><br />'. |
||
| 161 | 'Region: <strong>'.($Address['region'] ? $Address['region'] : '-').'</strong><br />'. |
||
| 162 | 'ZIP/Post code: <strong>'.($Address['postalcode'] ? $Address['postalcode'] : '-').'</strong><br />'. |
||
| 163 | 'Country: <strong>'.($Address['country'] ? $Address['country'] : '-').'</strong>'; |
||
| 164 | } |
||
| 165 | echo '</p>'; |
||
| 166 | } |
||
| 167 | |||
| 168 | if ($vCard -> AGENT) |
||
| 169 | { |
||
| 170 | echo '<h4>Agents</h4>'; |
||
| 171 | foreach ($vCard -> AGENT as $Agent) |
||
| 172 | { |
||
| 173 | if (is_scalar($Agent)) |
||
| 174 | { |
||
| 175 | echo '<div class="Agent">'.$Agent.'</div>'; |
||
| 176 | } |
||
| 177 | elseif (is_a($Agent, 'vCard')) |
||
| 178 | { |
||
| 179 | echo '<div class="Agent">'; |
||
| 180 | OutputvCard($Agent); |
||
| 181 | echo '</div>'; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 217 |
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.