| Conditions | 12 |
| Paths | 75 |
| Total Lines | 58 |
| Code Lines | 31 |
| 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 |
||
| 34 | public function __get($key) |
||
| 35 | { |
||
| 36 | switch ($key) { |
||
| 37 | case 'shareUrl': |
||
| 38 | return $this->shareUrl = $this->shareUrl(); |
||
| 39 | |||
| 40 | case 'shareCount': |
||
| 41 | |||
| 42 | // Check cache, if option is set. |
||
| 43 | if ($this->page->getConfig('useCache')) { |
||
| 44 | $id = $this->page->getId(get_class($this)); |
||
| 45 | $now = time(); |
||
| 46 | if ($cachedData = $this->page->cache->fetch($id)) { |
||
|
|
|||
| 47 | $expired = empty($cachedData[1]) || ( |
||
| 48 | $cachedData[1] + $this->page->getConfig('cacheDuration') < $now |
||
| 49 | ); |
||
| 50 | |||
| 51 | // If not expired, set shareCount and return. |
||
| 52 | if (!$expired) { |
||
| 53 | $this->shareCount = $cachedData[0]; |
||
| 54 | return $this->shareCount; |
||
| 55 | } |
||
| 56 | // Else, remove from cache and continue. |
||
| 57 | else { |
||
| 58 | $this->page->cache->delete($id); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($this->page->isMultiple()) { |
||
| 64 | $request = $this->shareCountRequestMultiple(); |
||
| 65 | } |
||
| 66 | else { |
||
| 67 | $request = $this->shareCountRequest(); |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($request !== null) { |
||
| 71 | $response = curl_exec($request) ?: ''; |
||
| 72 | curl_close($request); |
||
| 73 | |||
| 74 | if ($this->page->isMultiple()) { |
||
| 75 | $this->shareCount = $this->shareCountMultiple($response); |
||
| 76 | } |
||
| 77 | else { |
||
| 78 | $this->shareCount = $this->shareCount($response); |
||
| 79 | } |
||
| 80 | |||
| 81 | // Save in cache, if option is set. |
||
| 82 | if ($this->page->getConfig('useCache')) { |
||
| 83 | $this->page->cache->save($id, array($this->shareCount, $now)); |
||
| 84 | } |
||
| 85 | |||
| 86 | return $this->shareCount; |
||
| 87 | } |
||
| 88 | |||
| 89 | return $this->shareCount = null; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 252 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write 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.