Conditions | 42 |
Paths | 42 |
Total Lines | 89 |
Code Lines | 85 |
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 |
||
60 | public static function getStatusDescription($statusCode) |
||
61 | { |
||
62 | switch ($statusCode) { |
||
63 | case self::CODE_CONTINUE: |
||
64 | return 'Continue'; |
||
65 | case self::CODE_SWITCHING_PROTOCOLS: |
||
66 | return 'SwitchingProtocols'; |
||
67 | case self::CODE_OK: |
||
68 | return 'OK'; |
||
69 | case self::CODE_CREATED; |
||
|
|||
70 | return 'Created'; |
||
71 | case self::CODE_ACCEPTED; |
||
72 | return 'Accepted'; |
||
73 | case self::CODE_NON_AUTHRATIVE_INFORMATION; |
||
74 | return 'Non-Authrative Information'; |
||
75 | case self::CODE_NOCONTENT; |
||
76 | return 'No Content'; |
||
77 | case self::CODE_RESET_CONTENT; |
||
78 | return 'ResetContent'; |
||
79 | case self::CODE_PARTIAL_CONTENT; |
||
80 | return 'Partial Content'; |
||
81 | case self::CODE_MULTIPLE_CHOICE; |
||
82 | return 'Multiple Choices'; |
||
83 | case self::CODE_MOVED_PERMANENTLY; |
||
84 | return 'Moved Permanently'; |
||
85 | case self::CODE_FOUND; |
||
86 | return 'Found'; |
||
87 | case self::CODE_SEE_OTHER; |
||
88 | return 'See Other'; |
||
89 | case self::CODE_NOT_MODIFIED; |
||
90 | return 'Not Modified'; |
||
91 | case self::CODE_USE_PROXY; |
||
92 | return 'Use Proxy'; |
||
93 | case self::CODE_UNUSED; |
||
94 | return 'Unused'; |
||
95 | case self::CODE_TEMP_REDIRECT; |
||
96 | return 'Temporary Redirect'; |
||
97 | case self::CODE_BAD_REQUEST; |
||
98 | return 'Bad Request'; |
||
99 | case self::CODE_UNAUTHORIZED; |
||
100 | return 'Unauthorized'; |
||
101 | case self::CODE_PAYMENT_REQ; |
||
102 | return 'Payment Required'; |
||
103 | case self::CODE_FORBIDDEN; |
||
104 | return 'Forbidden'; |
||
105 | case self::CODE_NOT_FOUND; |
||
106 | return 'Not Found'; |
||
107 | case self::CODE_METHOD_NOT_ALLOWED; |
||
108 | return 'Method Not Allowed'; |
||
109 | case self::CODE_NOT_ACCEPTABLE; |
||
110 | return 'Not Acceptable'; |
||
111 | case self::CODE_PROXY_AUTHENTICATION_REQUIRED; |
||
112 | return 'Proxy Authentication Required'; |
||
113 | case self::CODE_REQUEST_TIMEOUT; |
||
114 | return 'Request Timeout'; |
||
115 | case self::CODE_CONFLICT; |
||
116 | return 'Conflict'; |
||
117 | case self::CODE_GONE; |
||
118 | return 'Gone'; |
||
119 | case self::CODE_LENGTH_REQUIRED; |
||
120 | return 'Length Required'; |
||
121 | case self::CODE_PRECONDITION_FAILED; |
||
122 | return 'Precondition Failed'; |
||
123 | case self::CODE_REQUEST_ENTITY_TOOLONG; |
||
124 | return 'Request Entity Too Large'; |
||
125 | case self::CODE_REQUEST_URI_TOOLONG; |
||
126 | return 'Request-URI Too Large'; |
||
127 | case self::CODE_UNSUPPORTED_MEDIATYPE; |
||
128 | return 'Unsupported Media Type'; |
||
129 | case self::CODE_REQUESTED_RANGE_NOT_SATISFIABLE; |
||
130 | return 'Requested Range NotSatisfiable'; |
||
131 | case self::CODE_EXPECTATION_FAILED; |
||
132 | return 'Expectation Failed'; |
||
133 | case self::CODE_INTERNAL_SERVER_ERROR; |
||
134 | return 'Internal Server Error'; |
||
135 | case self::CODE_NOT_IMPLEMENTED; |
||
136 | return 'Not Implemented'; |
||
137 | case self::CODE_BAD_GATEWAY; |
||
138 | return 'Bad Gateway'; |
||
139 | case self::CODE_SERVICE_UNAVAILABLE; |
||
140 | return 'Service Unavailable'; |
||
141 | case self::CODE_GATEWAY_TIMEOUT; |
||
142 | return 'Gateway Timeout'; |
||
143 | case self::CODE_HTTP_VERSION_NOT_SUPPORTED; |
||
144 | return 'HTTP Version Not Suppoted'; |
||
145 | } |
||
146 | |||
147 | return null; |
||
148 | } |
||
149 | } |
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break
.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.