| Conditions | 10 |
| Paths | 64 |
| Total Lines | 43 |
| Code Lines | 25 |
| 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 |
||
| 90 | private function createExclusionStrategies(FOSContext $context) |
||
| 91 | { |
||
| 92 | $exclusionStrategies = []; |
||
| 93 | |||
| 94 | if ($context->getGroups() !== null) { |
||
| 95 | $exclusionStrategies[] = new GroupsExclusionStrategy($context->getGroups()); |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($context->getVersion() !== null) { |
||
| 99 | $exclusionStrategies[] = new VersionExclusionStrategy($context->getVersion()); |
||
| 100 | } |
||
| 101 | |||
| 102 | if ($context->isMaxDepthEnabled() !== null) { |
||
| 103 | $exclusionStrategies[] = new MaxDepthExclusionStrategy(); |
||
| 104 | } |
||
| 105 | |||
| 106 | $customExclusionStrategies = $context->getAttribute($attribute = 'ivory_exclusion_strategies') ?: []; |
||
| 107 | |||
| 108 | if (!is_array($customExclusionStrategies) && !$customExclusionStrategies instanceof \Traversable) { |
||
| 109 | throw new \RuntimeException(sprintf( |
||
| 110 | 'The "%s" context attribute must be an array or implement "%s".', |
||
| 111 | $attribute, |
||
| 112 | \Traversable::class |
||
| 113 | )); |
||
| 114 | } |
||
| 115 | |||
| 116 | foreach ($customExclusionStrategies as $customExclusionStrategy) { |
||
| 117 | if (!$customExclusionStrategy instanceof ExclusionStrategyInterface) { |
||
| 118 | throw new \RuntimeException(sprintf( |
||
| 119 | 'The "%s" context attribute must be an array of "%s", got "%s".', |
||
| 120 | $attribute, |
||
| 121 | ExclusionStrategyInterface::class, |
||
| 122 | is_object($customExclusionStrategy) |
||
| 123 | ? get_class($customExclusionStrategy) |
||
| 124 | : gettype($customExclusionStrategy) |
||
| 125 | )); |
||
| 126 | } |
||
| 127 | |||
| 128 | $exclusionStrategies[] = $customExclusionStrategy; |
||
| 129 | } |
||
| 130 | |||
| 131 | return $exclusionStrategies; |
||
| 132 | } |
||
| 133 | } |
||
| 134 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: