Conditions | 8 |
Paths | 7 |
Total Lines | 60 |
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 |
||
65 | public function actionIndex($uid = null) |
||
66 | { |
||
67 | $message = Factory::receive(); |
||
68 | |||
69 | $isRequest = $message instanceof LogoutRequest; |
||
70 | $isResponse = $message instanceof LogoutResponse; |
||
71 | |||
72 | if ((! $isRequest && ! $isResponse) || |
||
73 | $isResponse && $this->getPlugin()->getSession()->getRequestId() !== $message->getInResponseTo()) { |
||
|
|||
74 | throw new HttpException(400, "Invalid request"); |
||
75 | } |
||
76 | |||
77 | $settings = $this->getPlugin()->getSettings(); |
||
78 | |||
79 | /** @var AbstractProvider $theirProvider */ |
||
80 | $theirProvider = $this->getPlugin()->getProvider()->findByEntityId( |
||
81 | MessageHelper::getIssuer($message->getIssuer()) |
||
82 | )->one(); |
||
83 | $condition = [ |
||
84 | 'enabled' => 1 |
||
85 | ]; |
||
86 | |||
87 | if ($uid) { |
||
88 | $condition['uid'] = $uid; |
||
89 | } else { |
||
90 | $condition['entityId'] = $settings->getEntityId(); |
||
91 | } |
||
92 | /** @var AbstractProvider $ourProvider */ |
||
93 | $ourProvider = $this->getPlugin()->getProvider()->find($condition)->one(); |
||
94 | |||
95 | if ($isRequest) { |
||
96 | if (\Craft::$app->getUser()->isGuest) { |
||
97 | $this->destroySpecifiedSession( |
||
98 | $message, |
||
99 | $theirProvider, |
||
100 | $this->getPlugin()->getSettings() |
||
101 | ); |
||
102 | } |
||
103 | |||
104 | /** @var LogoutResponse $response */ |
||
105 | $response = $this->getPlugin()->getLogoutResponse()->create( |
||
106 | $message, |
||
107 | $theirProvider, |
||
108 | $ourProvider |
||
109 | ); |
||
110 | |||
111 | /** |
||
112 | * Add the request id to the the response. |
||
113 | */ |
||
114 | $response->setInResponseTo($message->getId()); |
||
115 | |||
116 | \Craft::$app->user->logout(true); |
||
117 | Factory::send($response, $theirProvider); |
||
118 | \Craft::$app->end(); |
||
119 | } |
||
120 | |||
121 | return $this->redirect( |
||
122 | \Craft::$app->config->general->logoutPath |
||
123 | ); |
||
124 | } |
||
125 | |||
207 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: