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.
Passed
Push — master ( 613ade...e3d09d )
by
unknown
03:49
created

ResultDocument::parseRegions()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
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\Common\Solr\SearchResult;
14
15
/**
16
 * ResultDocument class for the 'dlf' extension. It keeps the result of the search in the SOLR index.
17
 *
18
 * @author Beatrycze Volk <[email protected]>
19
 * @package TYPO3
20
 * @subpackage dlf
21
 * @access public
22
 */
23
class ResultDocument
24
{
25
26
    /**
27
     * The identifier
28
     *
29
     * @var string
30
     * @access private
31
     */
32
    private $id;
33
34
    /**
35
     * The unified identifier
36
     *
37
     * @var string|null
38
     * @access private
39
     */
40
    private $uid;
41
42
    /**
43
     * The page on which result was found
44
     *
45
     * @var int
46
     * @access private
47
     */
48
    private $page;
49
50
    /**
51
     * All snippets imploded to one string
52
     *
53
     * @var string
54
     * @access private
55
     */
56
    private $snippets;
57
58
    /**
59
     * The thumbnail URL
60
     *
61
     * @var string
62
     * @access private
63
     */
64
    private $thumbnail;
65
66
    /**
67
     * The title of the document / structure element (e.g. chapter)
68
     *
69
     * @var string
70
     * @access private
71
     */
72
    private $title;
73
74
    /**
75
     * It's a toplevel element?
76
     *
77
     * @var boolean
78
     * @access private
79
     */
80
    private $toplevel = false;
81
82
    /**
83
     * The structure type
84
     *
85
     * @var string
86
     * @access private
87
     */
88
    private $type;
89
90
    /**
91
     * All pages in which search phrase was found
92
     *
93
     * @var array(Page)
94
     * @access private
95
     */
96
    private $pages = [];
97
98
    /**
99
     * All regions in which search phrase was found
100
     *
101
     * @var array(Region)
102
     * @access private
103
     */
104
    private $regions = [];
105
106
    /**
107
     * All highlights of search phrase
108
     *
109
     * @var array(Highlight)
110
     * @access private
111
     */
112
    private $highlights = [];
113
114
    /**
115
     * The snippets for given record
116
     *
117
     * @var array
118
     * @access private
119
     */
120
    private $snippetsForRecord = [];
121
122
    /**
123
     * The constructor for result.
124
     *
125
     * @access public
126
     *
127
     * @param array $record: Array of found document record
128
     * @param array $highlighting: Array of found highlight elements
129
     * @param array $fields: Array of fields used for search
130
     *
131
     * @return void
132
     */
133
    public function __construct($record, $highlighting, $fields)
134
    {
135
        $this->id = $record[$fields['id']];
136
        $this->uid = $record[$fields['uid']];
137
        $this->page = $record[$fields['page']];
138
        $this->thumbnail = $record[$fields['thumbnail']];
139
        $this->title = $record[$fields['title']];
140
        $this->toplevel = $record[$fields['toplevel']];
141
        $this->type = $record[$fields['type']];
142
143
        $highlightingForRecord = $highlighting[$record[$fields['id']]][$fields['fulltext']];
144
        $this->snippetsForRecord = is_array($highlightingForRecord['snippets']) ? $highlightingForRecord['snippets'] : [];
145
146
        $this->parseSnippets();
147
        $this->parsePages();
148
        $this->parseRegions();
149
        $this->parseHighlights();
150
    }
151
152
    /**
153
     * Get the result's record identifier.
154
     *
155
     * @access public
156
     *
157
     * @return string The result's record identifier
158
     */
159
    public function getId()
160
    {
161
        return $this->id;
162
    }
163
164
    /**
165
     * Get the result's record unified identifier.
166
     *
167
     * @access public
168
     *
169
     * @return string|null The result's record unified identifier
170
     */
171
    public function getUid()
172
    {
173
        return $this->uid;
174
    }
175
176
    /**
177
     * Get the result's record page.
178
     *
179
     * @access public
180
     *
181
     * @return int The result's record page
182
     */
183
    public function getPage()
184
    {
185
        return $this->page;
186
    }
187
188
    /**
189
     * Get all result's record snippets imploded to one string.
190
     *
191
     * @access public
192
     *
193
     * @return string All result's record snippets imploded to one string
194
     */
195
    public function getSnippets()
196
    {
197
        return $this->snippets;
198
    }
199
200
    /**
201
     * Get the thumbnail URL
202
     *
203
     * @access public
204
     *
205
     * @return string
206
     */
207
    public function getThumbnail()
208
    {
209
        return $this->thumbnail;
210
    }
211
212
    /**
213
     * Get the title
214
     *
215
     * @access public
216
     *
217
     * @return string
218
     */
219
    public function getTitle()
220
    {
221
        return $this->title;
222
    }
223
224
    /**
225
     * Get the toplevel flag
226
     *
227
     * @access public
228
     *
229
     * @return boolean
230
     */
231
    public function getToplevel()
232
    {
233
        return $this->toplevel;
234
    }
235
236
    /**
237
     * Get the structure type
238
     *
239
     * @access public
240
     *
241
     * @return string
242
     */
243
    public function getType()
244
    {
245
        return $this->type;
246
    }
247
248
    /**
249
     * Get all result's pages which contain search phrase.
250
     *
251
     * @access public
252
     *
253
     * @return array(Page) All result's pages which contain search phrase
254
     */
255
    public function getPages()
256
    {
257
        return $this->pages;
258
    }
259
260
    /**
261
     * Get all result's regions which contain search phrase.
262
     *
263
     * @access public
264
     *
265
     * @return array(Region) All result's regions which contain search phrase
266
     */
267
    public function getRegions()
268
    {
269
        return $this->regions;
270
    }
271
272
    /**
273
     * Get all result's highlights of search phrase.
274
     *
275
     * @access public
276
     *
277
     * @return array(Highlight) All result's highlights of search phrase
278
     */
279
    public function getHighlights()
280
    {
281
        return $this->highlights;
282
    }
283
284
    /**
285
     * Get all result's highlights' ids of search phrase.
286
     *
287
     * @access public
288
     *
289
     * @return array(string) All result's highlights of search phrase
290
     */
291
    public function getHighlightsIds()
292
    {
293
        $highlightsIds = [];
294
        foreach ($this->highlights as $highlight) {
295
            array_push($highlightsIds, $highlight->getId());
296
        }
297
        return $highlightsIds;
298
    }
299
300
    /**
301
     * Parse snippets array to string for displaying purpose.
302
     * Snippets are stored in 'text' field of 'snippets' object.
303
     *
304
     * @access private
305
     *
306
     * @return void
307
     */
308
    private function parseSnippets()
309
    {
310
        $snippetArray = $this->getArrayByIndex('text');
311
312
        $this->snippets = !empty($snippetArray) ? implode(' [...] ', $snippetArray) : '';
313
    }
314
315
    /**
316
     * Parse pages array to array of Page objects.
317
     * Pages are stored in 'pages' field of 'snippets' object.
318
     *
319
     * @access private
320
     *
321
     * @return void
322
     */
323
    private function parsePages()
324
    {
325
        $pageArray = $this->getArrayByIndex('pages');
326
327
        $i = 0;
328
        foreach ($pageArray as $pages) {
329
            foreach ($pages as $page) {
330
                array_push($this->pages, new Page($i, $page));
331
                $i++;
332
            }
333
        }
334
    }
335
336
    /**
337
     * Parse regions array to array of Region objects.
338
     * Regions are stored in 'regions' field of 'snippets' object.
339
     *
340
     * @access private
341
     *
342
     * @return void
343
     */
344
    private function parseRegions()
345
    {
346
        $regionArray = $this->getArrayByIndex('regions');
347
348
        $i = 0;
349
        foreach ($regionArray as $regions) {
350
            foreach ($regions as $region) {
351
                array_push($this->regions, new Region($i, $region));
352
                $i++;
353
            }
354
        }
355
    }
356
357
    /**
358
     * Parse highlights array to array of Highlight objects.
359
     * Highlights are stored in 'highlights' field of 'snippets' object.
360
     *
361
     * @access private
362
     *
363
     * @return void
364
     */
365
    private function parseHighlights()
366
    {
367
        $highlightArray = $this->getArrayByIndex('highlights');
368
369
        foreach ($highlightArray as $highlights) {
370
            foreach ($highlights as $highlight) {
371
                foreach ($highlight as $hl) {
372
                    array_push($this->highlights, new Highlight($hl));
373
                }
374
            }
375
        }
376
    }
377
378
    /**
379
     * Get array for given index.
380
     *
381
     * @access private
382
     *
383
     * @param string $index: Name of field for which array is going be created
384
     *
385
     * @return array
386
     */
387
    private function getArrayByIndex($index)
388
    {
389
        $objectArray = [];
390
        foreach ($this->snippetsForRecord as $snippet) {
391
            if (!empty($snippet[$index])) {
392
                array_push($objectArray, $snippet[$index]);
393
            }
394
        }
395
        return $objectArray;
396
    }
397
}
398