| Conditions | 3 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 34 |
| 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 |
||
| 57 | public function getTemplateData() |
||
| 58 | { |
||
| 59 | /** @var UserEntity $userEntity */ |
||
| 60 | $userEntity = $this->userStorage->getUserById(1); |
||
| 61 | |||
| 62 | $policies = $this->userToPolicyCoupler->getEntityDependencies($userEntity); |
||
| 63 | $groups = $this->userToGroupCoupler->getEntityDependencies($userEntity); |
||
| 64 | $groupPolicies = []; |
||
| 65 | |||
| 66 | /** @var UserGroupEntity $group */ |
||
| 67 | foreach ($groups as $group) { |
||
| 68 | $groupPolicies[$group->getKeyData()] = $this->userGroupToPolicyCoupler->getEntityDependencies($group); |
||
| 69 | } |
||
| 70 | |||
| 71 | |||
| 72 | // Give special name |
||
| 73 | $this->loginForm->setName('login'); |
||
| 74 | // Turn off aut complete feature. |
||
| 75 | $this->loginForm->setAutoComplete(false); |
||
| 76 | // test data setter |
||
| 77 | $this->loginForm->setData((array)$this->request->getParsedBody()); |
||
| 78 | |||
| 79 | if (!empty($this->request->getParsedBody())) { |
||
| 80 | $this->session->set('session', $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
||
| 81 | $this->session->regenerateId(); |
||
| 82 | } |
||
| 83 | |||
| 84 | return [ |
||
| 85 | 'blogPosts' => [ |
||
| 86 | [ |
||
| 87 | 'title' => 'Fake test 1', |
||
| 88 | 'slug' => 'fake_1', |
||
| 89 | 'publishedAt' => time(), |
||
| 90 | 'author' => [ |
||
| 91 | 'name' => $userEntity->getUserName() |
||
| 92 | ], |
||
| 93 | 'content' => 'Lorem ipsum dolor sit amet...' |
||
| 94 | ], |
||
| 95 | [ |
||
| 96 | 'title' => 'Fake test 2', |
||
| 97 | 'slug' => 'fake_2', |
||
| 98 | 'publishedAt' => time(), |
||
| 99 | 'author' => [ |
||
| 100 | 'name' => 'Jane Doe' |
||
| 101 | ], |
||
| 102 | 'content' => 'Lorem ipsum dolor sit amet...' |
||
| 103 | ] |
||
| 104 | ], |
||
| 105 | 'postData' => var_export($this->request->getParsedBody(), true), |
||
| 106 | 'session' => var_export($this->session->toArray(), true), |
||
| 107 | 'user' => var_export($userEntity, true), |
||
| 108 | 'policy' => var_export($policies, true), |
||
| 109 | 'group' => var_export($groups, true), |
||
| 110 | 'grouppolicy' => var_export($groupPolicies, true), |
||
| 111 | 'loginForm' => $this->loginForm |
||
| 112 | ]; |
||
| 113 | } |
||
| 114 | } |
||
| 115 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.