Conditions | 2 |
Paths | 2 |
Total Lines | 52 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
35 | protected function prepareRequestData(array $requests) : RequestList |
||
36 | { |
||
37 | $requestList = new RequestList(); |
||
38 | $requestList->requests = $requests; |
||
39 | |||
40 | $userIds = array_map( |
||
41 | function(Request $entry) { |
||
42 | return $entry->getReserved(); |
||
43 | }, |
||
44 | $requests |
||
45 | ); |
||
46 | |||
47 | $requestList->userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
||
48 | |||
49 | $requestList->requestTrustedIp = []; |
||
50 | $requestList->relatedIpRequests = []; |
||
51 | $requestList->relatedEmailRequests = []; |
||
52 | |||
53 | foreach ($requests as $request) { |
||
54 | $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
||
55 | $request->getIp(), |
||
56 | $request->getForwardedIp() |
||
57 | ); |
||
58 | |||
59 | RequestSearchHelper::get($this->getDatabase()) |
||
60 | ->byIp($trustedIp) |
||
61 | ->withConfirmedEmail() |
||
62 | ->excludingPurgedData($this->getSiteConfiguration()) |
||
63 | ->excludingRequest($request->getId()) |
||
64 | ->getRecordCount($ipCount); |
||
65 | |||
66 | RequestSearchHelper::get($this->getDatabase()) |
||
67 | ->byEmailAddress($request->getEmail()) |
||
68 | ->withConfirmedEmail() |
||
69 | ->excludingPurgedData($this->getSiteConfiguration()) |
||
70 | ->excludingRequest($request->getId()) |
||
71 | ->getRecordCount($emailCount); |
||
72 | |||
73 | $requestList->requestTrustedIp[$request->getId()] = $trustedIp; |
||
74 | $requestList->relatedEmailRequests[$request->getId()] = $emailCount; |
||
75 | $requestList->relatedIpRequests[$request->getId()] = $ipCount; |
||
76 | } |
||
77 | |||
78 | $currentUser = User::getCurrent($this->getDatabase()); |
||
79 | |||
80 | $requestList->canBan = $this->barrierTest('set', $currentUser, PageBan::class); |
||
81 | $requestList->canBreakReservation = $this->barrierTest('force', $currentUser, PageBreakReservation::class); |
||
82 | $requestList->showPrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData'); |
||
83 | $requestList->dataClearEmail = $this->getSiteConfiguration()->getDataClearEmail(); |
||
84 | $requestList->dataClearIp = $this->getSiteConfiguration()->getDataClearIp(); |
||
85 | |||
86 | return $requestList; |
||
87 | } |
||
89 |