Completed
Push — master ( a9a357...5d1efe )
by Tim
02:14
created

CalendarizeFieldListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A getCalendarizeDatabaseString() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HDNET\Calendarize\EventListener;
6
7
use HDNET\Calendarize\Register;
8
use TYPO3\CMS\Core\Database\Event\AlterTableDefinitionStatementsEvent;
9
10
class CalendarizeFieldListener
11
{
12
    public function __invoke(AlterTableDefinitionStatementsEvent $event): void
13
    {
14
        $event->addSqlData($this->getCalendarizeDatabaseString());
15
    }
16
17
    /**
18
     * Get the calendarize string for the registered tables.
19
     *
20
     * @return string
21
     */
22
    protected function getCalendarizeDatabaseString()
23
    {
24
        $sql = [];
25
        foreach (Register::getRegister() as $configuration) {
26
            $fieldName = isset($configuration['fieldName']) ? $configuration['fieldName'] : 'calendarize';
27
            $sql[] = 'CREATE TABLE ' . $configuration['tableName'] . ' (' . $fieldName . ' tinytext, calendarize_info tinytext);';
28
        }
29
30
        return implode(LF, $sql);
31
    }
32
}
33