Passed
Push — master ( 14b490...3d7c7d )
by Timo
23:43
created

Content   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRawContent() 0 13 3
A cObjGetSingleExt() 0 12 1
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
30
/**
31
 * A content object (cObj) to clean a database field in a way so that it can be
32
 * used to fill a Solr document's content field.
33
 *
34
 * @author Ingo Renner <[email protected]>
35
 */
36
class Content
37
{
38
    const CONTENT_OBJECT_NAME = 'SOLR_CONTENT';
39
40
    /**
41
     * Executes the SOLR_CONTENT content object.
42
     *
43
     * Cleans content coming from a database field, removing HTML tags ...
44
     *
45
     * @param string $name content object name 'SOLR_CONTENT'
46
     * @param array $configuration for the content object
47
     * @param string $TyposcriptKey not used
48
     * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject parent cObj
49
     * @return string serialized array representation of the given list
50
     */
51
    public function cObjGetSingleExt(
52
        /** @noinspection PhpUnusedParameterInspection */ $name,
53
        array $configuration,
54
        /** @noinspection PhpUnusedParameterInspection */ $TyposcriptKey,
55
        $contentObject
56
    ) {
57
        $contentExtractor = GeneralUtility::makeInstance(
58
            HtmlContentExtractor::class,
59
            /** @scrutinizer ignore-type */ $this->getRawContent($contentObject, $configuration)
60
        );
61
62
        return $contentExtractor->getIndexableContent();
63
    }
64
65
    /**
66
     * Gets the raw content as configured - a certain value or database field.
67
     *
68
     * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject The original content object
69
     * @param array $configuration content object configuration
70
     * @return string The raw content
71
     */
72
    protected function getRawContent($contentObject, $configuration)
73
    {
74
        $content = '';
75
        if (isset($configuration['value'])) {
76
            $content = $configuration['value'];
77
            unset($configuration['value']);
78
        }
79
80
        if (!empty($configuration)) {
81
            $content = $contentObject->stdWrap($content, $configuration);
82
        }
83
84
        return $content;
85
    }
86
}
87