Passed
Push — master ( e50b6a...8c2165 )
by Timo
22:54
created

Content   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 41
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 8 1
A getRawContent() 0 13 3
1
<?php
2
namespace ApacheSolrForTypo3\Solr\ContentObject;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2011-2015 Ingo Renner <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 3 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\HtmlContentExtractor;
28
use TYPO3\CMS\Core\Utility\GeneralUtility;
29
use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
30
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
31
32
/**
33
 * A content object (cObj) to clean a database field in a way so that it can be
34
 * used to fill a Solr document's content field.
35
 *
36
 * @author Ingo Renner <[email protected]>
37
 */
38
class Content extends AbstractContentObject
39
{
40
    const CONTENT_OBJECT_NAME = 'SOLR_CONTENT';
41
42
    /**
43
     * Executes the SOLR_CONTENT content object.
44
     *
45
     * Cleans content coming from a database field, removing HTML tags ...
46
     *
47
     * @inheritDoc
48
     */
49
    public function render($conf = [])
50
    {
51
        $contentExtractor = GeneralUtility::makeInstance(
52
            HtmlContentExtractor::class,
53
            /** @scrutinizer ignore-type */ $this->getRawContent($this->cObj, $conf)
54
        );
55
56
        return $contentExtractor->getIndexableContent();
57
    }
58
59
    /**
60
     * Gets the raw content as configured - a certain value or database field.
61
     *
62
     * @param ContentObjectRenderer $contentObject The original content object
63
     * @param array $configuration content object configuration
64
     * @return string The raw content
65
     */
66
    protected function getRawContent($contentObject, $configuration)
67
    {
68
        $content = '';
69
        if (isset($configuration['value'])) {
70
            $content = $configuration['value'];
71
            unset($configuration['value']);
72
        }
73
74
        if (!empty($configuration)) {
75
            $content = $contentObject->stdWrap($content, $configuration);
76
        }
77
78
        return $content;
79
    }
80
}
81