Passed
Branch tmp/scrutinizer-notification-d... (24bdcd)
by Romain
05:04
created

EntityLogTcaService::getDefinitionIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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