Completed
Push — master ( 44297e...90be80 )
by Tim
06:31 queued 03:38
created

ModelMapper::canHandleType()   B

Complexity

Conditions 6
Paths 11

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 8
cp 0
rs 8.9297
c 0
b 0
f 0
cc 6
nc 11
nop 1
crap 42
1
<?php
2
3
/**
4
 * Map general Models.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Autoloader\Mapper;
9
10
use HDNET\Autoloader\MapperInterface;
11
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
12
13
/**
14
 * Map general Models.
15
 */
16
class ModelMapper implements MapperInterface
17
{
18
    /**
19
     * Check if the current mapper can handle the given type.
20
     *
21
     * @param string $type
22
     *
23
     * @return bool
24
     */
25
    public function canHandleType($type)
26
    {
27
        $type = trim($type, '\\');
28
        if (!\class_exists($type)) {
29
            return false;
30
        }
31
        $abstractEntity = trim(AbstractEntity::class, '\\');
32
        try {
33
            if ($type === $abstractEntity) {
34
                return true;
35
            }
36
            $reflection = new \ReflectionClass($type);
37
            while ($reflection = $reflection->getParentClass()) {
38
                if ($abstractEntity === trim($reflection->getName(), '\\')) {
39
                    return true;
40
                }
41
            }
42
43
            return false;
44
        } catch (\Exception $exception) {
45
            return false;
46
        }
47
    }
48
49
    /**
50
     * Get the TCA configuration for the current type.
51
     *
52
     * @param string $fieldName
53
     * @param bool   $overWriteLabel
54
     *
55
     * @return array
56
     */
57
    public function getTcaConfiguration($fieldName, $overWriteLabel = false)
58
    {
59
        $baseConfig = [
60
            'type' => 'user',
61
            'userFunc' => 'HDNET\\Autoloader\\UserFunctions\\Tca->modelInfoField',
62
        ];
63
64
        return [
65
            'exclude' => 1,
66
            'label' => $overWriteLabel ? $overWriteLabel : $fieldName,
67
            'config' => $baseConfig,
68
        ];
69
    }
70
71
    /**
72
     * Get the database definition for the current mapper.
73
     *
74
     * @return string
75
     */
76
    public function getDatabaseDefinition()
77
    {
78
        return 'int(11) DEFAULT \'0\' NOT NULL';
79
    }
80
}
81