FCEFootnoteService::renderItemList()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6.2163

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 19
ccs 9
cts 11
cp 0.8182
rs 9.2222
cc 6
nc 5
nop 2
crap 6.2163
1
<?php
2
3
namespace AOE\HappyFeet\Service;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 3 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
29
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
30
31
/**
32
 * Render Footnotes for FCE
33
 */
34
class FCEFootnoteService
35
{
36
    public ?ContentObjectRenderer $cObj = null;
37
38 3
    public function __construct(
39
        private RenderingService $renderingService
40
    ) {
41 3
    }
42
43
    /**
44
     * @param array $conf optional (this will be automatically set, of this method is called via 'TYPOSCRIPT-userFunc')
45
     * @return ?string The wrapped index value
46
     */
47 3
    public function renderItemList(string $content, array $conf = []): ?string
0 ignored issues
show
Unused Code introduced by
The parameter $content is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

47
    public function renderItemList(/** @scrutinizer ignore-unused */ string $content, array $conf = []): ?string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49 3
        if (!array_key_exists('userFunc', $conf) || !array_key_exists('field', $conf)) {
50 1
            return '';
51
        }
52
53 2
        if (array_key_exists('isGridElement', $conf) && (bool) $conf['isGridElement']) {
54
            $footnoteUids = $this->getCObj()
55
                ->data['pi_flexform']['data']['sDEF']['lDEF'][$conf['field']]['vDEF'];
56
        } else {
57 2
            $footnoteUids = $this->getCObj()
58 2
                ->getCurrentVal();
59
        }
60
61 2
        if (empty($footnoteUids)) {
62 1
            return '';
63
        }
64
65 1
        return $this->renderingService->renderFootnotes(explode(',', $footnoteUids));
66
    }
67
68 1
    public function setCObj(ContentObjectRenderer $cObj): void
69
    {
70 1
        $this->cObj = $cObj;
71
    }
72
73 1
    protected function getCObj(): ContentObjectRenderer
74
    {
75 1
        return $this->cObj;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->cObj could return the type null which is incompatible with the type-hinted return TYPO3\CMS\Frontend\Conte...t\ContentObjectRenderer. Consider adding an additional type-check to rule them out.
Loading history...
76
    }
77
}
78