| Conditions | 10 |
| Paths | 12 |
| Total Lines | 41 |
| Code 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 |
||
| 52 | public function getPlainToken(): ?string |
||
| 53 | { |
||
| 54 | foreach ($this->providers as $idx => $providerParam) { |
||
| 55 | // Lazy load the class |
||
| 56 | if (is_string($providerParam) || is_array($providerParam)) { |
||
| 57 | if (is_string($providerParam)) { |
||
| 58 | $providerParam = [$providerParam => []]; |
||
| 59 | } |
||
| 60 | $providerClass = key($providerParam); |
||
| 61 | $providerOptions = $providerParam[$providerClass]; |
||
| 62 | if (class_exists($providerClass)) { |
||
| 63 | $provider = new $providerClass($this->request, $providerOptions); |
||
| 64 | } else { |
||
| 65 | throw new \InvalidArgumentException( |
||
| 66 | sprintf("Cannot instanciate provider '%s' class cannot be loaded.", |
||
| 67 | is_object($providerClass) ? get_class($providerClass) : gettype($providerClass) |
||
| 68 | ) |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | } else { |
||
| 72 | $provider = $providerParam; |
||
| 73 | } |
||
| 74 | |||
| 75 | if (!$provider instanceof ProviderInterface) { |
||
| 76 | throw new \InvalidArgumentException( |
||
| 77 | sprintf("Type error token provider '%s' must implement '%s'.", |
||
| 78 | is_object($provider) ? get_class($provider) : gettype($provider), |
||
| 79 | ProviderInterface::class |
||
| 80 | ) |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | // Set for later reuse |
||
| 85 | $this->providers[$idx] = $provider; |
||
| 86 | if (null !== ($plainToken = $provider->getPlainToken())) { |
||
| 87 | return $plainToken; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | return null; |
||
| 92 | } |
||
| 93 | } |
||
| 94 |