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