Database::loadTables()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Database
4
 */
5
6
namespace HDNET\Tagger\Slots;
7
8
use HDNET\Tagger\Utility\TaggerRegister;
9
10
/**
11
 * Database
12
 */
13
class Database
14
{
15
16
    /**
17
     * Add the smart object SQL string the the signal below
18
     *
19
     * @signalClass \TYPO3\CMS\Install\Service\SqlExpectedSchemaService
20
     * @signalName tablesDefinitionIsBeingBuilt
21
     *
22
     * @param array $sqlString
23
     *
24
     * @return array
25
     */
26
    public function loadTables(array $sqlString)
27
    {
28
        $sqlString[] = $this->getDatabaseString();
29
        return ['sqlString' => $sqlString];
30
    }
31
32
    /**
33
     * Add the smart object SQL string the the signal below
34
     *
35
     * @signalClass \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
36
     * @signalName tablesDefinitionIsBeingBuilt
37
     *
38
     * @param array $sqlString
39
     * @param string $extensionKey
40
     *
41
     * @return array
42
     */
43
    public function updateTables(array $sqlString, $extensionKey)
44
    {
45
        $sqlString[] = $this->getDatabaseString();
46
        return [
47
            'sqlString' => $sqlString,
48
            'extensionKey' => $extensionKey
49
        ];
50
    }
51
52
    /**
53
     * Get the tagger string for the registered tables
54
     *
55
     * @return string
56
     */
57
    protected function getDatabaseString()
58
    {
59
        $sql = [];
60
        foreach (TaggerRegister::getRegister() as $configuration) {
61
            $table = $configuration['tableName'];
62
            $sql[] = 'CREATE TABLE ' . $table . ' (
63
			tagger tinytext
64
			);';
65
        }
66
        return implode(LF, $sql);
67
    }
68
}
69