StringMapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 62
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canHandleType() 0 6 1
A getDatabaseDefinition() 0 4 1
A getTcaConfiguration() 0 27 4
1
<?php
2
3
/**
4
 * Map String.
5
 */
6
declare(strict_types = 1);
7
8
namespace HDNET\Autoloader\Mapper;
9
10
use HDNET\Autoloader\MapperInterface;
11
12
/**
13
 * Map String.
14
 */
15
class StringMapper implements MapperInterface
16
{
17
    /**
18
     * Check if the current mapper can handle the given type.
19
     *
20
     * @param string $type
21
     *
22
     * @return bool
23
     */
24
    public function canHandleType($type)
25
    {
26
        return \in_array(mb_strtolower($type), [
27
            'string',
28
        ], true);
29
    }
30
31
    /**
32
     * Get the TCA configuration for the current type.
33
     *
34
     * @param string $fieldName
35
     * @param bool   $overWriteLabel
36
     *
37
     * @return array
38
     */
39
    public function getTcaConfiguration($fieldName, $overWriteLabel = false)
40
    {
41
        if ('slug' === $fieldName) {
42
            return [
43
                'exclude' => 1,
44
                'label' => $overWriteLabel ? $overWriteLabel : $fieldName,
45
                'config' => [
46
                    'type' => 'slug',
47
                    'prependSlash' => true,
48
                    'generatorOptions' => [
49
                        'fields' => [], // 'title'
50
                        'prefixParentPageSlug' => true,
51
                    ],
52
                    'fallbackCharacter' => '-',
53
                    'eval' => 'uniqueInSite',
54
                ],
55
            ];
56
        }
57
58
        return [
59
            'exclude' => 1,
60
            'label' => $overWriteLabel ? $overWriteLabel : $fieldName,
61
            'config' => [
62
                'type' => 'input',
63
            ],
64
        ];
65
    }
66
67
    /**
68
     * Get the database definition for the current mapper.
69
     *
70
     * @return string
71
     */
72
    public function getDatabaseDefinition()
73
    {
74
        return 'text';
75
    }
76
}
77