Conditions | 14 |
Paths | 20 |
Total Lines | 29 |
Code Lines | 15 |
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 | // The Resource is an interface |
||
58 | if ($value instanceof $resourceClass && $type !== $resourceClass && interface_exists($resourceClass)) { |
||
59 | throw new InvalidArgumentException(sprintf('The given object\'s resource is the interface "%s", finding a class is not possible.', $resourceClass)); |
||
60 | } |
||
61 | |||
62 | if ( |
||
63 | ($isResourceClass ?? $this->isResourceClass($type)) |
||
64 | || (is_subclass_of($type, $resourceClass) && $this->isResourceClass($resourceClass)) |
||
65 | ) { |
||
66 | return $type; |
||
67 | } |
||
68 | |||
69 | throw new InvalidArgumentException(sprintf('No resource class found for object of type "%s".', $type)); |
||
70 | } |
||
90 |