Conditions | 11 |
Paths | 35 |
Total Lines | 36 |
Code Lines | 24 |
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 |
||
48 | public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []) |
||
49 | { |
||
50 | $this->context = $context; |
||
51 | $match = false; |
||
52 | $result = null; |
||
53 | |||
54 | foreach ($this->dataProviders as $dataProvider) { |
||
55 | $this->providersResponse[\get_class($dataProvider)] = $match ? null : false; |
||
56 | if ($match) { |
||
57 | continue; |
||
58 | } |
||
59 | try { |
||
60 | if ($dataProvider instanceof RestrictedDataProviderInterface |
||
61 | && !$dataProvider->supports($resourceClass, $operationName, $context)) { |
||
62 | continue; |
||
63 | } |
||
64 | |||
65 | $identifier = $id; |
||
66 | if (!$dataProvider instanceof DenormalizedIdentifiersAwareItemDataProviderInterface && $identifier && \is_array($identifier)) { |
||
67 | if (\count($identifier) > 1) { |
||
68 | @trigger_error(sprintf('Receiving "$id" as non-array in an item data provider is deprecated in 2.3 in favor of implementing "%s".', DenormalizedIdentifiersAwareItemDataProviderInterface::class), E_USER_DEPRECATED); |
||
69 | $identifier = http_build_query($identifier, '', ';'); |
||
70 | } else { |
||
71 | $identifier = current($identifier); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | $result = $dataProvider->getItem($resourceClass, $identifier, $operationName, $context); |
||
76 | $this->providersResponse[\get_class($dataProvider)] = $match = true; |
||
77 | } catch (ResourceClassNotSupportedException $e) { |
||
78 | @trigger_error(sprintf('Throwing a "%s" is deprecated in favor of implementing "%s"', \get_class($e), RestrictedDataProviderInterface::class), E_USER_DEPRECATED); |
||
79 | continue; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | return $result; |
||
84 | } |
||
86 |