Completed
Push — master ( 0a63e5...44f21d )
by Tim
02:15
created

NameMapperService::getDatabaseFieldName()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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