EntityLogTcaService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 76
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefinitionIdentifier() 0 3 1
A getLevels() 0 11 1
A getLogLevelsDescriptions() 0 27 1
A getLogLevelsList() 0 8 3
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C)
6
 * Nathan Boiron <[email protected]>
7
 * Romain Canon <[email protected]>
8
 *
9
 * This file is part of the TYPO3 NotiZ project.
10
 * It is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License, either
12
 * version 3 of the License, or any later version.
13
 *
14
 * For the full copyright and license information, see:
15
 * http://www.gnu.org/licenses/gpl-3.0.html
16
 */
17
18
namespace CuyZ\Notiz\Domain\Notification\Log\Application\EntityLog\TCA;
19
20
use CuyZ\Notiz\Core\Notification\Service\NotificationTcaService;
21
use CuyZ\Notiz\Domain\Notification\Log\Application\EntityLog\EntityLogNotification;
22
use CuyZ\Notiz\Service\LocalizationService;
23
use Psr\Log\LogLevel;
24
25
class EntityLogTcaService extends NotificationTcaService
26
{
27
    /**
28
     * List all available log levels and stores them as an array to be used by
29
     * the TCA.
30
     *
31
     * @param array $parameters
32
     */
33
    public function getLogLevelsList(array &$parameters)
34
    {
35
        if ($this->definitionHasErrors()) {
36
            return;
37
        }
38
39
        foreach ($this->getLevels() as $level) {
40
            $parameters['items'][] = [strtoupper($level), $level];
41
        }
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getLogLevelsDescriptions(): string
48
    {
49
        $lll = 'Notification/Log';
50
51
        $levels = array_map(
52
            function ($level) use ($lll) {
53
                $level = strtoupper($level);
54
55
                $description = LocalizationService::localize("$lll:level.$level");
56
57
                return "<tr><td><strong>$level</strong></td><td>$description</td></tr>";
58
            },
59
            $this->getLevels()
60
        );
61
62
        $rows = implode('', $levels);
63
64
        $linkLabel = LocalizationService::localize("$lll:levels.more_info");
65
66
        return <<<HTML
67
<table class="table table-striped table-hover">
68
    <tbody>
69
        $rows
70
    </tbody>
71
</table>
72
<small>
73
    <a href="http://www.php-fig.org/psr/psr-3/#psrlogloglevel" target="_blank">$linkLabel</a>
74
</small>
75
HTML;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    private function getLevels(): array
82
    {
83
        return [
84
            LogLevel::DEBUG,
85
            LogLevel::INFO,
86
            LogLevel::NOTICE,
87
            LogLevel::WARNING,
88
            LogLevel::ERROR,
89
            LogLevel::CRITICAL,
90
            LogLevel::ALERT,
91
            LogLevel::EMERGENCY,
92
        ];
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    protected function getDefinitionIdentifier(): string
99
    {
100
        return EntityLogNotification::getDefinitionIdentifier();
101
    }
102
}
103