| Conditions | 10 |
| Paths | 36 |
| Total Lines | 35 |
| Code Lines | 23 |
| 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 |
||
| 50 | public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []) |
||
| 51 | { |
||
| 52 | $this->context = $context; |
||
| 53 | foreach ($this->dataProviders as $dataProvider) { |
||
| 54 | $this->providersResponse[\get_class($dataProvider)] = null; |
||
| 55 | } |
||
| 56 | |||
| 57 | foreach ($this->dataProviders as $dataProvider) { |
||
| 58 | try { |
||
| 59 | if ($dataProvider instanceof RestrictedDataProviderInterface |
||
| 60 | && !$dataProvider->supports($resourceClass, $operationName, $context)) { |
||
| 61 | $this->providersResponse[\get_class($dataProvider)] = false; |
||
| 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 | $this->providersResponse[\get_class($dataProvider)] = true; |
||
| 75 | |||
| 76 | return $dataProvider->getItem($resourceClass, $identifier, $operationName, $context); |
||
| 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 | $this->providersResponse[\get_class($dataProvider)] = false; |
||
| 80 | continue; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | return null; |
||
| 85 | } |
||
| 87 |