Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 90c912...99a750 )
by Sebastian
14s queued 11s
created

SearchInDocument::main()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 45
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 45
rs 8.7537
cc 6
nc 3
nop 1
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Plugin\Eid;
14
15
use Kitodo\Dlf\Common\Helper;
16
use Kitodo\Dlf\Common\Solr;
17
use Psr\Http\Message\ResponseInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
use TYPO3\CMS\Core\Http\Response;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22
/**
23
 * eID search in document for plugin 'Search' of the 'dlf' extension
24
 *
25
 * @author Alexander Bigga <[email protected]>
26
 * @package TYPO3
27
 * @subpackage dlf
28
 * @access public
29
 */
30
class SearchInDocument
31
{
32
    /**
33
     * The main method of the eID script
34
     *
35
     * @param ServerRequestInterface $request
36
     * @return ResponseInterface JSON response of search suggestions
37
     */
38
    public function main(ServerRequestInterface $request)
39
    {
40
        $output = [
41
            'documents' => [],
42
            'numFound' => 0
43
        ];
44
        // Get input parameters and decrypt core name.
45
        $parameters = $request->getParsedBody();
46
        $encrypted = (string) $parameters['encrypted'];
47
        $hashed = (string) $parameters['hashed'];
48
        $count = intval($parameters['start']);
49
        if (empty($encrypted) || empty($hashed)) {
50
            throw new \InvalidArgumentException('No valid parameter passed!', 1580585079);
51
        }
52
        $core = Helper::decrypt($encrypted, $hashed);
53
        // Perform Solr query.
54
        $solr = Solr::getInstance($core);
55
        if ($solr->ready) {
56
            $query = $solr->service->createSelect();
57
            $query->setFields(['id', 'uid', 'page']);
58
            $query->setQuery('fulltext:(' . Solr::escapeQuery((string) $parameters['q']) . ') AND uid:' . intval($parameters['uid']));
59
            $query->setStart($count)->setRows(20);
60
            $hl = $query->getHighlighting();
61
            $hl->setFields(['fulltext']);
62
            $hl->setUseFastVectorHighlighter(true);
63
            $results = $solr->service->select($query);
64
            $output['numFound'] = $results->getNumFound();
65
            $highlighting = $results->getHighlighting();
66
            foreach ($results as $result) {
67
                $snippet = $highlighting->getResult($result->id)->getField('fulltext');
68
                $document = [
69
                    'id' => $result->id,
70
                    'uid' => $result->uid,
71
                    'page' => $result->page,
72
                    'snippet' => !empty($snippet) ? implode(' [...] ', $snippet) : ''
73
                ];
74
                $output['documents'][$count] = $document;
75
                $count++;
76
            }
77
        }
78
        // Create response object.
79
        /** @var Response $response */
80
        $response = GeneralUtility::makeInstance(Response::class);
81
        $response->getBody()->write(json_encode($output));
82
        return $response;
83
    }
84
}
85