| Conditions | 7 |
| Paths | 5 |
| Total Lines | 80 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 71 | public function __invoke($provider = null, $route = '') |
||
| 72 | { |
||
| 73 | $route = base64_encode($route); |
||
| 74 | $providers = (array) $this->config['backend']; |
||
| 75 | $urlHelper = $this->urlHelper; |
||
| 76 | |||
| 77 | if ($this->token->isAuthenticated()) { |
||
| 78 | // Display Logged in information |
||
| 79 | |||
| 80 | $user = sprintf($this->config['logoffstring'], $this->token->getDisplayName()); |
||
| 81 | $link = $urlHelper( |
||
| 82 | 'hybridauth/logout', |
||
| 83 | ['redirect' => $route] |
||
| 84 | ); |
||
| 85 | $link = sprintf($this->config['link'], $user, $link); |
||
| 86 | return sprintf($this->config['logoffcontainer'], $link); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (null !== $provider && in_array($provider, $providers)) { |
||
| 90 | return $urlHelper( |
||
| 91 | 'hybridauth/login', |
||
| 92 | array('redirect' => $route, 'provider' => $provider) |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | if (1 == count($providers)) { |
||
| 97 | return sprintf( |
||
| 98 | $this->config['item'], |
||
| 99 | sprintf( |
||
| 100 | $this->config['link'], |
||
| 101 | sprintf( |
||
| 102 | $this->config['loginstring'], |
||
| 103 | ' using ' . current($providers) |
||
| 104 | ), |
||
| 105 | $urlHelper( |
||
| 106 | 'hybridauth/login', |
||
| 107 | [ |
||
| 108 | 'redirect' => $route, |
||
| 109 | 'provider' => strtolower(current($providers)), |
||
| 110 | ] |
||
| 111 | ) |
||
| 112 | ), |
||
| 113 | null |
||
| 114 | ); |
||
| 115 | } |
||
| 116 | |||
| 117 | $xhtml = array(); |
||
| 118 | foreach ($providers as $name => $backend) { |
||
| 119 | $link = $urlHelper( |
||
| 120 | 'hybridauth/login', |
||
| 121 | [ |
||
| 122 | 'redirect' => $route, |
||
| 123 | 'provider' => $backend |
||
| 124 | ] |
||
| 125 | ); |
||
| 126 | $xhtml[] = sprintf( |
||
| 127 | $this->config['item'], |
||
| 128 | sprintf( |
||
| 129 | $this->config['link'], |
||
| 130 | (is_string($name)?$name:$backend), |
||
| 131 | $link |
||
| 132 | ), |
||
| 133 | $this->config['itemAttribs'] |
||
| 134 | ); |
||
| 135 | } |
||
| 136 | |||
| 137 | return sprintf( |
||
| 138 | $this->config['logincontainer'], |
||
| 139 | sprintf( |
||
| 140 | $this->config['loginstring'], |
||
| 141 | ' using' |
||
| 142 | ), |
||
| 143 | sprintf( |
||
| 144 | $this->config['itemlist'], |
||
| 145 | implode("\n",$xhtml), |
||
| 146 | $this->config['listAttribs'] |
||
| 147 | ) |
||
| 148 | ); |
||
| 149 | |||
| 150 | } |
||
| 151 | |||
| 168 |