Conditions | 32 |
Paths | 288 |
Total Lines | 68 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
69 | public static function create(FacebookResponse $response) |
||
70 | { |
||
71 | $data = $response->getDecodedBody(); |
||
72 | |||
73 | if (!isset($data['error']['code']) && isset($data['code'])) { |
||
74 | $data = ['error' => $data]; |
||
75 | } |
||
76 | |||
77 | $code = isset($data['error']['code']) ? $data['error']['code'] : null; |
||
78 | $message = isset($data['error']['message']) ? $data['error']['message'] : 'Unknown error from Graph.'; |
||
79 | |||
80 | if (isset($data['error']['error_subcode'])) { |
||
81 | switch ($data['error']['error_subcode']) { |
||
82 | // Other authentication issues |
||
83 | case 458: |
||
84 | case 459: |
||
85 | case 460: |
||
86 | case 463: |
||
87 | case 464: |
||
88 | case 467: |
||
89 | return new static($response, new FacebookAuthenticationException($message, $code)); |
||
90 | // Video upload resumable error |
||
91 | case 1363030: |
||
92 | case 1363019: |
||
93 | case 1363037: |
||
94 | case 1363033: |
||
95 | case 1363021: |
||
96 | case 1363041: |
||
97 | return new static($response, new FacebookResumableUploadException($message, $code)); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | switch ($code) { |
||
102 | // Login status or token expired, revoked, or invalid |
||
103 | case 100: |
||
104 | case 102: |
||
105 | case 190: |
||
106 | return new static($response, new FacebookAuthenticationException($message, $code)); |
||
107 | |||
108 | // Server issue, possible downtime |
||
109 | case 1: |
||
110 | case 2: |
||
111 | return new static($response, new FacebookServerException($message, $code)); |
||
112 | |||
113 | // API Throttling |
||
114 | case 4: |
||
115 | case 17: |
||
116 | case 341: |
||
117 | return new static($response, new FacebookThrottleException($message, $code)); |
||
118 | |||
119 | // Duplicate Post |
||
120 | case 506: |
||
121 | return new static($response, new FacebookClientException($message, $code)); |
||
122 | } |
||
123 | |||
124 | // Missing Permissions |
||
125 | if ($code == 10 || ($code >= 200 && $code <= 299)) { |
||
126 | return new static($response, new FacebookAuthorizationException($message, $code)); |
||
127 | } |
||
128 | |||
129 | // OAuth authentication error |
||
130 | if (isset($data['error']['type']) && $data['error']['type'] === 'OAuthException') { |
||
131 | return new static($response, new FacebookAuthenticationException($message, $code)); |
||
132 | } |
||
133 | |||
134 | // All others |
||
135 | return new static($response, new FacebookOtherException($message, $code)); |
||
136 | } |
||
137 | |||
215 |