We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 8 |
Paths | 4 |
Total Lines | 65 |
Code Lines | 38 |
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 |
||
63 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
64 | { |
||
65 | $response = $handler->handle($request); |
||
66 | // Get input parameters and decrypt core name. |
||
67 | $parameters = $request->getParsedBody(); |
||
68 | // Return if not this middleware |
||
69 | if (!isset($parameters['middleware']) || ($parameters['middleware'] != 'dlf/search-in-document')) { |
||
70 | return $response; |
||
71 | } |
||
72 | |||
73 | $encrypted = (string) $parameters['encrypted']; |
||
74 | if (empty($encrypted)) { |
||
75 | throw new \InvalidArgumentException('No valid parameter passed: ' . $parameters['middleware'] . ' ' . $parameters['encrypted'] . '!', 1580585079); |
||
76 | } |
||
77 | |||
78 | $output = [ |
||
79 | 'documents' => [], |
||
80 | 'numFound' => 0 |
||
81 | ]; |
||
82 | |||
83 | $core = Helper::decrypt($encrypted); |
||
84 | |||
85 | // Perform Solr query. |
||
86 | $this->solr = Solr::getInstance($core); |
||
87 | $this->fields = Solr::getFields(); |
||
88 | |||
89 | if ($this->solr->ready) { |
||
90 | $result = $this->executeSolrQuery($parameters); |
||
|
|||
91 | /** @scrutinizer ignore-call */ |
||
92 | $output['numFound'] = $result->getNumFound(); |
||
93 | $data = $result->getData(); |
||
94 | $highlighting = $data['ocrHighlighting']; |
||
95 | |||
96 | $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); |
||
97 | $site = $siteFinder->getSiteByPageId($parameters['pid']); |
||
98 | |||
99 | foreach ($result as $record) { |
||
100 | $resultDocument = new ResultDocument($record, $highlighting, $this->fields); |
||
101 | |||
102 | $url = (string) $site->getRouter()->generateUri( |
||
103 | $parameters['pid'], |
||
104 | [ |
||
105 | 'tx_dlf[id]' => !empty($resultDocument->getUid()) ? $resultDocument->getUid() : $parameters['uid'], |
||
106 | 'tx_dlf[page]' => $resultDocument->getPage(), |
||
107 | 'tx_dlf[highlight_word]' => $parameters['q'] |
||
108 | ] |
||
109 | ); |
||
110 | |||
111 | $document = [ |
||
112 | 'id' => $resultDocument->getId(), |
||
113 | 'uid' => !empty($resultDocument->getUid()) ? $resultDocument->getUid() : $parameters['uid'], |
||
114 | 'page' => $resultDocument->getPage(), |
||
115 | 'snippet' => $resultDocument->getSnippets(), |
||
116 | 'highlight' => $resultDocument->getHighlightsIds(), |
||
117 | 'url' => $url |
||
118 | ]; |
||
119 | $output['documents'][] = $document; |
||
120 | } |
||
121 | } |
||
122 | |||
123 | // Create response object. |
||
124 | /** @var Response $response */ |
||
125 | $response = GeneralUtility::makeInstance(Response::class); |
||
126 | $response->getBody()->write(json_encode($output)); |
||
127 | return $response; |
||
128 | } |
||
195 |