Conditions | 30 |
Paths | 30 |
Total Lines | 97 |
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 |
||
95 | private function createByReason(string $reason, array $json): SendNotificationException |
||
96 | { |
||
97 | $reason = \strtolower($reason); |
||
98 | |||
99 | switch ($reason) { |
||
100 | case 'badcollapseid': |
||
101 | return new BadCollapseIdException(); |
||
102 | |||
103 | case 'baddevicetoken': |
||
104 | return new BadDeviceTokenException(); |
||
105 | |||
106 | case 'badexpirationdate': |
||
107 | return new BadExpirationDateException(); |
||
108 | |||
109 | case 'badmessageid': |
||
110 | return new BadMessageIdException(); |
||
111 | |||
112 | case 'badpriority': |
||
113 | return new BadPriorityException(); |
||
114 | |||
115 | case 'badtopic': |
||
116 | return new BadTopicException(); |
||
117 | |||
118 | case 'devicetokennotfortopic': |
||
119 | return new DeviceTokenNotForTopicException(); |
||
120 | |||
121 | case 'duplicateheaders': |
||
122 | return new DuplicateHeadersException(); |
||
123 | |||
124 | case 'idletimeout': |
||
125 | return new IdleTimeoutException(); |
||
126 | |||
127 | case 'missingdevicetoken': |
||
128 | return new MissingDeviceTokenException(); |
||
129 | |||
130 | case 'missingtopic': |
||
131 | return new MissingTopicException(); |
||
132 | |||
133 | case 'payloadempty': |
||
134 | return new PayloadEmptyException(); |
||
135 | |||
136 | case 'topicdisallowed': |
||
137 | return new TopicDisallowedException(); |
||
138 | |||
139 | case 'badcertificate': |
||
140 | return new BadCertificateException(); |
||
141 | |||
142 | case 'badcertificateenvironment': |
||
143 | return new BadCertificateEnvironmentException(); |
||
144 | |||
145 | case 'expiredprovidertoken': |
||
146 | return new ExpiredProviderTokenException(); |
||
147 | |||
148 | case 'forbidden': |
||
149 | return new ForbiddenException(); |
||
150 | |||
151 | case 'invalidprovidertoken': |
||
152 | return new InvalidProviderTokenException(); |
||
153 | |||
154 | case 'missingprovidertoken': |
||
155 | return new MissingProviderTokenException(); |
||
156 | |||
157 | case 'badpath': |
||
158 | return new BadPathException(); |
||
159 | |||
160 | case 'methodnotallowed': |
||
161 | return new MethodNotAllowedException(); |
||
162 | |||
163 | case 'unregistered': |
||
164 | $timestamp = \array_key_exists('timestamp', $json) ? $json['timestamp'] : 0; |
||
165 | $lastConfirmed = new \DateTime('now', new \DateTimeZone('UTC')); |
||
166 | $lastConfirmed->setTimestamp($timestamp); |
||
167 | |||
168 | return new UnregisteredException($lastConfirmed); |
||
169 | |||
170 | case 'payloadtoolarge': |
||
171 | return new PayloadTooLargeException(); |
||
172 | |||
173 | case 'toomanyprovidertokenupdates': |
||
174 | return new TooManyProviderTokenUpdatesException(); |
||
175 | |||
176 | case 'toomanyrequests': |
||
177 | return new TooManyRequestsException(); |
||
178 | |||
179 | case 'internalservererror': |
||
180 | return new InternalServerErrorException(); |
||
181 | |||
182 | case 'serviceunavailable': |
||
183 | return new ServiceUnavailableException(); |
||
184 | |||
185 | case 'shutdown': |
||
186 | return new ShutdownException(); |
||
187 | |||
188 | default: |
||
189 | return new UndefinedErrorException(); |
||
190 | } |
||
191 | } |
||
192 | } |
||
193 |