NameMapperService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 75
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDatabaseFieldName() 0 8 3
1
<?php
2
3
/**
4
 * Map property names to DB field values.
5
 */
6
declare(strict_types = 1);
7
8
namespace HDNET\Autoloader\Service;
9
10
use TYPO3\CMS\Core\Utility\GeneralUtility;
11
12
/**
13
 * Map property names to DB field values.
14
 */
15
class NameMapperService
16
{
17
    /**
18
     * Core fields that are stored as camel case in the DB
19
     * So the field is mapped directly.
20
     *
21
     * @var array
22
     */
23
    protected $coreCamelCaseField = [
24
        'tt_content' => [
25
            'CType',
26
            'rowDescription',
27
            'spaceBefore',
28
            'spaceAfter',
29
            'colPos',
30
            'sectionIndex',
31
            'linkToTop',
32
        ],
33
        'sys_template' => [
34
            'nextLevel',
35
            'basedOn',
36
            'includeStaticAfterBasedOn',
37
        ],
38
        'sys_domain' => [
39
            'redirectHttpStatusCode',
40
            'redirectTo',
41
            'domainName',
42
        ],
43
        'fe_users' => [
44
            'lockToDomain',
45
            'TSconfig',
46
        ],
47
        'fe_groups' => [
48
            'lockToDomain',
49
            'TSconfig',
50
        ],
51
        'be_groups' => [
52
            'groupMods',
53
            'lockToDomain',
54
            'TSconfig',
55
        ],
56
        'be_users' => [
57
            'realName',
58
            'userMods',
59
            'lockToDomain',
60
            'disableIPlock',
61
            'TSconfig',
62
            'lastlogin',
63
            'createdByAction',
64
        ],
65
        'pages' => [
66
            'TSconfig',
67
            'lastUpdated',
68
            'newUntil',
69
            'SYS_LASTCHANGED',
70
            'extendToSubpages',
71
        ],
72
        'sys_log' => [
73
            'NEWid',
74
            'IP',
75
        ],
76
    ];
77
78
    /**
79
     * Get the right DB representation and respect camelCase field of the core.
80
     */
81
    public function getDatabaseFieldName(string $tableName, string $propertyName): string
82
    {
83
        if (isset($this->coreCamelCaseField[$tableName]) && \in_array($propertyName, $this->coreCamelCaseField[$tableName], true)) {
84
            return $propertyName;
85
        }
86
87
        return GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName);
88
    }
89
}
90