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
Pull Request — dev-extbase-fluid (#754)
by Alexander
03:00
created

ResultDocument::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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