Conditions | 7 |
Paths | 17 |
Total Lines | 52 |
Code Lines | 35 |
Lines | 0 |
Ratio | 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 |
||
22 | public function inspect(ResponseInterface $response) |
||
23 | { |
||
24 | $this->filterCommonErrors($response); |
||
25 | switch ($response->getStatusCode()) { |
||
26 | case 200: |
||
27 | // OK. |
||
28 | break; |
||
29 | default: |
||
30 | // KO. |
||
31 | throw $this->newBadRequestException($response); |
||
32 | } |
||
33 | $data = $this->decodeResponseBody($response); |
||
34 | |||
35 | $links = []; |
||
36 | foreach ($data['links'] as $link) { |
||
37 | $links[] = new PersistentSubscriptionInfoFeedLink($link['href'], $link['rel']); |
||
38 | } |
||
39 | |||
40 | $settings = new PersistentSubscriptionSettings(); |
||
41 | $config = $data['config']; |
||
42 | |||
43 | if ($config['resolveLinktos']) { |
||
44 | $settings->resolveLinktos(); |
||
45 | } else { |
||
46 | $settings->doNotResolveLinktos(); |
||
47 | } |
||
48 | $settings->startFrom($config['startFrom']); |
||
49 | $settings->withMessageTimeoutInMillisecondsOf($config['messageTimeoutMilliseconds']); |
||
50 | if ($config['extraStatistics']) { |
||
51 | $settings->withExtraStatistics(); |
||
52 | } |
||
53 | $settings->withMaxRetriesOf($config['maxRetryCount']); |
||
54 | $settings->WithReadBatchOf($config['readBatchSize']); |
||
55 | |||
56 | // todo: not sure of how preferRoundRobin relates to namedConsumerStrategy. |
||
57 | if ($config['preferRoundRobin'] || $config['namedConsumerStrategy'] == PersistentSubscriptionSettings::STRATEGY_ROUND_ROBIN) { |
||
58 | $settings->preferRoundRobin(); |
||
59 | } else { |
||
60 | $settings->preferDispatchToSingle(); |
||
61 | } |
||
62 | $settings->checkPointAfter($config['checkPointAfterMilliseconds']); |
||
63 | $settings->minCheckPointOf($config['minCheckPointCount']); |
||
64 | $settings->maxCheckPointOf($config['maxCheckPointCount']); |
||
65 | $settings->withMaxSubscribersOf($config['maxSubscriberCount']); |
||
66 | |||
67 | $streamId = new StreamId($data['eventStreamId']); |
||
68 | $groupName = $data['groupName']; |
||
69 | |||
70 | $info = new PersistentSubscriptionInfo($streamId, $groupName, $settings); |
||
71 | |||
72 | $this->feed = new PersistentSubscriptionInfoFeed($links, $info); |
||
73 | } |
||
74 | |||
83 |