| Conditions | 11 |
| Paths | 56 |
| Total Lines | 81 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 86 | public function authenticate() |
||
| 87 | { |
||
| 88 | $hybridAuth = $this->getHybridAuth(); |
||
| 89 | /* @var $adapter \Hybrid_Provider_Model */ |
||
| 90 | $adapter = $hybridAuth->authenticate($this->_provider); |
||
| 91 | |||
| 92 | $userProfile = $adapter->getUserProfile(); |
||
| 93 | $email = isset($userProfile->emailVerified) && !empty($userProfile->emailVerified) |
||
| 94 | ? $userProfile->emailVerified |
||
| 95 | : $userProfile->email; |
||
| 96 | |||
| 97 | |||
| 98 | $forceSave = false; |
||
| 99 | $user = $this->getRepository()->findByProfileIdentifier($userProfile->identifier, $this->_provider); |
||
| 100 | |||
| 101 | if (!$user) { |
||
| 102 | $forceSave = true; |
||
| 103 | $user = $this->getRepository()->create(); |
||
| 104 | } |
||
| 105 | |||
| 106 | |||
| 107 | $currentInfo = $user->getProfile($this->_provider); |
||
| 108 | $newInfo = [ |
||
| 109 | 'auth' => (array) $userProfile, |
||
| 110 | 'data' => $this->socialProfilePlugin->fetch($this->_provider)->getData(), |
||
| 111 | ]; |
||
| 112 | |||
| 113 | if ($forceSave || $currentInfo != $newInfo) { |
||
| 114 | /* */ |
||
| 115 | |||
| 116 | $dm = $this->getRepository()->getDocumentManager(); |
||
| 117 | if ('' == $user->getInfo()->email) { |
||
| 118 | $user->getInfo()->email = $email; |
||
| 119 | } |
||
| 120 | $user->getInfo()->firstName = $userProfile->firstName; |
||
| 121 | $user->getInfo()->lastName = $userProfile->lastName; |
||
| 122 | $user->getInfo()->birthDay = $userProfile->birthDay; |
||
| 123 | $user->getInfo()->birthMonth = $userProfile->birthMonth; |
||
| 124 | $user->getInfo()->birthYear = $userProfile->birthYear; |
||
| 125 | $user->getInfo()->postalcode = $userProfile->zip; |
||
| 126 | $user->getInfo()->city = $userProfile->city; |
||
| 127 | $user->getInfo()->street = $userProfile->address; |
||
| 128 | $user->getInfo()->phone = $userProfile->phone; |
||
| 129 | $user->getInfo()->gender = $userProfile->gender; |
||
| 130 | |||
| 131 | // $user->setLogin($email); // this may cause duplicate key exception |
||
| 132 | $user->addProfile($this->_provider, $newInfo); |
||
| 133 | |||
| 134 | $dm->persist($user); |
||
| 135 | // make sure all ids are generated and user exists in database. |
||
| 136 | $dm->flush(); |
||
| 137 | |||
| 138 | /* |
||
| 139 | * This must be after flush because a newly created user has no id! |
||
| 140 | */ |
||
| 141 | if ($forceSave || (!$user->getInfo()->image && $userProfile->photoURL)) { |
||
| 142 | // get user image |
||
| 143 | if ('' != $userProfile->photoURL) { |
||
| 144 | $client = new \Zend\Http\Client($userProfile->photoURL, array('sslverifypeer' => false)); |
||
| 145 | $response = $client->send(); |
||
| 146 | $file = new GridFSFile(); |
||
| 147 | $file->setBytes($response->getBody()); |
||
| 148 | |||
| 149 | $userImage = new UserImage(); |
||
| 150 | $userImage->setName($userProfile->lastName.$userProfile->firstName); |
||
| 151 | $userImage->setType($response->getHeaders()->get('Content-Type')->getFieldValue()); |
||
| 152 | $userImage->setUser($user); |
||
| 153 | $userImage->setFile($file); |
||
| 154 | $user->getInfo()->setImage($userImage); |
||
| 155 | $dm->persist($userImage); |
||
| 156 | //$this->getRepository()->store($user->info); |
||
| 157 | } |
||
| 158 | |||
| 159 | // We have to flush again |
||
| 160 | $dm->flush(); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | |||
| 165 | return new Result(Result::SUCCESS, $user->getId(), array('firstLogin' => $forceSave, 'user' => $user)); |
||
| 166 | } |
||
| 167 | |||
| 225 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.