Conditions | 11 |
Paths | 13 |
Total 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 |
||
41 | public function getResourceClass($value, string $resourceClass = null, bool $strict = false): string |
||
42 | { |
||
43 | if (\is_object($value) && !$value instanceof \Traversable) { |
||
44 | $typeToFind = $type = $this->getObjectClass($value); |
||
45 | if (null === $resourceClass) { |
||
46 | $resourceClass = $typeToFind; |
||
47 | } |
||
48 | } elseif (null === $resourceClass) { |
||
49 | throw new InvalidArgumentException(sprintf('No resource class found.')); |
||
50 | } else { |
||
51 | $typeToFind = $type = $resourceClass; |
||
52 | } |
||
53 | |||
54 | if (($strict && $resourceClass !== $type) || false === $isResourceClass = $this->isResourceClass($typeToFind)) { |
||
55 | if (is_subclass_of($type, $resourceClass) && $this->isResourceClass($resourceClass)) { |
||
56 | return $type; |
||
57 | } |
||
58 | if ($isResourceClass ?? $this->isResourceClass($typeToFind)) { |
||
59 | return $typeToFind; |
||
60 | } |
||
61 | |||
62 | throw new InvalidArgumentException(sprintf('No resource class found for object of type "%s".', $typeToFind)); |
||
63 | } |
||
64 | |||
65 | return $resourceClass; |
||
66 | } |
||
86 |