Conditions | 10 |
Paths | 9 |
Total Lines | 32 |
Code Lines | 18 |
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 |
||
56 | public function throwException() { |
||
57 | // Unauthorized |
||
58 | if($this->info['http_code'] === 401) { |
||
59 | if($this->name == 'login') { |
||
60 | throw new TVDBUnauthorizedException('401: Unable to retrieve a TVDB token with the given details. Check your config.'); |
||
61 | } |
||
62 | else { |
||
63 | throw new TVDBUnauthorizedException( |
||
64 | '401: Unauthorized request to ' . $this->info['url'] . '. ' . |
||
65 | (($this->usedToken === null) ? '(no TVDB token was found)' : '(however a TVDB token was found)') |
||
66 | ); |
||
67 | } |
||
68 | } |
||
69 | // Not found |
||
70 | else if($this->info['http_code'] === 404) { |
||
71 | if($this->name == 'get_series') { |
||
72 | throw new TVDBNotFoundException('404: Unable to find the series - ' . $this->info['url']); |
||
73 | } |
||
74 | else if($this->name == 'get_series_actors') { |
||
75 | throw new TVDBNotFoundException('404: Unable to find the actors - ' . $this->info['url']); |
||
76 | } |
||
77 | else if($this->name == 'get_series_episodes') { |
||
78 | throw new TVDBNotFoundException('404: Unable to find the episodes - ' . $this->info['url']); |
||
79 | } |
||
80 | else if($this->name == 'get_episode') { |
||
81 | throw new TVDBNotFoundException('404: Unable to find the episode - ' . $this->info['url']); |
||
82 | } |
||
83 | // Generic 404 exception |
||
84 | // We're ignoring 'search_series' because this API endpoint returns 404 |
||
85 | // .. when there are no search results - we don't want that. |
||
86 | else if($this->name != 'search_series') { |
||
87 | throw new TVDBNotFoundException('404: Not found. ' . $this->info['url']); |
||
88 | } |
||
91 | } |