Passed
Push — master ( 4595aa...20e07b )
by Romain
06:34
created

getFlexFormDS_postProcessDS()   C

Complexity

Conditions 11
Paths 18

Size

Total Lines 47
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 28
nc 18
nop 5
dl 0
loc 47
rs 5.2653
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Service\Hook;
18
19
use TYPO3\CMS\Core\Database\DatabaseConnection;
20
use TYPO3\CMS\Core\SingletonInterface;
21
use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23
/**
24
 * Utility class that allows TYPO3 v7 to handle the FlexForm for notifications
25
 * fields.
26
 *
27
 * @deprecated Must be removed when TYPO3 v7 is not supported anymore.
28
 */
29
class NotificationFlexFormProcessor implements SingletonInterface
30
{
31
    /**
32
     * @var array
33
     */
34
    protected static $handledTables = [
35
        'tx_notiz_domain_model_entityemailnotification' => 'event_configuration_flex',
36
        'tx_notiz_domain_model_entitylognotification' => 'event_configuration_flex'
37
    ];
38
39
    /**
40
     * @param array $flexFormArray
41
     * @param array $conf
42
     * @param array $row
43
     * @param string $table
44
     * @param string $fieldName
45
     */
46
    public function getFlexFormDS_postProcessDS(&$flexFormArray, $conf, $row, $table, $fieldName)
47
    {
48
        $flag = false;
49
50
        foreach (self::$handledTables as $handledTable => $handledField) {
51
            if ($handledTable === $table
52
                && $handledField === $fieldName
53
                && 0 !== $row['sys_language_uid']
54
            ) {
55
                $flag = true;
56
                break;
57
            }
58
        }
59
60
        if (!$flag) {
61
            return;
62
        }
63
64
        $parent = $this->getDatabaseConnection()
65
            ->exec_SELECTgetSingleRow(
66
                'event',
67
                $table,
68
                'uid=' . (int)$row['l10n_parent']
69
            );
70
71
        if (!$parent) {
72
            return;
73
        }
74
75
        $event = $parent['event'];
76
77
        if (!isset($conf['ds'][$event])) {
78
            return;
79
        }
80
81
        $ds = $conf['ds'][$event];
82
83
        if (substr($ds, 0, 5) == 'FILE:') {
84
            $file = GeneralUtility::getFileAbsFileName(substr($ds, 5));
85
86
            if ($file && @is_file($file)) {
87
                $flexFormArray = GeneralUtility::xml2array(GeneralUtility::getUrl($file));
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Core\Utility\G...lUtility::getUrl($file) can also be of type false; however, parameter $string of TYPO3\CMS\Core\Utility\GeneralUtility::xml2array() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

87
                $flexFormArray = GeneralUtility::xml2array(/** @scrutinizer ignore-type */ GeneralUtility::getUrl($file));
Loading history...
88
            } else {
89
                $flexFormArray = 'The file "' . substr($ds, 5) . '" in ds-array key "' . $event . '" was not found ("' . $file . '")';
90
            }
91
        } else {
92
            $flexFormArray = GeneralUtility::xml2array($ds);
93
        }
94
    }
95
96
    /**
97
     * @return DatabaseConnection
98
     */
99
    protected function getDatabaseConnection()
100
    {
101
        return $GLOBALS['TYPO3_DB'];
102
    }
103
}
104