| Conditions | 21 |
| Paths | 164 |
| Total Lines | 45 |
| Code Lines | 26 |
| 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 |
||
| 40 | public function getResourceClass($value, string $resourceClass = null, bool $strict = false): string |
||
| 41 | { |
||
| 42 | $type = \is_object($value) && !$value instanceof \Traversable ? $this->getObjectClass($value) : $resourceClass; |
||
| 43 | $resourceClass = $resourceClass ?? $type; |
||
| 44 | |||
| 45 | if (null === $resourceClass) { |
||
| 46 | throw new InvalidArgumentException(sprintf('No resource class found.')); |
||
| 47 | } |
||
| 48 | |||
| 49 | $resolvedResourceClass = null; |
||
| 50 | foreach ($this->resourceNameCollectionFactory->create() as $currentResourceClass) { |
||
| 51 | if ($resourceClass === $currentResourceClass) { |
||
| 52 | $resolvedResourceClass = $currentResourceClass; |
||
| 53 | } |
||
| 54 | if (null === $resolvedResourceClass && is_subclass_of($type, $currentResourceClass)) { |
||
| 55 | $resolvedResourceClass = $currentResourceClass; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | if (null !== $resolvedResourceClass) { |
||
|
|
|||
| 60 | $resourceClass = $resolvedResourceClass; |
||
| 61 | } |
||
| 62 | |||
| 63 | $typeIsStrictResourceClass = $this->isStrictResourceClass($type); |
||
| 64 | if ($strict && $typeIsStrictResourceClass) { |
||
| 65 | return $type; |
||
| 66 | } |
||
| 67 | |||
| 68 | $typeIsResourceClass = $this->isResourceClass($type); |
||
| 69 | if ( |
||
| 70 | null === $type |
||
| 71 | || (((!$strict || $resourceClass === $type)) && $typeIsResourceClass) |
||
| 72 | || null !== $resolvedResourceClass && (interface_exists($resourceClass) || !$typeIsStrictResourceClass) |
||
| 73 | ) { |
||
| 74 | return $resourceClass; |
||
| 75 | } |
||
| 76 | |||
| 77 | if ( |
||
| 78 | $typeIsResourceClass |
||
| 79 | || (is_subclass_of($type, $resourceClass) && $this->isResourceClass($resourceClass)) |
||
| 80 | ) { |
||
| 81 | return $type; |
||
| 82 | } |
||
| 83 | |||
| 84 | throw new InvalidArgumentException(sprintf('No resource class found for object of type "%s".', $type)); |
||
| 85 | } |
||
| 118 |