TcaUtility::insertTabDividerBefore()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
ccs 0
cts 4
cp 0
rs 9.7666
cc 3
nc 3
nop 3
crap 12
1
<?php
2
3
/**
4
 * TcaUtility.php.
5
 *
6
 * General file information
7
 */
8
declare(strict_types = 1);
9
10
namespace HDNET\Autoloader\Utility;
11
12
use HDNET\Autoloader\Exception;
13
14
/**
15
 * A basic TCA manipulation utility class.
16
 */
17
class TcaUtility
18
{
19
    /**
20
     * Inserts a divider tab before a given column name.
21
     *
22
     * @param array  $base       The base TCA array
23
     * @param string $columnName The column name before to insert a tab divider
24
     * @param string $tabTitle   The title of the tab
25
     *
26
     * @throws Exception
27
     *
28
     * @return array
29
     */
30
    public static function insertTabDividerBefore(&$base, $columnName, $tabTitle)
31
    {
32
        if (!\is_array($base)) {
33
            throw new Exception('A proper TCA configuration is needed!', 17823492);
34
        }
35
36
        $divider = '--div--;' . $tabTitle . ',';
37
        foreach ($base['types'] as $key => $layout) {
38
            $tempShowitem = explode($columnName, $layout['showitem']);
39
            $showItem = $tempShowitem[0] . $divider . $columnName . $tempShowitem[1];
40
            $base['types'][$key]['showitem'] = $showItem;
41
        }
42
43
        return $base;
44
    }
45
}
46